14 from nav_msgs.msg
import Odometry
15 from geometry_msgs.msg
import Twist
16 from std_msgs.msg
import String
17 from sensor_msgs.msg
import Imu
33 return (
"[%s, %s, %s]"%(self.
x, self.
y, self.
heading))
36 Implement a square motion 39 STATE_FORWARD =
"forward" 40 STATE_STOP_FORWARD =
"stop_forward" 42 STATE_STOP_TURN =
"stop_turn" 44 def __init__(self,cmd_vel_topic, odom_topic, gyro_topic):
62 def init(self, speed, side_distance):
71 self.cmd_vel_publisher.unregister()
73 self.odom_subscriber.unregister()
75 self.gyro_subscriber.unregister()
83 Drop this into threading.Thread or QThread for execution 86 rospy.logerr(
"Kobuki TestSuite: already executing a motion, ignoring the request")
88 timeout = rospy.Time.now() + rospy.Duration(5.0)
89 while not self._current_pose.configured():
90 if rospy.Time.now() > timeout:
91 rospy.logerr(
"Kobuki TestSuite: no odometry data, aborting")
94 rospy.logwarn(
"Kobuki TestSuite: haven't received any odometry data yet")
98 start = rospy.get_rostime()
102 rospy.loginfo(
"Kobuki Testsuite: executing a square motion pattern [%s]"%self.
_side_distance)
105 while not self.
_stop and not rospy.is_shutdown():
106 if self.
_state == Square.STATE_FORWARD:
108 elif self.
_state == Square.STATE_STOP_FORWARD:
110 elif self.
_state == Square.STATE_TURN:
112 elif self.
_state == Square.STATE_STOP_TURN:
117 if not rospy.is_shutdown():
126 dx = self._current_pose.x - self._starting_pose.x
127 dy = self._current_pose.y - self._starting_pose.y
128 travelled_sq = dx*dx + dy*dy
136 if math.fabs(self._current_pose.heading - self._starting_pose.heading) > math.pi/2.0:
143 Publishes a cmd_vel message for the kobuki. 146 cmd.linear.x = linear
147 cmd.angular.z = angular
148 self.cmd_vel_publisher.publish(cmd)
152 rospy.loginfo(
"Kobuki TestSuite: commencing turn")
153 self.
_state = Square.STATE_STOP_FORWARD
160 self.
_state = Square.STATE_TURN
166 self.
_state = Square.STATE_STOP_TURN
176 rospy.loginfo(
"Kobuki TestSuite: finished turn %s"%self.
_turn_count)
178 self.
_state = Square.STATE_FORWARD
190 self._current_pose.x = data.pose.pose.position.x
191 self._current_pose.y = data.pose.pose.position.y
196 quat = data.orientation
197 rot = PyKDL.Rotation.Quaternion(quat.x, quat.y, quat.z, quat.w)
198 self._current_pose.heading = rot.GetRPY()[2]
201 if __name__ ==
'__main__':
202 rospy.init_node(
'square')
def _has_reached_forward_goal(self)
Utilities.
def odometry_callback(self, data)
Ros Callbacks.
def _has_reached_turning_goal(self)
def _command(self, linear, angular)
def __init__(self, cmd_vel_topic, odom_topic, gyro_topic)
def heading_callback(self, data)
def init(self, speed, side_distance)