Ask Your Question
1

subscribe to imu <Solved>

asked 2016-06-15 10:58:03 -0500

ghaith gravatar image

updated 2016-06-16 08:04:56 -0500

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;

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2016-06-15 11:03:54 -0500

updated 2016-06-16 06:17:35 -0500

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; 
}
edit flag offensive delete link more

Comments

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

ghaith gravatar imageghaith ( 2016-06-16 06:13:07 -0500 )edit

thanks alot this work thanks ^_^"

ghaith gravatar imageghaith ( 2016-06-16 06:57:11 -0500 )edit

If it is working, please, mark the answer as solved.

Pablo Iñigo Blasco gravatar imagePablo Iñigo Blasco ( 2016-06-16 12:08:09 -0500 )edit
0

answered 2016-06-16 05:02:15 -0500

asimay_y gravatar image

updated 2016-06-16 05:03:57 -0500

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; }

edit flag offensive delete link more

Comments

i use this but it's not work i got this msg n ‘void handle_imu(const ConstPtr&)’: /home/owner/catkin_ws/src/beginner_tutorials/src/base_controller.cpp:41:30: error: ‘const struct sensor_msgs::Imu_<std::allocator<void> >’ has no member named ‘x’ { gyro_x = angular_velocity->x;

ghaith gravatar imageghaith ( 2016-06-16 05:32:14 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-15 10:58:03 -0500

Seen: 1,817 times

Last updated: Jun 16 '16