4 import roslib; roslib.load_manifest(
'kobuki_testsuite')
9 from kobuki_msgs.msg
import ButtonEvent
10 from kobuki_msgs.msg
import Sound
11 from geometry_msgs.msg
import Twist
13 from sensor_msgs.msg
import Imu
14 from geometry_msgs.msg
import Quaternion
15 from geometry_msgs.msg
import Pose2D
17 from tf.transformations
import euler_from_quaternion
18 from math
import degrees, radians
21 from kobuki_msgs.msg
import ScanAngle
24 a = mod(mod(x,2*pi)+2*pi, 2*pi)
31 rospy.init_node(
"gyro_perf")
38 self.
debug = rospy.get_param(
'~debug',
False)
41 self.
command_wz = radians(rospy.get_param(
'~command_wz', 5.0))
67 self.
state=
'WAIT_CONNECTION' 69 rospy.Timer(rospy.Duration.from_sec(0.02), self.
timerCallback)
76 if rospy.is_shutdown():
return 80 if event.last_real ==
None:
81 event.last_real = rospy.Time.from_sec(0.0)
82 event.last_expected = rospy.Time.from_sec(0.0)
83 event.last_duration = 0.0
85 if self.
state ==
'WAIT_CONNECTION':
86 if self.sub_angle.get_num_connections() > 0
and\
87 self.sub_gyro.get_num_connections() > 0
and\
88 self.pub_velocity.get_num_connections() > 0:
89 if self.
debug:
print 'connection ready.' 91 self.
state =
'ALIGNING' 95 if self.
debug:
print 'not ready yet.' 98 if self.
state ==
"ALIGNING":
102 if abs(scan_angle) > radians(1.0):
104 cmd_vel.angular.z = -0.33*scan_angle/abs(scan_angle)
105 self.pub_velocity.publish(cmd_vel)
106 self.
init_time = rospy.Time.now().to_time()
107 if self.
debug:
print 'state:', self.
state,
':', scan_angle,
'-->', cmd_vel.angular.z
111 cmd_vel.linear.x = 0.0
112 cmd_vel.angular.z = 0.0
113 self.pub_velocity.publish(cmd_vel)
116 if self.
debug:
print 'alining ready.' 118 self.pub_sound.publish(Sound(value=Sound.RECHARGE))
119 self.
state =
'WAIT_TRIGGER' 126 if self.
state ==
'WAIT_TRIGGER':
128 self.pub_sound.publish(Sound(value=Sound.CLEANINGEND))
129 self.
state =
'CALC_ANGLE_PRERUN' 137 if self.
state ==
'CALC_ANGLE_PRERUN':
142 self.pub_sound.publish(Sound(value=Sound.RECHARGE))
144 self.
state =
'RUNNING' 145 self.
init_time = rospy.Time.now().to_time()
160 if self.
state ==
'RUNNING':
164 cmd_vel.linear.x = 0.0
165 cmd_vel.angular.z = 0.0
166 self.pub_velocity.publish(cmd_vel)
168 self.
init_time = rospy.Time.now().to_time()
175 self.pub_velocity.publish(cmd_vel)
179 if self.
state ==
'STOP':
183 self.
state =
'CALC_ANGLE_POSTRUN' 190 if self.
state ==
'CALC_ANGLE_POSTRUN':
195 sign = angle_gyro/abs(angle_gyro)
198 rospy.loginfo(
'test_angle: {0} deg'.format(self.
test_angle))
199 rospy.loginfo(
'test_command: {0} m/s {1} deg/s'.format(self.
command_vx, degrees(self.
command_wz)))
200 rospy.loginfo(
'running_time: {0} s'.format(self.
running_time))
202 rospy.loginfo(
'angle_prerun: {0} deg'.format(degrees(self.
angle_prerun)))
203 rospy.loginfo(
'angle_postrun: {0} deg'.format(degrees(self.
angle_postrun)))
204 rospy.loginfo(
'angle_gyro: {0} deg'.format(degrees(angle_gyro)))
205 rospy.loginfo(
'angle_laser: {0} deg'.format(degrees(angle_laser)))
207 rospy.loginfo(
'error: {0} deg/rev'.format(angle_gyro/angle_laser*360.0-360.0))
208 rospy.loginfo(
'Done')
209 self.pub_sound.publish(Sound(value=Sound.CLEANINGSTART))
214 rospy.signal_shutdown(
'jobs_done')
222 if rospy.is_shutdown():
return 223 quat = data.orientation
224 q = [quat.x, quat.y, quat.z, quat.w]
225 roll, pitch, yaw = euler_from_quaternion(q)
237 if rospy.is_shutdown():
return 242 if self.
debug:
print 'Resetted' 256 if rospy.is_shutdown():
return 257 if data.button == ButtonEvent.Button0
and data.state == ButtonEvent.RELEASED:
266 if __name__ ==
'__main__':
268 print "It test gyro on kobuki and print gyro drift errors." 273 except rospy.ROSInterruptException:
pass
def buttonCallback(self, data)
def angleCallback(self, data)
def ending_condition(self)
def timerCallback(self, event)
def imuCallback(self, data)