LORD-MicroStrain / microstrain_inertial

ROS driver for all of MicroStrain's current G and C series products. To learn more visit
https://www.microstrain.com/inertial
97 stars 72 forks source link

odom velocity mesaurement are not relative to vehicle frame #275

Closed CaptKrasno closed 10 months ago

CaptKrasno commented 1 year ago

Describe the bug The velocity measurement in nav/relative_pos/odom are relative to vehicle frame even with:

filter_vel_in_vehicle_frame:  true  # default value

In fact, the velocities don't seem to consistently match those int the ENU/NED frame

See the screenshots below

Screenshot from 2023-09-01 16-37-28 In the above example the vehicle is moving straight ahead at 1.5 m/s. I would expect to see nav/relative_pos/odom/twist/twist/x ~= 1.5 and nav/relative_pos/odom/twist/twist/y ~= 0 in this case. However, as you can see In this screenshot the nav/relative_pos/odom velocities seem reasonable for the ENU frame given the plots of x/y position.

Screenshot from 2023-09-01 16-39-47 The above is an earlier part of the same recording. In this screenshot you can see that even though the x position has a negative slope nav/relative_pos/odom/twist/twist/x ~= 0. The y position has a slope near zero slope but nav/relative_pos/odom/twist/twist/y ~= -1.5

To Reproduce Steps to reproduce the behavior:

  1. use this launch file with default arguments asv-trevor-launch
  2. see the associated yaml file

Expected behavior See screenshots above

Environment (please complete the following information):

Modifications None

Launch Parameters asv-trevor-launch

[associated yaml file](https://github.com/USF-COMIT/trevor/blob/f9036dc1f14a78f6f4afaaae9b82e18573287a4c/trevor/config/microstrain.yaml

jpace121 commented 1 year ago

I'm seeing the same issue.

Specifically, I have set filter_vel_in_vehicle_frame to True in my config.

I have a GQ7 rigidly attached to an Ackermann steered vehicle, which I'm driving relatively slowly in a parking lot in a half circle. In the base_link frame I would expect the linear velocity to be almost entirely in the x direction. I don't see that.

If I integrate the velocities in the x direction and the separately integrate the y velocities the resulting path looks like the half circle I actually drove, implying the velocities are being reported in a fixed frame, not base_link.

I modified the driver to add the following log statement:

diff --git a/src/publishers.cpp b/src/publishers.cpp
index 983e8f7..7fd686b 100644
--- a/src/publishers.cpp
+++ b/src/publishers.cpp
@@ -736,6 +736,7 @@ void Publishers::handleFilterAttitudeQuaternion(const mip::data_filter::Attitude

   // Save the quaternion for later
   filter_attitude_quaternion_ = tf2::Quaternion(attitude_quaternion.q[1], attitude_quaternion.q[2], attitude_quaternion.q[3], attitude_quaternion.q[0]);
+  ROS_ERROR_STREAM("Saving for later. " << filter_attitude_quaternion_.getAngle());
 }

 void Publishers::handleFilterEulerAnglesUncertainty(const mip::data_filter::EulerAnglesUncertainty& euler_angles_uncertainty, const uint8_t descriptor_set, mip::Timestamp timestamp)
@@ -781,6 +782,7 @@ void Publishers::handleFilterVelocityNed(const mip::data_filter::VelocityNed& ve
   // If we are publishing velocity in the vehicle frame, rotate the velocity using the attitude
   if (config_->filter_vel_in_vehicle_frame_)
   {
+      ROS_ERROR_STREAM("Rotating filter to vehicle frame. Using: " << filter_attitude_quaternion_.getAngle());
     const tf2::Vector3 filter_current_vel(filter_odom_msg->twist.twist.linear.x, filter_odom_msg->twist.twist.linear.y, filter_odom_msg->twist.twist.linear.z);
     const tf2::Vector3 filter_rotated_vel = tf2::quatRotate(filter_attitude_quaternion_.inverse(), filter_current_vel);
     filter_odom_msg->twist.twist.linear.x = filter_rotated_vel.getX();

and can tell from that that when I'm running the driver, the driver does think config->filter_vel_in_vehicle_frame_ is true and that the angle in fitler_atittude_quaternion_ is changing logically.

robbiefish commented 1 year ago

I need to get setup to test, but we were using the NED rotation to rotate the velocity even when use_enu_frame was true. I will do some testing ASAP to see if this fixes your issue, but in the meantime if anyone wants to test, the code is in the following branches

jpace121 commented 1 year ago

Hi!

I tried running bugfix/ros_vel_in_sensor_frame on our vehicle and it appears to have fixed the issue, though as you note in the change to the default params, it puts the velocity in the sensor frame, not the vehicle frame, which is fine by me, I can handle that in tf by properly labeling the frames in the config.

Thanks for the quick turnaround!

github-actions[bot] commented 12 months ago

This issue is stale because it has been open for 2 weeks with no activity. If the issue is still not resolved, please leave a comment describing what is still not working

jpace121 commented 12 months ago

Hi @robbiefish, we've been running with the fix in https://github.com/LORD-MicroStrain/microstrain_inertial/tree/bugfix/ros_vel_in_sensor_frame for the last few weeks, and it appears to fix the issue described in this Issue.

Are there any plans to have that branch merged and released on the build farm?

github-actions[bot] commented 11 months ago

This issue is stale because it has been open for 2 weeks with no activity. If the issue is still not resolved, please leave a comment describing what is still not working

github-actions[bot] commented 10 months ago

This issue was closed because it has been inactive for 2 weeks since being marked as stale. If the issue is still not resolved, please reopen the issue, and leave a comment describing what is still not working

martfrau commented 10 months ago

I tested the bugfix/ros2_vel_in_sensor_frame branch with the 3DM-GQ7 device and it is not working correctly.

This is my setup:

I drove a short round in clockwise direction for each of these 4 parameter configurations:

As can be seen in the following plot, the x-acceleration (topic imu/data; field linear_acceleration.x) is positive during the first 6 seconds for all configurations. But the x-velocity (topic nav/odom; field twist.twist.linear.x) goes negative even though the x-axis points forward and filter_sensor2vehicle_frame_transformation_euler:=[0.0, 0.0, 0.0].

image

I have attached the 4 parameter files used during the measurements: parameter_files.zip

martfrau commented 10 months ago

I opened a new issue since this issue is already closed. See issue https://github.com/LORD-MicroStrain/microstrain_inertial/issues/287.