Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support preflight calibration ia command_int #24905

Merged
4 changes: 2 additions & 2 deletions ArduCopter/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,9 @@ void GCS_MAVLINK_Copter::handle_landing_target(const mavlink_landing_target_t &p
#endif
}

MAV_RESULT GCS_MAVLINK_Copter::_handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
MAV_RESULT GCS_MAVLINK_Copter::_handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
if (is_equal(packet.param6,1.0f)) {
if (packet.y == 1) {
// compassmot calibration
return copter.mavlink_compassmot(*this);
}
Expand Down
2 changes: 1 addition & 1 deletion ArduCopter/GCS_Mavlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GCS_MAVLINK_Copter : public GCS_MAVLINK
bool params_ready() const override;
void send_banner() override;

MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg) override;

void send_attitude_target() override;
void send_position_target_global_int() override;
Expand Down
2 changes: 1 addition & 1 deletion ArduPlane/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ void GCS_MAVLINK_Plane::handle_change_alt_request(AP_Mission::Mission_Command &c
}


MAV_RESULT GCS_MAVLINK_Plane::handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
MAV_RESULT GCS_MAVLINK_Plane::handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
plane.in_calibration = true;
MAV_RESULT ret = GCS_MAVLINK::handle_command_preflight_calibration(packet, msg);
Expand Down
2 changes: 1 addition & 1 deletion ArduPlane/GCS_Mavlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GCS_MAVLINK_Plane : public GCS_MAVLINK

bool sysid_enforce() const override;

MAV_RESULT handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_int_packet(const mavlink_command_int_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_long_packet(const mavlink_command_long_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_do_set_mission_current(const mavlink_command_long_t &packet) override;
Expand Down
4 changes: 2 additions & 2 deletions ArduSub/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ MAV_RESULT GCS_MAVLINK_Sub::_handle_command_preflight_calibration_baro(const mav
return MAV_RESULT_ACCEPTED;
}

MAV_RESULT GCS_MAVLINK_Sub::_handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
MAV_RESULT GCS_MAVLINK_Sub::_handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
if (is_equal(packet.param6,1.0f)) {
if (packet.y == 1) {
// compassmot calibration
//result = sub.mavlink_compassmot(chan);
gcs().send_text(MAV_SEVERITY_INFO, "#CompassMot calibration not supported");
Expand Down
2 changes: 1 addition & 1 deletion ArduSub/GCS_Mavlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GCS_MAVLINK_Sub : public GCS_MAVLINK {

MAV_RESULT handle_command_do_set_roi(const Location &roi_loc) override;
MAV_RESULT _handle_command_preflight_calibration_baro(const mavlink_message_t &msg) override;
MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_long_packet(const mavlink_command_long_t &packet, const mavlink_message_t &msg) override;

// override sending of scaled_pressure3 to send on-board temperature:
Expand Down
2 changes: 1 addition & 1 deletion Blimp/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void GCS_MAVLINK_Blimp::send_banner()
send_text(MAV_SEVERITY_INFO, "Frame: %s", blimp.get_frame_string());
}

MAV_RESULT GCS_MAVLINK_Blimp::_handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
MAV_RESULT GCS_MAVLINK_Blimp::_handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
return GCS_MAVLINK::_handle_command_preflight_calibration(packet, msg);
}
Expand Down
2 changes: 1 addition & 1 deletion Blimp/GCS_Mavlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GCS_MAVLINK_Blimp : public GCS_MAVLINK
bool params_ready() const override;
void send_banner() override;

MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg) override;

void send_position_target_global_int() override;

Expand Down
6 changes: 3 additions & 3 deletions Rover/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,15 @@ bool GCS_MAVLINK_Rover::handle_guided_request(AP_Mission::Mission_Command &cmd)
return rover.mode_guided.set_desired_location(cmd.content.location);
}

MAV_RESULT GCS_MAVLINK_Rover::_handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
MAV_RESULT GCS_MAVLINK_Rover::_handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
if (is_equal(packet.param6, 1.0f)) {
if (packet.y == 1) {
if (rover.g2.windvane.start_direction_calibration()) {
return MAV_RESULT_ACCEPTED;
} else {
return MAV_RESULT_FAILED;
}
} else if (is_equal(packet.param6, 2.0f)) {
} else if (packet.y == 2) {
if (rover.g2.windvane.start_speed_calibration()) {
return MAV_RESULT_ACCEPTED;
} else {
Expand Down
2 changes: 1 addition & 1 deletion Rover/GCS_Mavlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GCS_MAVLINK_Rover : public GCS_MAVLINK
uint8_t sysid_my_gcs() const override;
bool sysid_enforce() const override;

MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_int_packet(const mavlink_command_int_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_int_do_reposition(const mavlink_command_int_t &packet);
MAV_RESULT handle_command_nav_set_yaw_speed(const mavlink_command_int_t &packet, const mavlink_message_t &msg);
Expand Down
68 changes: 68 additions & 0 deletions Tools/autotest/arduplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -4752,6 +4752,73 @@ def MAV_CMD_GUIDED_CHANGE_ALTITUDE(self):
)
self.fly_home_land_and_disarm()

def _MAV_CMD_PREFLIGHT_CALIBRATION(self, command):
self.context_push()
self.start_subtest("Denied when armed")
self.wait_ready_to_arm()
self.arm_vehicle()
command(
mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION,
p1=1,
want_result=mavutil.mavlink.MAV_RESULT_FAILED,
)
self.disarm_vehicle()

self.context_collect('STATUSTEXT')

self.start_subtest("gyro cal")
command(
mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION,
p1=1,
)

self.start_subtest("baro cal")
command(
mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION,
p3=1,
)
self.wait_statustext('Barometer calibration complete', check_context=True)

# accelcal skipped here, it is checked elsewhere

self.start_subtest("ins trim")
command(
mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION,
p5=2,
)

# enforced delay between cals:
self.delay_sim_time(5)

self.start_subtest("simple accel cal")
command(
mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION,
p5=4,
)
# simple gyro cal makes the GPS units go unhealthy as they are
# not maintaining their update rate (gyro cal is synchronous
# in the main loop). Usually ~30 seconds to recover...
self.wait_gps_sys_status_not_present_or_enabled_and_healthy(timeout=60)

self.start_subtest("force save accels")
command(
mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION,
p5=76,
)

self.start_subtest("force save compasses")
command(
mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION,
p2=76,
)

self.context_pop()

def MAV_CMD_PREFLIGHT_CALIBRATION(self):
'''test MAV_CMD_PREFLIGHT_CALIBRATION mavlink handling'''
self._MAV_CMD_PREFLIGHT_CALIBRATION(self.run_cmd)
self._MAV_CMD_PREFLIGHT_CALIBRATION(self.run_cmd_int)

def tests(self):
'''return list of all tests'''
ret = super(AutoTestPlane, self).tests()
Expand Down Expand Up @@ -4843,6 +4910,7 @@ def tests(self):
self.MODE_SWITCH_RESET,
self.ExternalPositionEstimate,
self.MAV_CMD_GUIDED_CHANGE_ALTITUDE,
self.MAV_CMD_PREFLIGHT_CALIBRATION,
])
return ret

Expand Down
5 changes: 3 additions & 2 deletions Tools/autotest/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7201,7 +7201,7 @@ def assert_mode_is(self, mode):

def wait_gps_sys_status_not_present_or_enabled_and_healthy(self, timeout=30):
self.progress("Waiting for GPS health")
tstart = self.get_sim_time_cached()
tstart = self.get_sim_time()
while True:
now = self.get_sim_time_cached()
if now - tstart > timeout:
Expand All @@ -7221,7 +7221,8 @@ def wait_gps_sys_status_not_present_or_enabled_and_healthy(self, timeout=30):
if (not (m.onboard_control_sensors_health & mavutil.mavlink.MAV_SYS_STATUS_SENSOR_GPS)):
self.progress("GPS not healthy")
continue
self.progress("GPS healthy")
self.progress("GPS healthy after %f/%f seconds" %
((now - tstart), timeout))
return

def assert_sensor_state(self, sensor, present=True, enabled=True, healthy=True, verbose=False):
Expand Down
4 changes: 2 additions & 2 deletions libraries/GCS_MAVLink/GCS.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,9 @@ class GCS_MAVLINK

// generally this should not be overridden; Plane overrides it to ensure
// failsafe isn't triggered during calibration
virtual MAV_RESULT handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg);
virtual MAV_RESULT handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg);

virtual MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg);
virtual MAV_RESULT _handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg);
virtual MAV_RESULT _handle_command_preflight_calibration_baro(const mavlink_message_t &msg);

virtual MAV_RESULT handle_command_do_set_mission_current(const mavlink_command_long_t &packet);
Expand Down
19 changes: 9 additions & 10 deletions libraries/GCS_MAVLink/GCS_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4357,7 +4357,7 @@ MAV_RESULT GCS_MAVLINK::_handle_command_preflight_calibration_baro(const mavlink
return MAV_RESULT_IN_PROGRESS;
}

MAV_RESULT GCS_MAVLINK::_handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
MAV_RESULT GCS_MAVLINK::_handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
MAV_RESULT ret = MAV_RESULT_UNSUPPORTED;

Expand All @@ -4380,7 +4380,7 @@ MAV_RESULT GCS_MAVLINK::_handle_command_preflight_calibration(const mavlink_comm
rc().calibrating(is_positive(packet.param4));

#if HAL_INS_ACCELCAL_ENABLED
if (is_equal(packet.param5,1.0f)) {
if (packet.x == 1) {
// start with gyro calibration
if (!AP::ins().calibrate_gyros()) {
return MAV_RESULT_FAILED;
Expand All @@ -4393,11 +4393,11 @@ MAV_RESULT GCS_MAVLINK::_handle_command_preflight_calibration(const mavlink_comm
#endif

#if AP_INERTIALSENSOR_ENABLED
if (is_equal(packet.param5,2.0f)) {
if (packet.x == 2) {
return AP::ins().calibrate_trim();
}

if (is_equal(packet.param5,4.0f)) {
if (packet.x == 4) {
// simple accel calibration
return AP::ins().simple_accel_cal();
}
Expand All @@ -4407,7 +4407,7 @@ MAV_RESULT GCS_MAVLINK::_handle_command_preflight_calibration(const mavlink_comm
compass to be written as valid. This is useful when reloading
parameters after a full parameter erase
*/
if (is_equal(packet.param5,76.0f)) {
if (packet.x == 76) {
// force existing accel calibration to be accepted as valid
AP::ins().force_save_calibration();
ret = MAV_RESULT_ACCEPTED;
Expand All @@ -4423,7 +4423,7 @@ MAV_RESULT GCS_MAVLINK::_handle_command_preflight_calibration(const mavlink_comm
return ret;
}

MAV_RESULT GCS_MAVLINK::handle_command_preflight_calibration(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
MAV_RESULT GCS_MAVLINK::handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
if (hal.util->get_soft_armed()) {
// *preflight*, remember?
Expand Down Expand Up @@ -4871,10 +4871,6 @@ MAV_RESULT GCS_MAVLINK::handle_command_long_packet(const mavlink_command_long_t
result = handle_preflight_reboot(packet, msg);
break;

case MAV_CMD_PREFLIGHT_CALIBRATION:
result = handle_command_preflight_calibration(packet, msg);
break;

default:
result = try_command_long_as_command_int(packet, msg);
break;
Expand Down Expand Up @@ -5149,6 +5145,9 @@ MAV_RESULT GCS_MAVLINK::handle_command_int_packet(const mavlink_command_int_t &p
return handle_command_mag_cal(packet);
#endif

case MAV_CMD_PREFLIGHT_CALIBRATION:
return handle_command_preflight_calibration(packet, msg);

#if AP_MAVLINK_SERVO_RELAY_ENABLED
case MAV_CMD_DO_SET_SERVO:
case MAV_CMD_DO_REPEAT_SERVO:
Expand Down