Skip to content

Commit

Permalink
Various: Plane scripted follow checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
timtuxworth committed Jun 24, 2024
1 parent 696f489 commit ac0e125
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
9 changes: 4 additions & 5 deletions ArduPlane/ArduPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ bool Plane::update_target_location(const Location &old_loc, const Location &new_
*/
if (!old_loc.same_loc_as(next_WP_loc) ||
old_loc.get_alt_frame() != new_loc.get_alt_frame()) {
gcs().send_text(MAV_SEVERITY_NOTICE, "location diff %d %d", old_loc.same_loc_as(next_WP_loc), old_loc.get_alt_frame() != new_loc.get_alt_frame());
return false;
}
next_WP_loc = new_loc;
Expand Down Expand Up @@ -967,19 +968,17 @@ bool Plane::flight_option_enabled(FlightOptions flight_option) const
// this implements the virtual function defined in AP_Vehicle for Plane to set the desired airspeed in m/s
bool Plane::set_desired_airspeed(float airspeed_new)
{
if (control_mode == &mode_guided || control_mode == &mode_auto) {
if (control_mode->is_guided_mode() || control_mode == &mode_auto) {
plane.new_airspeed_cm = constrain_float(airspeed_new, aparm.airspeed_min, aparm.airspeed_max) * 100.0f;
return true;
}
return false;
}
#endif

#if AP_SCRIPTING_ENABLED
// Helper function to let scripting set the guided mode radius
// Helper function to let scripting set the guided mode radius this implements
bool Plane::set_guided_radius_and_direction(float radius, bool direction_is_ccw)
{
if (control_mode->mode_number() == Mode::GUIDED) {
if (control_mode->is_guided_mode()) {
plane.mode_guided.set_radius_and_direction(radius, direction_is_ccw);
return true;
}
Expand Down
7 changes: 6 additions & 1 deletion libraries/AP_Scripting/docs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2427,10 +2427,15 @@ function vehicle:nav_scripting_enable(param1) end
---@return boolean -- success
function vehicle:set_desired_speed(param1) end

-- desc sets autopilot desired airspeed (Plane)
---@param airspeed_new number -- new airspeed in m/s
---@return boolean
function vehicle:set_desired_airspeed(airspeed_new) end

-- desc set the guided mode radious and direction used for the final loiter at the target
---@return boolean
---@param radius float
---@param direction_is_ccw boolean
---@param direction_is_ccw boolean
function vehicle:set_guided_radius_and_direction() end

-- desc
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ singleton AP_Vehicle method set_target_throttle_rate_rpy void float -100 100 flo
singleton AP_Vehicle method set_rudder_offset void float'skip_check boolean
singleton AP_Vehicle method set_desired_turn_rate_and_speed boolean float'skip_check float'skip_check
singleton AP_Vehicle method set_desired_speed boolean float'skip_check
singleton AP_Vehicle method set_desired_airspeed boolean float'skip_check
singleton AP_Vehicle method set_guided_radius_and_direction boolean float'skip_check boolean
singleton AP_Vehicle method nav_scripting_enable boolean uint8_t'skip_check
singleton AP_Vehicle method set_velocity_match boolean Vector2f
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Vehicle/AP_Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class AP_Vehicle : public AP_HAL::HAL::Callbacks {
// set auto mode speed in meters/sec (for use by scripting with Copter/Rover)
virtual bool set_desired_speed(float speed) { return false; }

// set auto mode airspeed in meters/sec (for use by scripting with Plane)
virtual bool set_desired_airspeed(float airspeed_new) { return false; }

// support for NAV_SCRIPT_TIME mission command
virtual bool nav_script_time(uint16_t &id, uint8_t &cmd, float &arg1, float &arg2, int16_t &arg3, int16_t &arg4) { return false; }
virtual void nav_script_time_done(uint16_t id) {}
Expand Down

0 comments on commit ac0e125

Please sign in to comment.