ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How do I write a C++ code to record variable location of robot in rosbag file?

asked 2016-06-21 02:04:26 -0500

Pikachu gravatar image

updated 2016-06-21 02:10:48 -0500

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?

edit retag flag offensive close merge delete

Comments

maybe checking out this discussion helps.

mgruhler gravatar image mgruhler  ( 2016-06-21 02:13:38 -0500 )edit

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.

Pikachu gravatar image Pikachu  ( 2016-06-21 03:21:55 -0500 )edit

You can use a service to close the file when you want.

F.Brosseau gravatar image F.Brosseau  ( 2016-06-21 04:05:35 -0500 )edit

Can you explain me on how to use a service? I am unaware of that. Are you talking about something of service-client kind?

Pikachu gravatar image Pikachu  ( 2016-06-21 06:49:16 -0500 )edit

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))

F.Brosseau gravatar image F.Brosseau  ( 2016-06-21 07:49:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-06-28 23:27:55 -0500

shashank gravatar image

updated 2016-06-28 23:28:52 -0500

I think you can create a bag file using rosbag api and write your topics in it .link text

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-06-21 02:04:26 -0500

Seen: 608 times

Last updated: Jun 28 '16