3

Is there a node or package that can send commands to /cmd_vel to move ATRV-Jr like 2 meters forward or turn it 90 degree to right/left? I don't want to tell the robot to move with specified speed. For example when I use this command rostopic pub /cmd_vel geometry_msgs/Twist '[1.0,0.0,0.0]' '[0.0,0.0,0.0]' the robot starts moving forward until I send another command or send break command.

Maysam
  • 345
  • 3
  • 11

1 Answers1

0

I've found this usefull:

#!/usr/bin/env python
import roslib; roslib.load_manifest('robot_mover')
import rospy

from geometry_msgs.msg import Twist

def mover():
    pub = rospy.Publisher('cmd_vel', Twist)
    rospy.init_node('robot_mover')

    twist = Twist()
    twist.linear.x = 0.1; # move forward at 0.1 m/s   

    rospy.loginfo("Moving the robot forward.")
    pub.publish(twist)
    rospy.sleep(1)

    rospy.loginfo("Moving the robot backward.")
    twist.linear.x = -0.1; # move backward at 0.1 m/s
    pub.publish(twist)
    rospy.sleep(1);

    rospy.loginfo("Turning the robot left.");
    twist = Twist();
    twist.angular.z = 0.5
    pub.publish(twist)
    rospy.sleep(1);

    rospy.loginfo("Turning the robot right.");
    twist.angular.z = -0.5
    pub.publish(twist)
    rospy.sleep(1);

    rospy.loginfo("Stopping!")
    twist = Twist()
    pub.publish(twist)

    rospy.loginfo("Node exiting.");

if __name__ == '__main__':
    try:
        mover()
    except rospy.ROSInterruptException: pass

Source: http://pharos.ece.utexas.edu/wiki/index.php/Writing_A_Simple_Node_that_Moves_the_iRobot_Create_Robot

Maysam
  • 345
  • 3
  • 11