How do I write a C++ code to record variable location of robot in rosbag file?
I have written a code to record in rosbag file. But if the rosbag file starts, then the robot does not move because of sequential way of code. Here is that part of code :
i=system("rosbag record -a");
while(ros::ok())
{
//Declares the message to be sent
geometry_msgs::Twist msg;
msg.linear.x=3;
msg.angular.z=-0.3;
//Publish the message
pub.publish(msg);
//Delays until it is time to send another message
rate.sleep();
}
I need to record in rosbag file while simultaneously moving the robot, then after sometime close the file. How to do that?
maybe checking out this discussion helps.
I already checked it. It only provides the way to start rosbag file in a code, which I did. I need to simultaneously move the robot and later close the file through code.
You can use a service to close the file when you want.
Can you explain me on how to use a service? I am unaware of that. Are you talking about something of service-client kind?
Yes it's another way to communicate with ROS nodes. Services allow you to communicate with nodes at a given time.
You can look to the ros wiki for more information : http://wiki.ros.org/ROS/Tutorials/WritingServiceClient(c%2B%2B))