Welcome to ROS Robot Expansion Board repository
4. Robot state estimation
4、Robot state estimation
4.1、run
4.1.1、code reference path
~/driver_ws/src/yahboomcar_bringup/launch/bringup.launch
4.1.1、start
xxxxxxxxxxcd ~/driver_ws/src/yahboom_bringup/launchroslaunch bringup.launch

4.1.1、View tf tree and node graph
1)、View TF tree
xxxxxxxxxxrosrun rqt_tf_tree rqt_tf_tree

2)、View Node Graph
xxxxxxxxxxrosrun rqt_graph rqt_graph

4.1.2、launch file analysis
In the bringup.launch file, there are several important nodes
1)、/drive_node
This node mainly publishes /imu/imu_raw and /vel_raw data, terminal input
xxxxxxxxxxrosnode info /driver_node

As can be seen,
- The /driver_node node publishes the /imu/imu_raw topic data to the /imu_filter_madgwick node, which filters and fuses the imu data;
- The /driver_node node publishes the /vel_raw topic data to the /odometry_publisher node. After the latter is integrated, the /odom_raw data is published;
2)、/odometry_publisher
This node mainly receives the vel_raw topic data sent by the /driver_node node, publishes the /odom_raw topic data to /ekf_localization, and publishes the /tf topic data to other nodes, terminal input,
xxxxxxxxxxrosnode info /odometry_publisher

3)、/imu_filter_madgwick
This node mainly filters and fuses imu data, and then publishes the processed /imu/imu_data topic data to the /ekf_localization node to receive and publish /tf data to other nodes, terminal input,
xxxxxxxxxxrosnode info /imu_filter_madgwick

4)、/ekf_localization
This node mainly integrates imu data and odom data and publishes tf data, terminal input,
xxxxxxxxxxrosnode info /ekf_localization

Next, we describe these nodes in detail.
4.1.3、imu_filter_madgwick
1)、Introduction
IMU refers to a six-axis sensor that includes a gyroscope and an accelerometer. MARG refers to a nine-axis sensor that adds a magnetometer to the IMU.
xxxxxxxxxxIMU = gyroscope + accelerometerMARG(Magnetic, Angular Rate, and Gravity) = gyroscope + accelerometer + magnetometerMadgwick is an Orientation Filter that filters and fuses raw data from IMU devices. It fuses angular velocity, acceleration, and (optionally) magnetometer readings from generic IMU devices into orientation quaternions, and publishes the fused data on the IMU topic without considering the entire IMU integration process.
2)、Topic
| / | Topic Name | Type | Attributes |
|---|---|---|---|
| Subscribed | /imu/data_raw | sensor_msgs/Imu | 校准后的IMU数据的消息,包括角速度和线加速度 |
| Subscribed | /imu/mag | sensor_msgs/MagneticField | [可选]磁力计,会受磁场影响 |
| Published | /imu/data | sensor_msgs/Imu | 融合的Imu信息。 |
3)、parameter
| Topic Name | Type | Defaults | Attributes |
|---|---|---|---|
| ~gain | double | 0.1 | filter gain Higher values result in faster convergence but more noise.。 The lower the value, the slower the convergence, but the smoother the signal. Range: 0.0 to 1.0 |
| ~zeta | double | 0.0 | Gyro drift gain (about rad/s). Range: -1.0 to 1.0 |
| ~mag_bias_x | double | 0.0 | Magnetometer bias (hard iron corrected), x-component. Range: -10.0 to 10.0 |
| ~mag_bias_y | double | 0.0 | Magnetometer bias (hard iron correction), y component. Range: -10.0 to 10.0 |
| ~mag_bias_z | double | 0.0 | Magnetometer bias (hard iron correction), z component. Range: -10.0 to 10.0 |
| ~orientation_stddev | double | 0.0 | The standard deviation of the orientation estimate. Range: 0.0 to 1.0 |
| ~world_frame | string | "nwu" | World frame indicating direction (see REP-145). The old default was "nwu" (northwest up). New deployments should use "enu". Valid values: "nwu", "enu", "ned". |
| ~use_mag | bool | true | Whether to use magnetic field data in data fusion. |
| ~use_magnetic_field_msg | bool | false | If set to true, subscribe /imu, /mag topics as sensor_msgs/MagneticField; if set to false (deprecated), use geometry_msgs/Vector3Stamped |
| ~fixed_frame | string | odom | Parent coordinate system to use in publishing |
| ~publish_tf | bool | false | Whether to publish the TF transformation representing the direction of the IMU as the pose of the IMU; use the fixed coordinate system as the parent coordinate system, and the input imu information as the child coordinate system |
| ~reverse_tf | bool | false | If set to true, the transformation from the imu coordinate system to the fixed coordinate system is published, not the other way around. |
| ~constant_dt | double | 0.0 | The dt to use; if 0.0 (default), the dt dynamic value is calculated from the message start position. |
| ~publish_debug_topics | bool | false | If set to true, two debug topics are published. |
| ~stateless | bool | false | If set to true, the filtered orientation is not published. Instead, a stateless estimate of orientation is published based only on the latest accelerometer (and optional magnetometer) readings. for debugging. |
| ~remove_gravity_vector | bool | false | If set to true, the gravity vector is subtracted from the acceleration field in the published IMU message. |
4.1.4、robot_localization
1)、Introduction
robot_localization is a collection of state estimation nodes, each node is an implementation of a nonlinear state estimator for robots moving in 3D space. It includes two state estimation nodes ekf_localization_node and ukf_localization_node. Also, robot_localization provides navsat_transform_node, which helps to integrate GPS data.
ekf_localization_node is an implementation of Extended Kalman Filter. It uses an omnidirectional motion model to predict states in time and uses sensed sensor data to correct the predicted estimates.
ukf_localization_node is an implementation of Unscented Kalman Filter. It uses a carefully chosen set of sigma points to project the state through the same motion model used in the EKF, and then uses these projected sigma points to recover the state estimate and covariance. This eliminates the use of the Jacobian matrix and makes the filter more stable. However, it is also more computationally heavy compared to ekf_localization_node.
2)、Topic
| / | Topic Name | Type | Attributes |
|---|---|---|---|
| Subscribed | /imu/data | sensor_msgs/Imu | Filtered imu information |
| Subscribed | /odom_raw | nav_msgs/Odometry | Odometer Information |
| Published | /odom | nav_msgs/Odometry | Fusion odometer information |
| Published | /tf | tf2_msgs/TFMessage | Coordinate system information |
3)、Parameter
frequency: The true frequency (in Hz) at which the filter produces state estimates. Note: The filter will not start computing until at least one message has been received from one of the inputs.
[sensor] : For each sensor, the user needs to define this parameter according to the message type. Each parameter name is indexed from 0 (e.g. odom0, odom1, etc.) and must be defined in order (e.g. don't use pose0 and pose2 if pose1 is not already defined). The value of each parameter is the topic name for that sensor.
xxxxxxxxxxodom0: /odom_rawimu0: /imu/data[sensor]_differential: For each sensor message defined above that contains pose information, the user can specify whether the pose variables should be integrated differentially. If the given value is set to true, then for the measurement taken at time t from the relevant sensor, we will first subtract the measurement at time t-1 and then convert the resulting value to velocity.。
xxxxxxxxxx~odomN_differential~imuN_differential~poseN_differential[sensor]_relative: If this parameter is set to true, any measurements from this sensor will be fused relative to the first measurement received from this sensor. This is useful, for example, if you want the state estimate to always start at (0,0,0) and the roll, pitch and yaw angle values to be (0,0,0).
xxxxxxxxxx~odomN_relative~imuN_relative~poseN_relativetwo_d_mode: Set this to true if your robot operates in a flat environment and can ignore small changes in the ground (as reported by the IMU). It fuses all 3D variables (Z, roll, pitch and their respective velocity and acceleration) into a value of 0. This ensures that the covariances of these values don't explode, while ensuring that your robot's state estimate remains fixed in the X-Y plane.
odom0_config:[ false, false, false, false, false, false, true, true, false, false, false, true, false, false, false ]
The order of Boolean values is: [[X],[Y],[Z],[roll],[pitch],[yaw],[X ' ],[Y ' ],[Z ' ],[roll '] ,[pitch '],[yaw '],[X ''],[Y ''],[Z '']]. The user must specify which variables of these messages should be fused into the final state estimate.
4)、Published Transform
If the user's world_frame parameter is set to the value of odom_frame, the transformation is posted from the coordinate system given by the odom_frame parameter to the coordinate system given by the base_link_frame parameter. If the user's world_frame parameter is set to the value of map_frame, the transformation is published from the coordinate system given by the map_frame parameter to the coordinate system given by the odom_frame parameter.
For example, we set to publish the transformation from the coordinate system given by the [odom_frame] parameter to the coordinate system given by the [base_link_frame] parameter.
xxxxxxxxxxodom_frame: odombase_link_frame: base_footprintworld_frame: odom
