Help publishing to cmd_vel and subscribing to LaserScan
Hey guys, I am trying to program a publisher for cmd_vel and a subscriber of base_scan (sensor_msgs/LaserScan, specifically the array ranges). For the first one I know I have to give a command like this:
rostopic pub /cmd_vel geometry_msgs/Twist -r 10000 '[10, 0, 0]' '[0, 0, 5]'
I have tried giving it to the command prompt, and it works. Now, including that in a publisher (I have tried modifying the "talker" one of the tutorials - from here). The thing is I don't know how to modify it to include the command I want to give to it. I tried changing the following line to:
ss << "/cmd_vel geometry_msgs/Twist -r 10000 '[10, 0, 0]' '[0, 0, 5]'";
that belongs to this loop
while (ros::ok())
{ std_msgs::String msg;
std::stringstream ss;
ss << "/cmd_vel geometry_msgs/Twist -r 10000 '[10, 0, 0]' '[0, 0, 5]'";
msg.data = ss.str();
ROS_INFO("%s", msg.data.c_str());
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
But as expected, changing just the string to the command I want to give didn't work. There probably is a really simple way of doing it, but I don't know how.
As for the second task, the subscriber to LaserScan, I know that I have to use the ranges array to visualize the meters to the obstacles, but first of all I don't know how to visualize the array in the command prompt. Once I know that with the previous task answered, I may be able to find out how to do it.
Thanks a lot for all the help and support! (not only here but in all the questions I've been having lately!)