How to get X Y Z Data from IMU seperated

I need for a small Experiment the X Y Z Datas seperated from the IMU Topic ( Not the complete Datas from the IMU Topic) . I will read this Data in Java Script . So That i have an ID for Pitch, another for Roll, and anozher for YAW. Is this possible ?

Do you mean the IMU connected to the CORE2 board? Do you use any nodes to process the raw data into sensor_msgs/IMU messages? Or do you just have the imu/gyro, imu/accel topics?

yes i mean the IMU on the Core2 Ros. What i need for the Web UI is the the Pitch , Roll and YAW Data. The Problem is that i get this Data only in a String ???. I want to Have an ID (Or what else) for Pitch, another ID for Yaw and Another for Roll. The Reason is a Funktion to Stabilise a Dynamixel Servo (Deeeeeep Alpa Idea) and show the Data in a Canvas Element at the same time. Withe another IMU , based on a ESP it works. The Idea is to use the internal one. It doesn´t matter when the Data comes is Radiant. I can use Math Funktions in JAva Script to make Degrees. Another Problem is that the Datas are come with 2.112231232312321 - thats to much. Better is 2.11 RAD or so .

I know that i can read via Java Script the IMU Message. But when i do that i get the Orientation Data in one String- not seperatet. For my little Project i need the Pitch , Roll and JAW Data like that

sensor_msg/IMU/PITCH
sensor_msg/IMU/ROLL
sensor_msk/IMU/YAW (Heading)

Are you using roslibjs? If so, you should be able to get the IMU messages as a JSON object, not as Strings. You can look at how the battery voltage is retrieved in leo_ui

Here the battery topic is subscribed:

And here is the callback:

The message field here is the std_msgs/Float32 message as a JSON object. The message.data is the voltage as a float. You can see it being converted to String with 4 precision points by the toPrecision method.

Thank you for your Reply,

i use the Roslib.js. The Problem is the IMU Message. Its not the same like Battery. It gives no Message only for the X Axes or the Z Axes,… . I´ve looked into the Firmware and i can´t find a Axes Publisher. Only the imu_gyro_msg. So i get only the complete Message and that is very hard to cut.

// IMU
if (conf.imu_enabled) {
imu_gyro_pub = new ros::Publisher(“imu/gyro”, &imu_gyro_msg);
imu_accel_pub = new ros::Publisher(“imu/accel”, &imu_accel_msg);
imu_mag_pub = new ros::Publisher(“imu/mag”, &imu_mag_msg);
auto imu_cal_mpu_srv = new ros::ServiceServer<std_srvs::TriggerRequest,
std_srvs::TriggerResponse>(
“imu/calibrate_gyro_accel”, &calMpuCallback);
auto imu_cal_mag_srv = new ros::ServiceServer<std_srvs::TriggerRequest,
std_srvs::TriggerResponse>(
“imu/calibrate_mag”, &calMagCallback);
nh.advertise(*imu_gyro_pub);
nh.advertise(*imu_accel_pub);
nh.advertise(*imu_mag_pub);
nh.advertiseService<std_srvs::TriggerRequest, std_srvs::TriggerResponse>(
*imu_cal_mpu_srv);
nh.advertiseService<std_srvs::TriggerRequest, std_srvs::TriggerResponse>(
*imu_cal_mag_srv);
}

I didn´t know how the IMU Publisher work, but it must be possible to publish X,Y,Z seperatly.

I don’t know if I understood correctly, but you can access the individual fields of the message when using roslibjs. For example, if you created a subscriber for imu/gyro messages, you can access the angular speed around X axis under message.vector.x.

1 Like

OK :- :open_mouth: . I will try :slight_smile:

Thank you

      
          function vector.xSubCallback(message) {
              document.getElementById('VectorXID').innerHTML = 'X-AXE: ' + message.data.toPrecision(4) + 'RAD';
          }
      
    

Like This ?

No, more like this:

gyroxSub = new ROSLIB.Topic({
              ros : ros,
              name : 'imu/gyro',
              messageType : 'geometry_msgs/Vector3Stamped',
              queue_length: 1
          });
gyroxSub.subscribe(GyroCallback);

function GyroCallback(message) {
              document.getElementById('VectorXID').innerHTML = 'X-AXE: ' + message.vector.x.toPrecision(4) + ' RAD/S';
}
1 Like

You can’t subscribe to specific data from the topic, you have to subscribe to the whole messages which are of geometry_msgs/Vector3Stamped type in this case.

Then, in the callback function, you can just extract the data you want from the messages.

1 Like

WOOOOOOW. It Works :-)))))))

That´s a mega GOAL and CUT MAX PROBLEMS FROM MY LIST.

THANK YOU VERY MUCH

1 Like

a short question. Is it possible to convert the data Rad/s into Grad / s?. I am not shure how to implement the multiplikator or Math Funktions .

Thank you

I’m not really experienced with Javascript, but maybe try it like that:

(message.vector.x * (180.0 / Math.PI)).toPrecision(4)

That works fine, but a new Problem is that i have to do a lot of mathematics to change RAD/s or GRAD/s to a Angle. I know that the Datas from Gyro (via Ros) give me the Vector. But what i need is only the aktual Angle from Roll and Pitch. A Heading will be also fine.

If you want to get the actual orientation of the IMU, you will need to do a little more. Check out the Autonomous Navigation tutorial up to the 3D odometry section.

In short, if you will build the leo_navigation package and run:

roslaunch leo_navigation odometry.launch three_d:=true

you should get the sensor_msgs/IMU messages on the /imu/data topic with the orientation filtered from gyroscope and accelerometer reading.

The only problem is that the orientation is represented as a Quaternion, not Euler or RPY angles so you will need to do a little bit of math to convert this representation.

Sorry for my late Replay. I have to work outside at the Moment. I will will try the Navigation Package. I´ve found a Code on the Husarion Website - maybe will help . I will post the Result .

Thank for your help

I´ve readed a little bit in the Rosbot (Husarion Firmware). I´ve found some different´s about the same Sensor. . Is it possible to publish the same Orientation.msg in the Leo Firmware. (Vector3 ?)

Another stupid Problem what i not understand. I have made a new installation of the Software/Firmware to the actual Version. Everything is fine. I have Set Up the Imu and the Datas are running.

Thats the edited Xacro file :

<?xml version="1.0" encoding="utf-8"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro"
       name="leo">

  <xacro:include filename="$(find leo_description)/urdf/macros.xacro"/>

  <xacro:leo default_antenna="true"
             rockers_fixed="true"
             footprint_link="true"
             link_prefix=""
             joint_prefix=""/>

<link name="imu"/>

<joint name="imu_joint" type="fixed">

  <parent link="base_link"/>

  <child link="imu"/>

  <origin xyz="0.027 0 -0.07" rpy="0 0 0"/>

</joint>

</robot>

When i type rosrun tf tf_echo base_link imu - it will give me only Data in Zero and nothing change. Is something missing ?

When i start

roslaunch leo_navigation odometry.launch three_d:=true

and show me the datas - Everything is good.

Orientation (Quant) x,y,z,w
angular_velocity
linear acceleration

i am a little bit confused :slight_smile:

An the next thing - how can i get the Data . I didn´t now how to change the topic in Leo.JS

That was the old one

gyroxSub = new ROSLIB.Topic({
              ros : ros,
              name : 'imu/gyro',
              messageType : 'geometry_msgs/Vector3Stamped',
              queue_length: 1
          });
gyroxSub.subscribe(GyroCallback);

function GyroCallback(message) {
              document.getElementById('VectorXID').innerHTML = 'X-AXE: ' + message.vector.x.toPrecision(4) + ' RAD/S';

I know this is a different Message Type. But i doesn´t work for the Quanternien to show.