How do I publish ROS messages to ROS_INFO?
I currently have a node that is producing messages of the type 'sensor_msgs' which I would like to see in my /rosout log. My approach was to add a statement similar to the following:
ROS_INFO(sensorMessage);
This produces type conversion errors that I might be able to work around but I feel like there would be an easier solution.
Edit: Here is the full function, with the ROS_INFO statement at the bottom:
void publishData(const Imu::IMUData &data) {
sensor_msgs::Imu imu;
sensor_msgs::MagneticField field;
sensor_msgs::FluidPressure pressure;
// assume we have all of these since they were requested
/// @todo: Replace this with a mode graceful failure...
assert(data.fields & Imu::IMUData::Accelerometer);
assert(data.fields & Imu::IMUData::Magnetometer);
assert(data.fields & Imu::IMUData::Barometer);
assert(data.fields & Imu::IMUData::Gyroscope);
// timestamp identically
imu.header.stamp = ros::Time::now();
imu.header.frame_id = frameId;
field.header.stamp = imu.header.stamp;
field.header.frame_id = frameId;
pressure.header.stamp = imu.header.stamp;
pressure.header.frame_id = frameId;
imu.orientation_covariance[0] =
-1; // orientation data is on a separate topic
imu.linear_acceleration.x = data.accel[0] * kEarthGravity;
imu.linear_acceleration.y = data.accel[1] * kEarthGravity;
imu.linear_acceleration.z = data.accel[2] * kEarthGravity;
imu.angular_velocity.x = data.gyro[0];
imu.angular_velocity.y = data.gyro[1];
imu.angular_velocity.z = data.gyro[2];
field.magnetic_field.x = data.mag[0];
field.magnetic_field.y = data.mag[1];
field.magnetic_field.z = data.mag[2];
pressure.fluid_pressure = data.pressure;
// publish
pubIMU.publish(imu);
ROS_INFO(imu); <-------I want to publish imu data
pubMag.publish(field);
pubPressure.publish(pressure);
if (imuDiag) {
imuDiag->tick(imu.header.stamp);
}
}
Thanks!