Skip to content

Commit

Permalink
Copter: fix do-change-speed received during takeoff
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Nov 29, 2023
1 parent a25381b commit 436e020
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ArduCopter/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,13 @@ class ModeAuto : public Mode {
float climb_rate; // climb rate in m/s. provided by mission command
uint32_t start_ms; // system time that nav attitude time command was received (used for timeout)
} nav_attitude_time;

// desired speeds
struct {
float xy; // desired speed horizontally in m/s. 0 if unset
float up; // desired speed upwards in m/s. 0 if unset
float down; // desired speed downwards in m/s. 0 if unset
} desired_speed_override;
};

#if AUTOTUNE_ENABLED == ENABLED
Expand Down
20 changes: 19 additions & 1 deletion ArduCopter/mode_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ bool ModeAuto::init(bool ignore_checks)
// initialise waypoint and spline controller
wp_nav->wp_and_spline_init();

// initialise desired speed overrides
desired_speed_override = {0, 0, 0};

// set flag to start mission
waiting_to_start = true;

Expand Down Expand Up @@ -370,7 +373,16 @@ bool ModeAuto::wp_start(const Location& dest_loc)
stopping_point = takeoff_complete_pos.tofloat();
}
}
wp_nav->wp_and_spline_init(0, stopping_point);
float des_speed_xy_cm = is_positive(desired_speed_override.xy) ? (desired_speed_override.xy * 100) : 0;
wp_nav->wp_and_spline_init(des_speed_xy_cm, stopping_point);

// override speeds up and down if necessary
if (is_positive(desired_speed_override.up)) {
wp_nav->set_speed_up(desired_speed_override.up * 100.0);
}
if (is_positive(desired_speed_override.down)) {
wp_nav->set_speed_down(desired_speed_override.down * 100.0);
}
}

if (!wp_nav->set_wp_destination_loc(dest_loc)) {
Expand Down Expand Up @@ -585,18 +597,21 @@ bool ModeAuto::use_pilot_yaw(void) const
bool ModeAuto::set_speed_xy(float speed_xy_cms)
{
copter.wp_nav->set_speed_xy(speed_xy_cms);
desired_speed_override.xy = speed_xy_cms * 0.01;
return true;
}

bool ModeAuto::set_speed_up(float speed_up_cms)
{
copter.wp_nav->set_speed_up(speed_up_cms);
desired_speed_override.up = speed_up_cms * 0.01;
return true;
}

bool ModeAuto::set_speed_down(float speed_down_cms)
{
copter.wp_nav->set_speed_down(speed_down_cms);
desired_speed_override.down = speed_down_cms * 0.01;
return true;
}

Expand Down Expand Up @@ -1855,10 +1870,13 @@ void ModeAuto::do_change_speed(const AP_Mission::Mission_Command& cmd)
if (cmd.content.speed.target_ms > 0) {
if (cmd.content.speed.speed_type == 2) {
copter.wp_nav->set_speed_up(cmd.content.speed.target_ms * 100.0f);
desired_speed_override.up = cmd.content.speed.target_ms;
} else if (cmd.content.speed.speed_type == 3) {
copter.wp_nav->set_speed_down(cmd.content.speed.target_ms * 100.0f);
desired_speed_override.down = cmd.content.speed.target_ms;
} else {
copter.wp_nav->set_speed_xy(cmd.content.speed.target_ms * 100.0f);
desired_speed_override.xy = cmd.content.speed.target_ms;
}
}
}
Expand Down

0 comments on commit 436e020

Please sign in to comment.