rosbag to variable

asked 2015-11-03 06:21:56 -0500

Carollour gravatar image

updated 2015-11-03 07:49:14 -0500

HI,

I have saved a rosbag with the goal topic of an action:

...
messages:    1
compression: none [1/1 chunks]
types:       control_msgs/FollowJointTrajectoryActionGoal [cff5c1d533bf2f82dd0138d57f4304bb]
topics:      /robot_joint_trajectory_action_controller/follow_joint_trajectory/goal   1 msg     : control_msgs/FollowJointTrajectoryActionGoal

What I was trying to do was to copy this 1 message to a variable so I can call the service with this saved goal within my cpp node:

rosbag::Bag bag;
bag.open("test.bag", rosbag::bagmode::Read);

std::vector<std::string> topics;
topics.push_back(std::string("/robot_joint_trajectory_action_controller/follow_joint_trajectory/goal"));

rosbag::View view(bag, rosbag::TopicQuery(topics));

foreach(rosbag::MessageInstance const m, view)
{
    control_msgs::FollowJointTrajectoryActionGoal::ConstPtr s = m.instantiate<control_msgs::FollowJointTrajectoryActionGoal>();
    if (s != NULL){
        goal=s;
    }
}

bag.close();

//ac.sendGoal(goal);

//wait for the action to return
bool finished_before_timeout = ac.waitForResult(ros::Duration(30.0));

if (finished_before_timeout)
{
    actionlib::SimpleClientGoalState state = ac.getState();
    ROS_INFO("Action finished: %s",state.toString().c_str());
}
else{
    ROS_INFO("Action did not finish before the time out.");
}

Of course i cannot do s=goal. How to do this?

Thanks!

edit retag flag offensive close merge delete