Skip to content

Commit c117003

Browse files
peterbarkerclaude
andcommitted
ArduSub: Remove inertial_nav
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent c7dd434 commit c117003

15 files changed

Lines changed: 25 additions & 28 deletions

ArduSub/Attitude.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ float Sub::get_roi_yaw()
6464
roi_yaw_counter++;
6565
if (roi_yaw_counter >= 4) {
6666
roi_yaw_counter = 0;
67-
yaw_look_at_WP_bearing = get_bearing_cd(inertial_nav.get_position_xy_cm(), roi_WP.xy());
67+
yaw_look_at_WP_bearing = get_bearing_cd((pos_control.get_pos_estimate_NED_m().xy() * 100.0f).tofloat(), roi_WP.xy());
6868
}
6969

7070
return yaw_look_at_WP_bearing;
7171
}
7272

7373
float Sub::get_look_ahead_yaw()
7474
{
75-
const Vector3f& vel = inertial_nav.get_velocity_neu_cms();
75+
Vector3f vel = (pos_control.get_vel_estimate_NED_ms() * 100.0f).tofloat();
76+
vel.z = -vel.z;
7677
const float speed_sq = vel.xy().length_squared();
7778
// Commanded Yaw to automatically look ahead.
7879
if (position_ok() && (speed_sq > (YAW_LOOK_AHEAD_MIN_SPEED * YAW_LOOK_AHEAD_MIN_SPEED))) {

ArduSub/GCS_MAVLink_Sub.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,9 @@ void GCS_MAVLINK_Sub::handle_message(const mavlink_message_t &msg)
641641
packet.coordinate_frame == MAV_FRAME_BODY_NED ||
642642
packet.coordinate_frame == MAV_FRAME_BODY_FRD ||
643643
packet.coordinate_frame == MAV_FRAME_BODY_OFFSET_NED) {
644-
pos_vector += sub.inertial_nav.get_position_neu_cm();
644+
Vector3f pos_cm = (sub.pos_control.get_pos_estimate_NED_m() * 100.0f).tofloat();
645+
pos_cm.z = -pos_cm.z;
646+
pos_vector += pos_cm;
645647
}
646648
}
647649

ArduSub/Log.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void Sub::Log_Write_Control_Tuning()
4545
throttle_out : motors.get_throttle(),
4646
throttle_hover : motors.get_throttle_hover(),
4747
desired_alt : pos_control.get_pos_target_U_cm() * 0.01f,
48-
inav_alt : inertial_nav.get_position_z_up_cm() * 0.01f,
48+
inav_alt : pos_control.get_pos_estimate_U_m(),
4949
baro_alt : barometer.get_altitude(),
5050
desired_rangefinder_alt : mode_surftrak.get_rangefinder_target_cm() * 0.01,
5151
rangefinder_alt : rangefinder_state.alt,

ArduSub/Sub.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Sub::Sub()
3232
#endif
3333
motors(MAIN_LOOP_RATE),
3434
auto_yaw_mode(AUTO_YAW_LOOK_AT_NEXT_WP),
35-
inertial_nav(ahrs),
3635
ahrs_view(ahrs, ROTATION_NONE),
3736
attitude_control(ahrs_view, motors),
3837
pos_control(ahrs_view, motors, attitude_control),

ArduSub/Sub.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include <AP_Relay/AP_Relay.h> // APM relay
5252
#include <AP_Mount/AP_Mount.h> // Camera/Antenna mount
5353
#include <AP_Vehicle/AP_Vehicle.h> // needed for AHRS build
54-
#include <AP_InertialNav/AP_InertialNav.h> // inertial navigation library
5554
#include <AC_WPNav/AC_WPNav.h> // Waypoint navigation library
5655
#include <AC_WPNav/AC_Loiter.h>
5756
#include <AC_WPNav/AC_Circle.h> // circle navigation library
@@ -331,9 +330,6 @@ class Sub : public AP_Vehicle {
331330
int32_t condition_value; // used in condition commands (eg delay, change alt, etc.)
332331
uint32_t condition_start;
333332

334-
// Inertial Navigation
335-
AP_InertialNav inertial_nav;
336-
337333
AP_AHRS_View ahrs_view;
338334

339335
// Attitude, Position and Waypoint navigation objects

ArduSub/commands_logic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ bool Sub::verify_circle(const AP_Mission::Mission_Command& cmd)
486486

487487
// set lat/lon position if not provided
488488
if (cmd.content.location.lat == 0 && cmd.content.location.lng == 0) {
489-
circle_center.xy() = inertial_nav.get_position_xy_cm();
489+
circle_center.xy() = (sub.pos_control.get_pos_estimate_NED_m().xy() * 100.0f).tofloat();
490490
}
491491

492492
// start circling

ArduSub/inertia.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
void Sub::read_inertia()
55
{
66
// inertial altitude estimates
7-
inertial_nav.update();
87
sub.pos_control.update_estimates();
98

109
// pull position from ahrs
@@ -19,9 +18,9 @@ void Sub::read_inertia()
1918
return;
2019
}
2120

22-
current_loc.alt = inertial_nav.get_position_z_up_cm();
21+
current_loc.alt = pos_control.get_pos_estimate_U_m() * 100.0f;
2322

2423
// get velocity, altitude is always absolute frame, referenced from
2524
// water's surface
26-
climb_rate = inertial_nav.get_velocity_z_up_cms();
25+
climb_rate = pos_control.get_vel_estimate_U_ms() * 100.0f;
2726
}

ArduSub/mode.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
Mode::Mode(void) :
77
g(sub.g),
88
g2(sub.g2),
9-
inertial_nav(sub.inertial_nav),
109
ahrs(sub.ahrs),
1110
motors(sub.motors),
1211
channel_roll(sub.channel_roll),

ArduSub/mode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class Mode
9696
// convenience references to avoid code churn in conversion:
9797
Parameters &g;
9898
ParametersG2 &g2;
99-
AP_InertialNav &inertial_nav;
10099
AP_AHRS &ahrs;
101100
AP_Motors6DOF &motors;
102101
RC_Channel *&channel_roll;

ArduSub/mode_althold.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void ModeAlthold::run_post()
108108
void ModeAlthold::control_depth() {
109109
// return 0.2f when at the surface to p
110110
// scale linearly between 0.2f and 1.0f as we approach the surface
111-
float distance_to_surface = (g.surface_depth - inertial_nav.get_position_z_up_cm()) * 0.01f;
111+
float distance_to_surface = (g.surface_depth - position_control->get_pos_estimate_U_m() * 100.0f) * 0.01f;
112112
distance_to_surface = constrain_float(distance_to_surface, 0.0f, 1.0f);
113113
motors.set_max_throttle(g.surface_max_throttle + (1.0f - g.surface_max_throttle) * distance_to_surface);
114114

@@ -121,7 +121,7 @@ void ModeAlthold::control_depth() {
121121
if (sub.ap.at_surface) {
122122
position_control->set_pos_desired_U_cm(MIN(position_control->get_pos_desired_U_cm(), g.surface_depth)); // set target to 5 cm below surface level
123123
} else if (sub.ap.at_bottom) {
124-
position_control->set_pos_desired_U_cm(MAX(inertial_nav.get_position_z_up_cm() + 10.0f, position_control->get_pos_desired_U_cm())); // set target to 10 cm above bottom
124+
position_control->set_pos_desired_U_cm(MAX(position_control->get_pos_estimate_U_m() * 100.0f + 10.0f, position_control->get_pos_desired_U_cm())); // set target to 10 cm above bottom
125125
}
126126
}
127127

0 commit comments

Comments
 (0)