cmd_vel_test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 from math import sin, pi
00005 from geometry_msgs.msg import Twist
00006 
00007 speed_trans = 0.1
00008 speed_rotate = 0.5
00009 
00010 if __name__=="__main__":
00011 
00012     # first thing, init a node!
00013     rospy.init_node('cmd_vel_test')
00014 
00015     # publish to cmd_vel
00016     p = rospy.Publisher('spur/cmd_vel', Twist)
00017 
00018     # create a twist message, fill in the details
00019     twist = Twist()
00020     twist.linear.x = speed_trans
00021     twist.linear.y = 0
00022     twist.linear.z = 0
00023     twist.angular.x = 0
00024     twist.angular.y = 0
00025     twist.angular.z = 0
00026 
00027     # announce move, and publish the message
00028     rospy.loginfo("About to be moving forward!")
00029     for i in range(30):
00030         p.publish(twist)
00031         rospy.sleep(0.1) # 30*0.1 = 3.0
00032 
00033     twist.linear.x = speed_trans
00034     twist.linear.y = 0
00035     twist.angular.z = speed_trans
00036     rospy.loginfo("About to be moving forward + rotation")
00037     for i in range(30):
00038         p.publish(twist)
00039         rospy.sleep(0.1) # 30*0.1 = 3.0
00040 
00041     twist.linear.x = speed_trans
00042     twist.linear.y = 0
00043     twist.angular.z = -speed_trans
00044     rospy.loginfo("About to be moving forward - rotation")
00045     for i in range(30):
00046         p.publish(twist)
00047         rospy.sleep(0.1) # 30*0.1 = 3.0
00048 
00049     twist.linear.x = 0
00050     twist.linear.y = speed_trans
00051     rospy.loginfo("About to be moving to right!")
00052     for i in range(30):
00053         p.publish(twist)
00054         rospy.sleep(0.1) # 30*0.1 = 3.0
00055 
00056     twist.linear.x = 0
00057     twist.linear.y = 0
00058     twist.angular.z = speed_trans
00059     rospy.loginfo("About to be moving rotation!")
00060     for i in range(30):
00061         p.publish(twist)
00062         rospy.sleep(0.1) # 30*0.1 = 3.0
00063 
00064     twist.linear.x = speed_trans
00065     twist.linear.y = 0
00066     rospy.loginfo("About to be moving sin curve")
00067     for i in range(100):
00068         twist.angular.z = speed_rotate*sin(pi*i/50.0)
00069         rospy.loginfo("%6.4f %6.4f %6.4f" % (twist.linear.x, twist.linear.y, twist.angular.z))
00070         p.publish(twist)
00071         rospy.sleep(0.1) # 30*0.1 = 3.0
00072 
00073     # create a new message
00074     twist = Twist()
00075 
00076     # note: everything defaults to 0 in twist, if we don't fill it in, we stop!
00077     rospy.loginfo("Stopping!")
00078     p.publish(twist)


spur_controller
Author(s): Tokyo Opensource Robotics Programmer 534o <534o@opensource-robotics.tokyo.jp>, Isaac I. Y. Saito
autogenerated on Sat Jun 8 2019 19:44:12