0
$\begingroup$

Rosanswers logo

Currently this is the code that I have, and I am able to get the robot moving by editing the linear x or angular z values (speed).

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>

int main(int argc, char **argv)
{
ros::init(argc, argv, "move_pub");
ros::NodeHandle n;
ros::Publisher movement_pub = n.advertise<geometry_msgs::Twist>("mobile_base/commands/velocity",1); 
ros::Rate rate(10);

while (ros::ok()) 
{
    geometry_msgs::Twist move;
    //velocity controls
    move.linear.x = -0.1; //speed value m/s
    move.angular.z = 0;
    movement_pub.publish(move);

    ros::spinOnce();
    rate.sleep();
}
return 0;
}

Is there a time control in ROS? Whereby I can do something like while time <= 5s, publish linear x velocity of 0.2m/s. Thus, covering 1 meter. I am new to ROS and it is my first week into it. Im working on the TurtleBot 2.


Originally posted by dylankc on ROS Answers with karma: 13 on 2015-03-16

Post score: 1


Original comments

Comment by gvdhoorn on 2015-03-16:
Also see robot pose slightly off when publishing to /cmd_vel for some discussion on the feasibility of what you are trying to achieve.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

There is ros::Time and ros::Duration, which can be used in an intuitive way. ros::Time::now() gives you the current time. You probably want something like:

ros::Time start = ros::Time::now()
while(ros::Time::now() - start < ros::Duration(5.0))
    ...

Originally posted by dornhege with karma: 31395 on 2015-03-16

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by dylankc on 2015-03-16:
Thank you dornhege for teaching me about the ros::Time & ros::Duration function. However, i've taken a look at "http://answers.ros.org/question/204973/robot-pose-slightly-off-when-publishing-to-cmd_vel/" and realized that my method is prone to inaccuracy!

I'll try publishing to /odom.

Comment by dylankc on 2015-03-16:
I appreciate your help very much. Thank you

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.