Sensors and state estimation
GPS does not work underwater, so the robot works out its state (position, rotation and speed) from sensors that each give part of the answer. Combining them is state estimation.
The sensors
Section titled “The sensors”The commands below need the simulator, whose sensors publish the same topics as the real ones.
Pressure sensor: how deep am I?
Section titled “Pressure sensor: how deep am I?”Water pressure rises by about 1% of an atmosphere for every 10 cm of depth, so pressure gives depth directly. It is accurate to millimeters and never drifts.
ros2 topic echo --once --field pose.pose.position.z /marlin_v3/odometry/depthGood at: depth. Can’t tell you: anything else.
IMU: how am I rotated?
Section titled “IMU: how am I rotated?”An IMU (Inertial Measurement Unit) is a small chip with a gyroscope, which measures how fast it is rotating, and an accelerometer, which measures acceleration, including gravity.
ros2 topic echo --once --field angular_velocity /marlin_v3/imu/datax: 0.007848796003220932y: -0.002111621477207822z: -0.004037236483260004These are radians per second, nonzero even at rest: that is sensor noise.
The accelerometer senses which way gravity points, so roll and pitch are reliable. Gravity says nothing about which way the robot faces, so yaw comes from adding up the gyroscope’s rate over time, and small errors make it drift, by about 10° an hour. Ours has no magnetic compass to correct it.
Good at: rotation, quickly. Weak at: yaw over a long time.
DVL: how fast am I moving?
Section titled “DVL: how fast am I moving?”A DVL (Doppler Velocity Log) sends four beams of sound down at the pool floor and listens to the echoes. When the robot moves, the echoes’ pitch shifts (the Doppler effect, which makes a passing siren change note), and the shift gives its velocity over the floor. It also measures the distance to the floor, its altitude.
ros2 topic echo --once --field twist.twist.linear /marlin_v3/dvl/velocityros2 topic echo --once --field range /marlin_v3/altitudeWhen it can hear the floor it has bottom lock. It is accurate, but loses lock near walls, and its readings arrive about 0.15 s late.
Good at: speed. Can’t tell you: position directly, only how fast it is changing.
Cameras: what is around me?
Section titled “Cameras: what is around me?”Cameras don’t feed into the position estimate. They are how the robot finds the props: see Computer vision.
Dead reckoning, and why it drifts
Section titled “Dead reckoning, and why it drifts”No sensor measures x and y. Position comes from the DVL’s speed and the IMU’s heading, added up every time step:
position = position + velocity × time stepThis is dead reckoning. Its errors add up and never go away, so the longer the run, the further off the estimate. A hard-coded “swim 10 m forward” is only roughly 10 m, which is why missions find the props with the cameras.
Combining them: the EKF
Section titled “Combining them: the EKF”The EKF (Extended Kalman Filter) combines the sensors into one best guess, updated whenever new data arrives, by repeating two steps:
- Predict: “I was here, moving at this speed, so now I should be about there.” The guess gets a little less certain.
- Update: when a reading arrives, move the guess part of the way towards it: further the more the sensor is trusted relative to the prediction. The guess gets more certain.
The EKF is ekf_filter_node from the standard robot_localization package, and src/sub_bringup/config/ekf.yaml sets what it uses from each sensor:
| From | It uses | On topic |
|---|---|---|
| IMU | Yaw and yaw rate, roll and pitch and their rates | imu/data |
| DVL | Velocity in x, y and z | dvl/velocity |
| Pressure sensor | Depth | odometry/depth |
It publishes the result on odometry/filtered, which nearly everything else reads:
ros2 topic echo --once --field pose.pose.position /marlin_v3/odometry/filteredx: 0.0008025494261619621y: -0.001417184359673121z: -0.13056966190063396The simulator’s ground truth
Section titled “The simulator’s ground truth”The simulator knows exactly where the robot is, and publishes it on sim/odometry:
ros2 topic echo --once --field pose.pose.position /marlin_v3/sim/odometryx: 17.177234458592146y: -10.24440400644934z: 0.32491813483549115These differ from odometry/filtered at the same moment because they are in a different frame: sim/odometry is measured from the corner of the simulated pool, in Stonefish’s z-down convention, and odometry/filtered from where the robot armed. sim/ topics exist only in the simulator.
What happens when a sensor fails?
Section titled “What happens when a sensor fails?”sub_control watches the age of every sensor’s messages. If the DVL goes quiet, it stops trusting x and y and holds what it can. If the IMU or the position estimate goes quiet, it cuts the thrusters and lets the robot float up. The Safety table has the whole list.
To try it in the simulator, remove the program that publishes imu/data. First send the robot down:
ros2 topic pub --once /marlin_v3/motion_setpoint sub_control_interfaces/msg/MotionSetpoint '{mode: [0, 0, 1, 0, 0, 0], position: [0.0, 0.0, -1.0, 0.0, 0.0, 0.0]}'The sensor bridges all run inside one program. List them to find the IMU’s number:
ros2 component list/marlin_v3/sim_sensors_container 1 /marlin_v3/sim_dvl_remapper 2 /marlin_v3/sim_imu_remapper 3 /marlin_v3/sim_pressure_to_depth ...Once the robot has reached its depth, after about 15 seconds, unload it by that number:
ros2 component unload /marlin_v3/sim_sensors_container 2One second later, sub_control prints this in the simulator’s terminal, and every thruster command goes to zero:
[sub_control-3] [ERROR] [marlin_v3.sub_control]: no IMU for 1.00 s: thrusters offThe robot floats back up to about −0.12 m. Restart the simulator to get the IMU back.
Learn more
Section titled “Learn more”- Kalman Filter from the Ground Up explains it with worked examples.
- Architecture:
ekf_filter_nodehas the details of our setup.