move.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """ Example code of how to move a robot forward for 3 seconds. """
00004 
00005 # We always import roslib, and load the manifest to handle dependencies
00006 import roslib; roslib.load_manifest('mini_max_tutorials')
00007 import rospy
00008 
00009 # recall: robots generally take base movement commands on a topic 
00010 #  called "cmd_vel" using a message type "geometry_msgs/Twist"
00011 from geometry_msgs.msg import Twist
00012 
00013 x_speed = 0.1  # 0.1 m/s
00014 
00015 # this quick check means that the following code runs ONLY if this is the 
00016 # main file -- if we "import move" in another file, this code will not execute.
00017 if __name__=="__main__":
00018 
00019     # first thing, init a node!
00020     rospy.init_node('move')
00021 
00022     # publish to cmd_vel
00023     p = rospy.Publisher('cmd_vel', Twist)
00024 
00025     # create a twist message, fill in the details
00026     twist = Twist()
00027     twist.linear.x = x_speed;                   # our forward speed
00028     twist.linear.y = 0; twist.linear.z = 0;     # we can't use these!        
00029     twist.angular.x = 0; twist.angular.y = 0;   #          or these!
00030     twist.angular.z = 0;                        # no rotation
00031 
00032     # announce move, and publish the message
00033     rospy.loginfo("About to be moving forward!")
00034     for i in range(30):
00035         p.publish(twist)
00036         rospy.sleep(0.1) # 30*0.1 = 3.0
00037 
00038     # create a new message
00039     twist = Twist()
00040 
00041     # note: everything defaults to 0 in twist, if we don't fill it in, we stop!
00042     rospy.loginfo("Stopping!")
00043     p.publish(twist)
00044 
00045 
00046 


mini_max_tutorials
Author(s): Michael Ferguson
autogenerated on Mon Jan 6 2014 11:26:48