Ask Your Question

Revision history [back]

You should have a look at the ROS Navigation Stack, that contains the components to implement a full autonomous navigation.

Among these packages, the one responsible for moving the robot is MoveBase. This provides you API for moving the robot toward a goal. This goal could be computed in local coordinates and it could easily represent the concept of "X meters in front of the robot". The "problem" is that you will also need a localization package in order to understand when the robot has really traveled that distance. Something very simple could be dead reckoning, i.e. just looking at the wheel encoders.

The Navigation stack contains tutorial for setting up all what you need.

However, in an extremely oversimplified scenario, if you know that your robot moves at 1m/s you can create a function that publishes the "move forward command" that you are executing through the keyboard for the required amount of time to cover your distance. This "command" will be a message of type geometry_msgs/Twist on topic cmd_vel.

You should have a look at the ROS Navigation Stack, that contains the components to implement a full autonomous navigation.

Among these packages, the one responsible for moving the robot is MoveBase. This provides you API for moving the robot toward a goal. This goal could be computed in local coordinates and it could easily represent the concept of "X meters in front of the robot". The "problem" is that you will also need a localization package in order to understand when the robot has really traveled that distance. Something very simple could be dead reckoning, i.e. just looking at the wheel encoders.

The Navigation stack contains tutorial for setting up all what you need.

However, in an extremely oversimplified scenario, if you know that your robot moves at 1m/s you can create a function that publishes the "move forward command" that you are executing through the keyboard for the required amount of time to cover your distance. This "command" will be a message of type geometry_msgs/Twist on topic cmd_vel.

EDIT:

I don't advise you to run something as "move randomly for 30 seconds" on a turtlebot, if you don't want to crash it against a wall. Anyhow, you can do something like

import rospy
from geometry_msgs.msg import Twist

pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
rospy.init_node('node_name')
r = rospy.Rate(30) # 30hz

total_time = 10 #seconds
start_time = time.time()

while not rospy.is_shutdown() and (time.time() - start_time < total_time):

    msg = Twist()

    # here you should fill the msg fields
    # http://docs.ros.org/api/geometry_msgs/html/msg/Twist.html
    # you can fill it randomly or with a direction in mind

    pub.publish(msg)
    r.sleep()

You should have a look at the ROS Navigation Stack, that contains the components to implement a full autonomous navigation.

Among these packages, the one responsible for moving the robot is MoveBase. This provides you API for moving the robot toward a goal. This goal could be computed in local coordinates and it could easily represent the concept of "X meters in front of the robot". The "problem" is that you will also need a localization package in order to understand when the robot has really traveled that distance. Something very simple could be dead reckoning, i.e. just looking at the wheel encoders.

The Navigation stack contains tutorial for setting up all what you need.

However, in an extremely oversimplified scenario, if you know that your robot moves at 1m/s you can create a function that publishes the "move forward command" that you are executing through the keyboard for the required amount of time to cover your distance. This "command" will be a message of type geometry_msgs/Twist on topic cmd_vel.

EDIT:

I don't advise you to run something as "move randomly for 30 seconds" on a turtlebot, if you don't want to crash it against a wall. Anyhow, you can do something like

import rospy
from geometry_msgs.msg import Twist

pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
rospy.init_node('node_name')
r = rospy.Rate(30) # 30hz

total_time = 10 #seconds
start_time = time.time()

while not rospy.is_shutdown() and or (time.time() - start_time < total_time):

    msg = Twist()

    # here you should fill the msg fields
    # http://docs.ros.org/api/geometry_msgs/html/msg/Twist.html
    # you can fill it randomly or with a direction in mind

    pub.publish(msg)
    r.sleep()