rosbag::MessageInstance derefenced pointer error
I am trying to follow this sample code to pull data from a bag file but am running into a bug that I cannot figure out. Hopefully this is the right forum to ask this in.
The c++ api specially "Example usage for read:" of the link below. http://wiki.ros.org/rosbag/Code%20API
I successfully recreated the write/read bag file examples, but when trying to apply to my own problem I cannot access the data within the returned pointer of rosbag::MessageInstance.instantiate().
I have a bag file containing topic /robot_mode of type std_msgs::Int8 that I would like to access its data member. However the call to robot_mode_p->data returns strange items.
Sample code:
BOOST_FOREACH(rosbag::MessageInstance const m, view)
{
cout << m.getTopic() << endl;
if (m.getTopic() == mode_topic )
{
std_msgs::Int8::ConstPtr robot_mode_p = m.instantiate<std_msgs::Int8>();
std::string message_def = m.getDataType();
cout << message_def << endl;
cout << "robot_mode_p: " << *robot_mode_p << endl;
if (robot_mode_p != nullptr)
cout << "Dereferenced robot_mode: " << robot_mode_p->data << endl;
}
}
I would expect in output of:
/robot_mode
std_msgs/Int8
robot_mode_p: data: 24
Dereferenced robot_mode: 24
But my code outputs:
/robot_mode
std_msgs/Int8
robot_mode_p: data: 24
Dereferenced robot_mode:
Any help is much appreciated. Thanks!
drive folder for bag file and sample code if interested: https://drive.google.com/drive/folder...