Rosanswers logo

hi i am trying to subscribe to an imu data the imu is connected to arduino mega when i run arduino it work fine and when i see the topic there is an imu data that is publish and i can see it change but when i try to subscribe to it i git this error [WARN] [WallTime: 1466005750.393726] Could not process inbound connection: topic types do not match: [geometry_msgs/Vector3] vs. [sensor_msgs/Imu]{'topic': '/imu', 'tcp_nodelay': '0', 'md5sum': '4a842b65f413084dc2b10fb484ea7f17', 'type': 'geometry_msgs/Vector3', 'callerid': '/base_controller_node'} i use indigo

i subscribe as follow:

void handle_imu( const geometry_msgs::Vector3 angular_velocity) {

gyro_x = angular_velocity.x;

gyro_y = angular_velocity.y;

gyro_z = angular_velocity.z; }

and in the arduino code i use

#include <sensor_msgs/Imu.h> i need to know is there any other way to subscribe to imu and why this problem occure thanks i wish you can help.

this is how i subscribe to the imu :

int main(int argc, char** argv){

ros::init(argc, argv, "base_controller");

ros::NodeHandle n;

ros::NodeHandle nh_private_("~");

ros::Subscriber sub = n.subscribe("rpm", 50, handle_rpm);

ros::Subscriber imu_sub = n.subscribe("imu", 50, handle_imu);

ros::Publisher odom_pub = n.advertise<nav_msgs::Odometry>("odom", 50);

tf::TransformBroadcaster broadcaster;

i need to git the the angular velocity

note: i tried this void handle_imu(const sensor_msgs::Imu::ConstPtr &angular_velocity)

{ gyro_x = angular_velocity->x;

gyro_y = angular_velocity->y;

gyro_z = angular_velocity->z; } and i got the following msg

r: ‘const struct sensor_msgs::Imu_std::allocator<void >’ has no member named ‘x’ { gyro_x = angular_velocity->x; ^ /home/owner/catkin_ws/src/beginner_tutorials/src/base_controller.cpp:43:28: error: ‘const struct sensor_msgs::Imu_std::allocator<void >’ has no member named ‘y’ gyro_y = angular_velocity->y; ^ /home/owner/catkin_ws/src/beginner_tutorials/src/base_controller.cpp:45:28: error: ‘const struct sensor_msgs::Imu_std::allocator<void >’ has no member named ‘z’ gyro_z = angular_velocity->z;

Originally posted by ghaith on ROS Answers with karma: 89 on 2016-06-15

Post score: 1


1 Answer 1


Rosanswers logo

the topic types does not mach.

You must not subscribe to the imu topic as a vector3 type but as a sensor_msgs/Imu type.

In your code, you are subscribing to a topic called "imu" that must have a Vector3 type.

However, in practice the sensor publishes messages on the "imu" topic with type sensor_msgs/Imu. These are the fields of a sensor_msgs/Imu:

std_msgs/Header header
geometry_msgs/Quaternion orientation
float64[9] orientation_covariance
geometry_msgs/Vector3 angular_velocity
float64[9] angular_velocity_covariance
geometry_msgs/Vector3 linear_acceleration
float64[9] linear_acceleration_covariance

You have to take the orientation field (that it is a quaternion) and convert it to euler angles (roll, pitch, yaw)... then you will have the three values you are looking. In order to do that you can use the conversion functions that exist in the "tf" library.

This would be approximately a more correct code:

void handle_imu(const sensor_msgs::Imu::ConstPtr &msg)
   gyro_x = msg->angular_velocity.x;
   gyro_y = msg->angular_velocity.y;
   gyro_z = msg->angular_velocity.z; 

Originally posted by Pablo Iñigo Blasco with karma: 2982 on 2016-06-15

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by ghaith on 2016-06-16:
how i can take the angular velocity value just this or is there any other way to publish just the gyro and subscribe to it

Comment by ghaith on 2016-06-16:
thanks alot this work thanks ^_^"

Comment by Pablo Iñigo Blasco on 2016-06-16:
If it is working, please, mark the answer as solved.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.