2014-01-28 09:44:37 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
#include "Copter.h"
|
|
|
|
|
2014-01-28 09:44:37 -04:00
|
|
|
/*
|
|
|
|
* control_guided.pde - init and run calls for guided flight mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GUIDED_LOOK_AT_TARGET_MIN_DISTANCE_CM
|
|
|
|
# define GUIDED_LOOK_AT_TARGET_MIN_DISTANCE_CM 500 // point nose at target if it is more than 5m away
|
|
|
|
#endif
|
|
|
|
|
2015-01-06 23:33:54 -04:00
|
|
|
#define GUIDED_POSVEL_TIMEOUT_MS 3000 // guided mode's position-velocity controller times out after 3seconds with no new updates
|
2015-10-10 09:41:42 -03:00
|
|
|
#define GUIDED_ATTITUDE_TIMEOUT_MS 1000 // guided mode's attitude controller times out after 1 second with no new updates
|
2015-01-06 23:33:54 -04:00
|
|
|
|
2014-11-25 16:15:45 -04:00
|
|
|
static Vector3f posvel_pos_target_cm;
|
|
|
|
static Vector3f posvel_vel_target_cms;
|
|
|
|
static uint32_t posvel_update_time_ms;
|
2015-08-11 20:36:42 -03:00
|
|
|
static uint32_t vel_update_time_ms;
|
2014-11-25 16:15:45 -04:00
|
|
|
|
2015-10-08 08:13:53 -03:00
|
|
|
struct {
|
|
|
|
uint32_t update_time_ms;
|
|
|
|
float roll_cd;
|
|
|
|
float pitch_cd;
|
|
|
|
float yaw_cd;
|
|
|
|
float climb_rate_cms;
|
|
|
|
} static guided_angle_state = {0,0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
2014-10-13 05:41:48 -03:00
|
|
|
struct Guided_Limit {
|
|
|
|
uint32_t timeout_ms; // timeout (in seconds) from the time that guided is invoked
|
|
|
|
float alt_min_cm; // lower altitude limit in cm above home (0 = no limit)
|
|
|
|
float alt_max_cm; // upper altitude limit in cm above home (0 = no limit)
|
|
|
|
float horiz_max_cm; // horizontal position limit in cm from where guided mode was initiated (0 = no limit)
|
|
|
|
uint32_t start_time;// system time in milliseconds that control was handed to the external computer
|
|
|
|
Vector3f start_pos; // start position as a distance from home in cm. used for checking horiz_max limit
|
|
|
|
} guided_limit;
|
|
|
|
|
2014-01-28 09:44:37 -04:00
|
|
|
// guided_init - initialise guided controller
|
2015-05-29 23:12:49 -03:00
|
|
|
bool Copter::guided_init(bool ignore_checks)
|
2014-01-28 09:44:37 -04:00
|
|
|
{
|
2015-01-02 07:43:50 -04:00
|
|
|
if (position_ok() || ignore_checks) {
|
2014-07-06 04:43:29 -03:00
|
|
|
// initialise yaw
|
|
|
|
set_auto_yaw_mode(get_default_auto_yaw_mode(false));
|
2014-06-02 06:06:11 -03:00
|
|
|
// start in position control mode
|
|
|
|
guided_pos_control_start();
|
2014-01-28 09:44:37 -04:00
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-04 11:11:23 -03:00
|
|
|
|
|
|
|
// guided_takeoff_start - initialises waypoint controller to implement take-off
|
2016-03-11 04:16:26 -04:00
|
|
|
bool Copter::guided_takeoff_start(float final_alt_above_home)
|
2014-08-04 11:11:23 -03:00
|
|
|
{
|
|
|
|
guided_mode = Guided_TakeOff;
|
2016-03-11 04:16:26 -04:00
|
|
|
|
2014-08-04 11:11:23 -03:00
|
|
|
// initialise wpnav destination
|
2016-03-11 04:16:26 -04:00
|
|
|
Location_Class target_loc = current_loc;
|
2016-04-28 07:53:58 -03:00
|
|
|
target_loc.set_alt_cm(final_alt_above_home, Location_Class::ALT_FRAME_ABOVE_HOME);
|
2016-03-11 04:16:26 -04:00
|
|
|
|
|
|
|
if (!wp_nav.set_wp_destination(target_loc)) {
|
2016-04-22 08:46:36 -03:00
|
|
|
// failure to set destination can only be because of missing terrain data
|
2016-03-11 04:16:26 -04:00
|
|
|
Log_Write_Error(ERROR_SUBSYSTEM_NAVIGATION, ERROR_CODE_FAILED_TO_SET_DESTINATION);
|
2016-04-22 08:46:36 -03:00
|
|
|
// failure is propagated to GCS with NAK
|
2016-03-11 04:16:26 -04:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-04 11:11:23 -03:00
|
|
|
|
|
|
|
// initialise yaw
|
|
|
|
set_auto_yaw_mode(AUTO_YAW_HOLD);
|
|
|
|
|
2015-07-01 22:37:12 -03:00
|
|
|
// clear i term when we're taking off
|
|
|
|
set_throttle_takeoff();
|
2016-03-11 04:16:26 -04:00
|
|
|
|
|
|
|
return true;
|
2014-08-04 11:11:23 -03:00
|
|
|
}
|
|
|
|
|
2014-06-02 06:06:11 -03:00
|
|
|
// initialise guided mode's position controller
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_pos_control_start()
|
2014-06-02 06:06:11 -03:00
|
|
|
{
|
|
|
|
// set to position control mode
|
|
|
|
guided_mode = Guided_WP;
|
|
|
|
|
|
|
|
// initialise waypoint and spline controller
|
|
|
|
wp_nav.wp_and_spline_init();
|
|
|
|
|
|
|
|
// initialise wpnav to stopping point at current altitude
|
|
|
|
// To-Do: set to current location if disarmed?
|
|
|
|
// To-Do: set to stopping point altitude?
|
|
|
|
Vector3f stopping_point;
|
|
|
|
stopping_point.z = inertial_nav.get_altitude();
|
|
|
|
wp_nav.get_wp_stopping_point_xy(stopping_point);
|
2016-04-22 08:46:36 -03:00
|
|
|
|
|
|
|
// no need to check return status because terrain data is not used
|
|
|
|
wp_nav.set_wp_destination(stopping_point, false);
|
2014-06-02 06:06:11 -03:00
|
|
|
|
2014-07-06 04:43:29 -03:00
|
|
|
// initialise yaw
|
|
|
|
set_auto_yaw_mode(get_default_auto_yaw_mode(false));
|
2014-06-02 06:06:11 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// initialise guided mode's velocity controller
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_vel_control_start()
|
2014-06-02 06:06:11 -03:00
|
|
|
{
|
|
|
|
// set guided_mode to velocity controller
|
|
|
|
guided_mode = Guided_Velocity;
|
|
|
|
|
|
|
|
// initialize vertical speeds and leash lengths
|
|
|
|
pos_control.set_speed_z(-g.pilot_velocity_z_max, g.pilot_velocity_z_max);
|
|
|
|
pos_control.set_accel_z(g.pilot_accel_z);
|
|
|
|
|
|
|
|
// initialise velocity controller
|
|
|
|
pos_control.init_vel_controller_xyz();
|
|
|
|
}
|
|
|
|
|
2014-11-25 16:15:45 -04:00
|
|
|
// initialise guided mode's posvel controller
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_posvel_control_start()
|
2014-11-25 16:15:45 -04:00
|
|
|
{
|
|
|
|
// set guided_mode to velocity controller
|
|
|
|
guided_mode = Guided_PosVel;
|
|
|
|
|
|
|
|
pos_control.init_xy_controller();
|
|
|
|
|
2015-01-06 23:33:54 -04:00
|
|
|
// set speed and acceleration from wpnav's speed and acceleration
|
|
|
|
pos_control.set_speed_xy(wp_nav.get_speed_xy());
|
2014-11-25 16:15:45 -04:00
|
|
|
pos_control.set_accel_xy(wp_nav.get_wp_acceleration());
|
2015-10-28 23:47:46 -03:00
|
|
|
pos_control.set_jerk_xy_to_default();
|
2014-11-25 16:15:45 -04:00
|
|
|
|
|
|
|
const Vector3f& curr_pos = inertial_nav.get_position();
|
|
|
|
const Vector3f& curr_vel = inertial_nav.get_velocity();
|
|
|
|
|
2015-01-06 23:33:54 -04:00
|
|
|
// set target position and velocity to current position and velocity
|
2014-11-25 16:15:45 -04:00
|
|
|
pos_control.set_xy_target(curr_pos.x, curr_pos.y);
|
|
|
|
pos_control.set_desired_velocity_xy(curr_vel.x, curr_vel.y);
|
|
|
|
|
2015-01-06 23:33:54 -04:00
|
|
|
// set vertical speed and acceleration
|
2014-11-25 16:15:45 -04:00
|
|
|
pos_control.set_speed_z(wp_nav.get_speed_down(), wp_nav.get_speed_up());
|
|
|
|
pos_control.set_accel_z(wp_nav.get_accel_z());
|
|
|
|
|
2015-01-06 23:33:54 -04:00
|
|
|
// pilot always controls yaw
|
|
|
|
set_auto_yaw_mode(AUTO_YAW_HOLD);
|
2014-11-25 16:15:45 -04:00
|
|
|
}
|
|
|
|
|
2015-10-08 08:13:53 -03:00
|
|
|
// initialise guided mode's angle controller
|
|
|
|
void Copter::guided_angle_control_start()
|
|
|
|
{
|
|
|
|
// set guided_mode to velocity controller
|
|
|
|
guided_mode = Guided_Angle;
|
|
|
|
|
|
|
|
// set vertical speed and acceleration
|
|
|
|
pos_control.set_speed_z(wp_nav.get_speed_down(), wp_nav.get_speed_up());
|
|
|
|
pos_control.set_accel_z(wp_nav.get_accel_z());
|
|
|
|
|
2015-10-27 10:06:50 -03:00
|
|
|
// initialise position and desired velocity
|
|
|
|
pos_control.set_alt_target(inertial_nav.get_altitude());
|
|
|
|
pos_control.set_desired_velocity_z(inertial_nav.get_velocity_z());
|
2015-10-08 08:13:53 -03:00
|
|
|
|
|
|
|
// initialise targets
|
|
|
|
guided_angle_state.update_time_ms = millis();
|
|
|
|
guided_angle_state.roll_cd = ahrs.roll_sensor;
|
|
|
|
guided_angle_state.pitch_cd = ahrs.pitch_sensor;
|
|
|
|
guided_angle_state.yaw_cd = ahrs.yaw_sensor;
|
|
|
|
guided_angle_state.climb_rate_cms = 0.0f;
|
|
|
|
|
|
|
|
// pilot always controls yaw
|
|
|
|
set_auto_yaw_mode(AUTO_YAW_HOLD);
|
|
|
|
}
|
|
|
|
|
2014-01-28 09:44:37 -04:00
|
|
|
// guided_set_destination - sets guided mode's target destination
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_set_destination(const Vector3f& destination)
|
2014-01-28 09:44:37 -04:00
|
|
|
{
|
2014-06-02 06:06:11 -03:00
|
|
|
// ensure we are in position control mode
|
|
|
|
if (guided_mode != Guided_WP) {
|
|
|
|
guided_pos_control_start();
|
|
|
|
}
|
|
|
|
|
2016-04-22 08:46:36 -03:00
|
|
|
// no need to check return status because terrain data is not used
|
|
|
|
wp_nav.set_wp_destination(destination, false);
|
2016-01-10 22:41:28 -04:00
|
|
|
|
|
|
|
// log target
|
|
|
|
Log_Write_GuidedTarget(guided_mode, destination, Vector3f());
|
2014-01-28 09:44:37 -04:00
|
|
|
}
|
|
|
|
|
2016-03-11 04:16:26 -04:00
|
|
|
// sets guided mode's target from a Location object
|
|
|
|
// returns false if destination could not be set (probably caused by missing terrain data)
|
|
|
|
bool Copter::guided_set_destination(const Location_Class& dest_loc)
|
|
|
|
{
|
|
|
|
// ensure we are in position control mode
|
|
|
|
if (guided_mode != Guided_WP) {
|
|
|
|
guided_pos_control_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wp_nav.set_wp_destination(dest_loc)) {
|
2016-04-22 08:46:36 -03:00
|
|
|
// failure to set destination can only be because of missing terrain data
|
2016-03-11 04:16:26 -04:00
|
|
|
Log_Write_Error(ERROR_SUBSYSTEM_NAVIGATION, ERROR_CODE_FAILED_TO_SET_DESTINATION);
|
2016-04-22 08:46:36 -03:00
|
|
|
// failure is propagated to GCS with NAK
|
2016-03-11 04:16:26 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// log target
|
|
|
|
Log_Write_GuidedTarget(guided_mode, Vector3f(dest_loc.lat, dest_loc.lng, dest_loc.alt),Vector3f());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-02 06:06:11 -03:00
|
|
|
// guided_set_velocity - sets guided mode's target velocity
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_set_velocity(const Vector3f& velocity)
|
2014-06-02 06:06:11 -03:00
|
|
|
{
|
|
|
|
// check we are in velocity control mode
|
|
|
|
if (guided_mode != Guided_Velocity) {
|
|
|
|
guided_vel_control_start();
|
|
|
|
}
|
|
|
|
|
2015-08-11 20:36:42 -03:00
|
|
|
vel_update_time_ms = millis();
|
|
|
|
|
2014-06-02 06:06:11 -03:00
|
|
|
// set position controller velocity target
|
2014-06-11 23:53:02 -03:00
|
|
|
pos_control.set_desired_velocity(velocity);
|
2016-01-10 22:41:28 -04:00
|
|
|
|
|
|
|
// log target
|
|
|
|
Log_Write_GuidedTarget(guided_mode, Vector3f(), velocity);
|
2014-06-02 06:06:11 -03:00
|
|
|
}
|
|
|
|
|
2014-11-25 16:15:45 -04:00
|
|
|
// set guided mode posvel target
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_set_destination_posvel(const Vector3f& destination, const Vector3f& velocity) {
|
2014-11-25 16:15:45 -04:00
|
|
|
// check we are in velocity control mode
|
|
|
|
if (guided_mode != Guided_PosVel) {
|
|
|
|
guided_posvel_control_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
posvel_update_time_ms = millis();
|
|
|
|
posvel_pos_target_cm = destination;
|
|
|
|
posvel_vel_target_cms = velocity;
|
|
|
|
|
|
|
|
pos_control.set_pos_target(posvel_pos_target_cm);
|
2016-01-10 22:41:28 -04:00
|
|
|
|
|
|
|
// log target
|
|
|
|
Log_Write_GuidedTarget(guided_mode, destination, velocity);
|
2014-11-25 16:15:45 -04:00
|
|
|
}
|
|
|
|
|
2015-10-08 08:13:53 -03:00
|
|
|
// set guided mode angle target
|
|
|
|
void Copter::guided_set_angle(const Quaternion &q, float climb_rate_cms)
|
|
|
|
{
|
|
|
|
// check we are in velocity control mode
|
|
|
|
if (guided_mode != Guided_Angle) {
|
|
|
|
guided_angle_control_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert quaternion to euler angles
|
|
|
|
q.to_euler(guided_angle_state.roll_cd, guided_angle_state.pitch_cd, guided_angle_state.yaw_cd);
|
|
|
|
guided_angle_state.roll_cd = ToDeg(guided_angle_state.roll_cd) * 100.0f;
|
|
|
|
guided_angle_state.pitch_cd = ToDeg(guided_angle_state.pitch_cd) * 100.0f;
|
2016-04-27 06:35:18 -03:00
|
|
|
guided_angle_state.yaw_cd = wrap_180_cd(ToDeg(guided_angle_state.yaw_cd) * 100.0f);
|
2015-10-08 08:13:53 -03:00
|
|
|
|
|
|
|
guided_angle_state.climb_rate_cms = climb_rate_cms;
|
|
|
|
guided_angle_state.update_time_ms = millis();
|
2016-01-10 22:41:28 -04:00
|
|
|
|
|
|
|
// log target
|
|
|
|
Log_Write_GuidedTarget(guided_mode,
|
|
|
|
Vector3f(guided_angle_state.roll_cd, guided_angle_state.pitch_cd, guided_angle_state.yaw_cd),
|
|
|
|
Vector3f(0.0f, 0.0f, guided_angle_state.climb_rate_cms));
|
2015-10-08 08:13:53 -03:00
|
|
|
}
|
|
|
|
|
2014-01-28 09:44:37 -04:00
|
|
|
// guided_run - runs the guided controller
|
|
|
|
// should be called at 100hz or more
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_run()
|
2014-01-28 09:44:37 -04:00
|
|
|
{
|
2014-08-04 11:11:23 -03:00
|
|
|
// call the correct auto controller
|
|
|
|
switch (guided_mode) {
|
|
|
|
|
|
|
|
case Guided_TakeOff:
|
|
|
|
// run takeoff controller
|
|
|
|
guided_takeoff_run();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Guided_WP:
|
|
|
|
// run position controller
|
2014-06-02 06:06:11 -03:00
|
|
|
guided_pos_control_run();
|
2014-08-04 11:11:23 -03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Guided_Velocity:
|
|
|
|
// run velocity controller
|
2014-06-02 06:06:11 -03:00
|
|
|
guided_vel_control_run();
|
2014-11-14 17:26:45 -04:00
|
|
|
break;
|
|
|
|
|
2014-11-25 16:15:45 -04:00
|
|
|
case Guided_PosVel:
|
2015-01-06 23:33:54 -04:00
|
|
|
// run position-velocity controller
|
2014-11-25 16:15:45 -04:00
|
|
|
guided_posvel_control_run();
|
|
|
|
break;
|
2015-10-08 08:13:53 -03:00
|
|
|
|
|
|
|
case Guided_Angle:
|
|
|
|
// run angle controller
|
|
|
|
guided_angle_control_run();
|
|
|
|
break;
|
2014-06-02 06:06:11 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-04 11:11:23 -03:00
|
|
|
// guided_takeoff_run - takeoff in guided mode
|
|
|
|
// called by guided_run at 100hz or more
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_takeoff_run()
|
2014-08-04 11:11:23 -03:00
|
|
|
{
|
2015-10-20 03:40:24 -03:00
|
|
|
// if not auto armed or motors not enabled set throttle to zero and exit immediately
|
2016-01-13 03:10:45 -04:00
|
|
|
if (!motors.armed() || !ap.auto_armed || !motors.get_interlock()) {
|
2015-10-20 03:40:24 -03:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME // Helicopters always stabilize roll/pitch/yaw
|
|
|
|
// call attitude controller
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw_smooth(0, 0, 0, get_smoothing_gain());
|
2015-10-20 03:40:24 -03:00
|
|
|
attitude_control.set_throttle_out(0,false,g.throttle_filt);
|
2016-01-13 03:10:45 -04:00
|
|
|
#else
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_SPIN_WHEN_ARMED);
|
2016-01-13 03:10:45 -04:00
|
|
|
// multicopters do not stabilize roll/pitch/yaw when disarmed
|
2015-10-20 03:40:24 -03:00
|
|
|
attitude_control.set_throttle_out_unstabilized(0,true,g.throttle_filt);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-04 11:11:23 -03:00
|
|
|
// process pilot's yaw input
|
|
|
|
float target_yaw_rate = 0;
|
|
|
|
if (!failsafe.radio) {
|
|
|
|
// get pilot's desired yaw rate
|
ArduCopter: Fix up after refactoring RC_Channel class
Further to refactor of RC_Channel class which included
adding get_xx set_xx methods, change reads and writes to the public members
to calls to get and set functionsss
old public member(int16_t) get function -> int16_t set function (int16_t)
(expression where c is an object of type RC_Channel)
c.radio_in c.get_radio_in() c.set_radio_in(v)
c.control_in c.get_control_in() c.set_control_in(v)
c.servo_out c.get_servo_out() c.set_servo_out(v)
c.pwm_out c.get_pwm_out() // use existing
c.radio_out c.get_radio_out() c.set_radio_out(v)
c.radio_max c.get_radio_max() c.set_radio_max(v)
c.radio_min c.get_radio_min() c.set_radio_min(v)
c.radio_trim c.get_radio_trim() c.set_radio_trim(v);
c.min_max_configured() // return true if min and max are configured
Because data members of RC_Channels are now private and so cannot be written directly
some overloads are provided in the Plane classes to provide the old functionality
new overload Plane::stick_mix_channel(RC_Channel *channel)
which forwards to the previously existing
void stick_mix_channel(RC_Channel *channel, int16_t &servo_out);
new overload Plane::channel_output_mixer(Rc_Channel* , RC_Channel*)const
which forwards to
(uint8_t mixing_type, int16_t & chan1, int16_t & chan2)const;
Rename functions
RC_Channel_aux::set_radio_trim(Aux_servo_function_t function)
to RC_Channel_aux::set_trim_to_radio_in_for(Aux_servo_function_t function)
RC_Channel_aux::set_servo_out(Aux_servo_function_t function, int16_t value)
to RC_Channel_aux::set_servo_out_for(Aux_servo_function_t function, int16_t value)
Rationale:
RC_Channel is a complicated class, which combines
several functionalities dealing with stick inputs
in pwm and logical units, logical and actual actuator
outputs, unit conversion etc, etc
The intent of this PR is to clarify existing use of
the class. At the basic level it should now be possible
to grep all places where private variable is set by
searching for the set_xx function.
(The wider purpose is to provide a more generic and
logically simpler method of output mixing. This is a small step)
2016-05-08 05:46:59 -03:00
|
|
|
target_yaw_rate = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
|
2014-08-04 11:11:23 -03:00
|
|
|
}
|
|
|
|
|
2016-01-13 03:10:45 -04:00
|
|
|
// set motors to full range
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_THROTTLE_UNLIMITED);
|
2016-01-13 03:10:45 -04:00
|
|
|
|
2014-08-04 11:11:23 -03:00
|
|
|
// run waypoint controller
|
2016-04-22 08:46:36 -03:00
|
|
|
failsafe_terrain_set_status(wp_nav.update_wpnav());
|
2014-08-04 11:11:23 -03:00
|
|
|
|
|
|
|
// call z-axis position controller (wpnav should have already updated it's alt target)
|
|
|
|
pos_control.update_z_controller();
|
|
|
|
|
|
|
|
// roll & pitch from waypoint controller, yaw rate from pilot
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw(wp_nav.get_roll(), wp_nav.get_pitch(), target_yaw_rate);
|
2014-08-04 11:11:23 -03:00
|
|
|
}
|
|
|
|
|
2014-06-02 06:06:11 -03:00
|
|
|
// guided_pos_control_run - runs the guided position controller
|
|
|
|
// called from guided_run
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_pos_control_run()
|
2014-06-02 06:06:11 -03:00
|
|
|
{
|
2015-08-11 06:34:26 -03:00
|
|
|
// if not auto armed or motors not enabled set throttle to zero and exit immediately
|
2016-01-13 03:10:45 -04:00
|
|
|
if (!motors.armed() || !ap.auto_armed || !motors.get_interlock() || ap.land_complete) {
|
2015-08-11 06:34:26 -03:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME // Helicopters always stabilize roll/pitch/yaw
|
|
|
|
// call attitude controller
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw_smooth(0, 0, 0, get_smoothing_gain());
|
2015-08-11 06:34:26 -03:00
|
|
|
attitude_control.set_throttle_out(0,false,g.throttle_filt);
|
2016-01-13 03:10:45 -04:00
|
|
|
#else
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_SPIN_WHEN_ARMED);
|
2016-01-13 03:10:45 -04:00
|
|
|
// multicopters do not stabilize roll/pitch/yaw when disarmed
|
2015-08-11 06:34:26 -03:00
|
|
|
attitude_control.set_throttle_out_unstabilized(0,true,g.throttle_filt);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-28 09:44:37 -04:00
|
|
|
// process pilot's yaw input
|
|
|
|
float target_yaw_rate = 0;
|
|
|
|
if (!failsafe.radio) {
|
|
|
|
// get pilot's desired yaw rate
|
ArduCopter: Fix up after refactoring RC_Channel class
Further to refactor of RC_Channel class which included
adding get_xx set_xx methods, change reads and writes to the public members
to calls to get and set functionsss
old public member(int16_t) get function -> int16_t set function (int16_t)
(expression where c is an object of type RC_Channel)
c.radio_in c.get_radio_in() c.set_radio_in(v)
c.control_in c.get_control_in() c.set_control_in(v)
c.servo_out c.get_servo_out() c.set_servo_out(v)
c.pwm_out c.get_pwm_out() // use existing
c.radio_out c.get_radio_out() c.set_radio_out(v)
c.radio_max c.get_radio_max() c.set_radio_max(v)
c.radio_min c.get_radio_min() c.set_radio_min(v)
c.radio_trim c.get_radio_trim() c.set_radio_trim(v);
c.min_max_configured() // return true if min and max are configured
Because data members of RC_Channels are now private and so cannot be written directly
some overloads are provided in the Plane classes to provide the old functionality
new overload Plane::stick_mix_channel(RC_Channel *channel)
which forwards to the previously existing
void stick_mix_channel(RC_Channel *channel, int16_t &servo_out);
new overload Plane::channel_output_mixer(Rc_Channel* , RC_Channel*)const
which forwards to
(uint8_t mixing_type, int16_t & chan1, int16_t & chan2)const;
Rename functions
RC_Channel_aux::set_radio_trim(Aux_servo_function_t function)
to RC_Channel_aux::set_trim_to_radio_in_for(Aux_servo_function_t function)
RC_Channel_aux::set_servo_out(Aux_servo_function_t function, int16_t value)
to RC_Channel_aux::set_servo_out_for(Aux_servo_function_t function, int16_t value)
Rationale:
RC_Channel is a complicated class, which combines
several functionalities dealing with stick inputs
in pwm and logical units, logical and actual actuator
outputs, unit conversion etc, etc
The intent of this PR is to clarify existing use of
the class. At the basic level it should now be possible
to grep all places where private variable is set by
searching for the set_xx function.
(The wider purpose is to provide a more generic and
logically simpler method of output mixing. This is a small step)
2016-05-08 05:46:59 -03:00
|
|
|
target_yaw_rate = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
|
2015-05-04 23:34:21 -03:00
|
|
|
if (!is_zero(target_yaw_rate)) {
|
2014-01-28 09:44:37 -04:00
|
|
|
set_auto_yaw_mode(AUTO_YAW_HOLD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-13 03:10:45 -04:00
|
|
|
// set motors to full range
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_THROTTLE_UNLIMITED);
|
2016-01-13 03:10:45 -04:00
|
|
|
|
2014-01-28 09:44:37 -04:00
|
|
|
// run waypoint controller
|
2016-04-22 08:46:36 -03:00
|
|
|
failsafe_terrain_set_status(wp_nav.update_wpnav());
|
2014-01-28 09:44:37 -04:00
|
|
|
|
|
|
|
// call z-axis position controller (wpnav should have already updated it's alt target)
|
|
|
|
pos_control.update_z_controller();
|
|
|
|
|
|
|
|
// call attitude controller
|
|
|
|
if (auto_yaw_mode == AUTO_YAW_HOLD) {
|
|
|
|
// roll & pitch from waypoint controller, yaw rate from pilot
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw(wp_nav.get_roll(), wp_nav.get_pitch(), target_yaw_rate);
|
2014-01-28 09:44:37 -04:00
|
|
|
}else{
|
|
|
|
// roll, pitch from waypoint controller, yaw heading from auto_heading()
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_yaw(wp_nav.get_roll(), wp_nav.get_pitch(), get_auto_heading(), true);
|
2014-06-02 06:06:11 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// guided_vel_control_run - runs the guided velocity controller
|
|
|
|
// called from guided_run
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_vel_control_run()
|
2014-06-02 06:06:11 -03:00
|
|
|
{
|
2015-08-11 06:34:26 -03:00
|
|
|
// if not auto armed or motors not enabled set throttle to zero and exit immediately
|
2016-01-13 03:10:45 -04:00
|
|
|
if (!motors.armed() || !ap.auto_armed || !motors.get_interlock() || ap.land_complete) {
|
2015-08-11 06:34:26 -03:00
|
|
|
// initialise velocity controller
|
|
|
|
pos_control.init_vel_controller_xyz();
|
|
|
|
#if FRAME_CONFIG == HELI_FRAME // Helicopters always stabilize roll/pitch/yaw
|
|
|
|
// call attitude controller
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw_smooth(0, 0, 0, get_smoothing_gain());
|
2015-08-11 06:34:26 -03:00
|
|
|
attitude_control.set_throttle_out(0,false,g.throttle_filt);
|
2016-01-13 03:10:45 -04:00
|
|
|
#else
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_SPIN_WHEN_ARMED);
|
2016-01-13 03:10:45 -04:00
|
|
|
// multicopters do not stabilize roll/pitch/yaw when disarmed
|
2015-08-11 06:34:26 -03:00
|
|
|
attitude_control.set_throttle_out_unstabilized(0,true,g.throttle_filt);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-02 06:06:11 -03:00
|
|
|
// process pilot's yaw input
|
|
|
|
float target_yaw_rate = 0;
|
|
|
|
if (!failsafe.radio) {
|
|
|
|
// get pilot's desired yaw rate
|
ArduCopter: Fix up after refactoring RC_Channel class
Further to refactor of RC_Channel class which included
adding get_xx set_xx methods, change reads and writes to the public members
to calls to get and set functionsss
old public member(int16_t) get function -> int16_t set function (int16_t)
(expression where c is an object of type RC_Channel)
c.radio_in c.get_radio_in() c.set_radio_in(v)
c.control_in c.get_control_in() c.set_control_in(v)
c.servo_out c.get_servo_out() c.set_servo_out(v)
c.pwm_out c.get_pwm_out() // use existing
c.radio_out c.get_radio_out() c.set_radio_out(v)
c.radio_max c.get_radio_max() c.set_radio_max(v)
c.radio_min c.get_radio_min() c.set_radio_min(v)
c.radio_trim c.get_radio_trim() c.set_radio_trim(v);
c.min_max_configured() // return true if min and max are configured
Because data members of RC_Channels are now private and so cannot be written directly
some overloads are provided in the Plane classes to provide the old functionality
new overload Plane::stick_mix_channel(RC_Channel *channel)
which forwards to the previously existing
void stick_mix_channel(RC_Channel *channel, int16_t &servo_out);
new overload Plane::channel_output_mixer(Rc_Channel* , RC_Channel*)const
which forwards to
(uint8_t mixing_type, int16_t & chan1, int16_t & chan2)const;
Rename functions
RC_Channel_aux::set_radio_trim(Aux_servo_function_t function)
to RC_Channel_aux::set_trim_to_radio_in_for(Aux_servo_function_t function)
RC_Channel_aux::set_servo_out(Aux_servo_function_t function, int16_t value)
to RC_Channel_aux::set_servo_out_for(Aux_servo_function_t function, int16_t value)
Rationale:
RC_Channel is a complicated class, which combines
several functionalities dealing with stick inputs
in pwm and logical units, logical and actual actuator
outputs, unit conversion etc, etc
The intent of this PR is to clarify existing use of
the class. At the basic level it should now be possible
to grep all places where private variable is set by
searching for the set_xx function.
(The wider purpose is to provide a more generic and
logically simpler method of output mixing. This is a small step)
2016-05-08 05:46:59 -03:00
|
|
|
target_yaw_rate = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
|
2015-05-04 23:34:21 -03:00
|
|
|
if (!is_zero(target_yaw_rate)) {
|
2014-06-02 06:06:11 -03:00
|
|
|
set_auto_yaw_mode(AUTO_YAW_HOLD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-13 03:10:45 -04:00
|
|
|
// set motors to full range
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_THROTTLE_UNLIMITED);
|
2016-01-13 03:10:45 -04:00
|
|
|
|
2015-08-11 20:36:42 -03:00
|
|
|
// set velocity to zero if no updates received for 3 seconds
|
|
|
|
uint32_t tnow = millis();
|
|
|
|
if (tnow - vel_update_time_ms > GUIDED_POSVEL_TIMEOUT_MS && !pos_control.get_desired_velocity().is_zero()) {
|
|
|
|
pos_control.set_desired_velocity(Vector3f(0,0,0));
|
|
|
|
}
|
|
|
|
|
2015-11-17 02:51:25 -04:00
|
|
|
// call velocity controller which includes z axis controller
|
|
|
|
pos_control.update_vel_controller_xyz(ekfNavVelGainScaler);
|
2014-06-02 06:06:11 -03:00
|
|
|
|
|
|
|
// call attitude controller
|
|
|
|
if (auto_yaw_mode == AUTO_YAW_HOLD) {
|
|
|
|
// roll & pitch from waypoint controller, yaw rate from pilot
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw(pos_control.get_roll(), pos_control.get_pitch(), target_yaw_rate);
|
2014-06-02 06:06:11 -03:00
|
|
|
}else{
|
|
|
|
// roll, pitch from waypoint controller, yaw heading from auto_heading()
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_yaw(pos_control.get_roll(), pos_control.get_pitch(), get_auto_heading(), true);
|
2014-01-28 09:44:37 -04:00
|
|
|
}
|
|
|
|
}
|
2014-10-13 05:41:48 -03:00
|
|
|
|
2014-11-25 16:15:45 -04:00
|
|
|
// guided_posvel_control_run - runs the guided spline controller
|
|
|
|
// called from guided_run
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_posvel_control_run()
|
2014-11-25 16:15:45 -04:00
|
|
|
{
|
2015-08-11 06:34:26 -03:00
|
|
|
// if not auto armed or motors not enabled set throttle to zero and exit immediately
|
2016-01-13 03:10:45 -04:00
|
|
|
if (!motors.armed() || !ap.auto_armed || !motors.get_interlock() || ap.land_complete) {
|
2015-08-11 06:34:26 -03:00
|
|
|
// set target position and velocity to current position and velocity
|
|
|
|
pos_control.set_pos_target(inertial_nav.get_position());
|
|
|
|
pos_control.set_desired_velocity(Vector3f(0,0,0));
|
|
|
|
#if FRAME_CONFIG == HELI_FRAME // Helicopters always stabilize roll/pitch/yaw
|
|
|
|
// call attitude controller
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw_smooth(0, 0, 0, get_smoothing_gain());
|
2015-08-11 06:34:26 -03:00
|
|
|
attitude_control.set_throttle_out(0,false,g.throttle_filt);
|
2016-01-13 03:10:45 -04:00
|
|
|
#else
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_SPIN_WHEN_ARMED);
|
2016-01-13 03:10:45 -04:00
|
|
|
// multicopters do not stabilize roll/pitch/yaw when disarmed
|
2015-08-11 06:34:26 -03:00
|
|
|
attitude_control.set_throttle_out_unstabilized(0,true,g.throttle_filt);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-25 16:15:45 -04:00
|
|
|
// process pilot's yaw input
|
|
|
|
float target_yaw_rate = 0;
|
|
|
|
|
|
|
|
if (!failsafe.radio) {
|
|
|
|
// get pilot's desired yaw rate
|
ArduCopter: Fix up after refactoring RC_Channel class
Further to refactor of RC_Channel class which included
adding get_xx set_xx methods, change reads and writes to the public members
to calls to get and set functionsss
old public member(int16_t) get function -> int16_t set function (int16_t)
(expression where c is an object of type RC_Channel)
c.radio_in c.get_radio_in() c.set_radio_in(v)
c.control_in c.get_control_in() c.set_control_in(v)
c.servo_out c.get_servo_out() c.set_servo_out(v)
c.pwm_out c.get_pwm_out() // use existing
c.radio_out c.get_radio_out() c.set_radio_out(v)
c.radio_max c.get_radio_max() c.set_radio_max(v)
c.radio_min c.get_radio_min() c.set_radio_min(v)
c.radio_trim c.get_radio_trim() c.set_radio_trim(v);
c.min_max_configured() // return true if min and max are configured
Because data members of RC_Channels are now private and so cannot be written directly
some overloads are provided in the Plane classes to provide the old functionality
new overload Plane::stick_mix_channel(RC_Channel *channel)
which forwards to the previously existing
void stick_mix_channel(RC_Channel *channel, int16_t &servo_out);
new overload Plane::channel_output_mixer(Rc_Channel* , RC_Channel*)const
which forwards to
(uint8_t mixing_type, int16_t & chan1, int16_t & chan2)const;
Rename functions
RC_Channel_aux::set_radio_trim(Aux_servo_function_t function)
to RC_Channel_aux::set_trim_to_radio_in_for(Aux_servo_function_t function)
RC_Channel_aux::set_servo_out(Aux_servo_function_t function, int16_t value)
to RC_Channel_aux::set_servo_out_for(Aux_servo_function_t function, int16_t value)
Rationale:
RC_Channel is a complicated class, which combines
several functionalities dealing with stick inputs
in pwm and logical units, logical and actual actuator
outputs, unit conversion etc, etc
The intent of this PR is to clarify existing use of
the class. At the basic level it should now be possible
to grep all places where private variable is set by
searching for the set_xx function.
(The wider purpose is to provide a more generic and
logically simpler method of output mixing. This is a small step)
2016-05-08 05:46:59 -03:00
|
|
|
target_yaw_rate = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
|
2015-05-04 23:34:21 -03:00
|
|
|
if (!is_zero(target_yaw_rate)) {
|
2014-11-25 16:15:45 -04:00
|
|
|
set_auto_yaw_mode(AUTO_YAW_HOLD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-13 03:10:45 -04:00
|
|
|
// set motors to full range
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_THROTTLE_UNLIMITED);
|
2016-01-13 03:10:45 -04:00
|
|
|
|
2015-01-06 23:33:54 -04:00
|
|
|
// set velocity to zero if no updates received for 3 seconds
|
2014-11-25 16:15:45 -04:00
|
|
|
uint32_t tnow = millis();
|
2015-01-06 23:33:54 -04:00
|
|
|
if (tnow - posvel_update_time_ms > GUIDED_POSVEL_TIMEOUT_MS && !posvel_vel_target_cms.is_zero()) {
|
2014-11-25 16:15:45 -04:00
|
|
|
posvel_vel_target_cms.zero();
|
|
|
|
}
|
|
|
|
|
2015-04-13 22:51:16 -03:00
|
|
|
// calculate dt
|
|
|
|
float dt = pos_control.time_since_last_xy_update();
|
2014-11-25 16:15:45 -04:00
|
|
|
|
2015-04-13 22:51:16 -03:00
|
|
|
// update at poscontrol update rate
|
|
|
|
if (dt >= pos_control.get_dt_xy()) {
|
|
|
|
// sanity check dt
|
|
|
|
if (dt >= 0.2f) {
|
|
|
|
dt = 0.0f;
|
|
|
|
}
|
2015-01-06 23:33:54 -04:00
|
|
|
|
2015-04-13 22:51:16 -03:00
|
|
|
// advance position target using velocity target
|
|
|
|
posvel_pos_target_cm += posvel_vel_target_cms * dt;
|
|
|
|
|
|
|
|
// send position and velocity targets to position controller
|
|
|
|
pos_control.set_pos_target(posvel_pos_target_cm);
|
|
|
|
pos_control.set_desired_velocity_xy(posvel_vel_target_cms.x, posvel_vel_target_cms.y);
|
|
|
|
|
|
|
|
// run position controller
|
2015-09-06 09:25:09 -03:00
|
|
|
pos_control.update_xy_controller(AC_PosControl::XY_MODE_POS_AND_VEL_FF, ekfNavVelGainScaler, false);
|
2015-04-13 22:51:16 -03:00
|
|
|
}
|
2014-11-25 16:15:45 -04:00
|
|
|
|
2015-04-22 16:04:27 -03:00
|
|
|
pos_control.update_z_controller();
|
|
|
|
|
2014-11-25 16:15:45 -04:00
|
|
|
// call attitude controller
|
|
|
|
if (auto_yaw_mode == AUTO_YAW_HOLD) {
|
|
|
|
// roll & pitch from waypoint controller, yaw rate from pilot
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw(pos_control.get_roll(), pos_control.get_pitch(), target_yaw_rate);
|
2014-11-25 16:15:45 -04:00
|
|
|
}else{
|
|
|
|
// roll, pitch from waypoint controller, yaw heading from auto_heading()
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_yaw(pos_control.get_roll(), pos_control.get_pitch(), get_auto_heading(), true);
|
2014-11-25 16:15:45 -04:00
|
|
|
}
|
|
|
|
}
|
2014-11-14 17:26:45 -04:00
|
|
|
|
2015-10-08 08:13:53 -03:00
|
|
|
// guided_angle_control_run - runs the guided angle controller
|
|
|
|
// called from guided_run
|
|
|
|
void Copter::guided_angle_control_run()
|
|
|
|
{
|
|
|
|
// if not auto armed or motors not enabled set throttle to zero and exit immediately
|
2016-01-13 03:10:45 -04:00
|
|
|
if (!motors.armed() || !ap.auto_armed || !motors.get_interlock() || ap.land_complete) {
|
2015-10-08 08:13:53 -03:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME // Helicopters always stabilize roll/pitch/yaw
|
|
|
|
// call attitude controller
|
|
|
|
attitude_control.set_yaw_target_to_current_heading();
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw_smooth(0.0f, 0.0f, 0.0f, get_smoothing_gain());
|
2015-10-08 08:13:53 -03:00
|
|
|
attitude_control.set_throttle_out(0.0f,false,g.throttle_filt);
|
2016-01-13 03:10:45 -04:00
|
|
|
#else
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_SPIN_WHEN_ARMED);
|
2016-01-13 03:10:45 -04:00
|
|
|
// multicopters do not stabilize roll/pitch/yaw when disarmed
|
2015-10-08 08:13:53 -03:00
|
|
|
attitude_control.set_throttle_out_unstabilized(0.0f,true,g.throttle_filt);
|
|
|
|
#endif
|
|
|
|
pos_control.relax_alt_hold_controllers(0.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// constrain desired lean angles
|
|
|
|
float roll_in = guided_angle_state.roll_cd;
|
|
|
|
float pitch_in = guided_angle_state.pitch_cd;
|
2016-04-16 06:58:46 -03:00
|
|
|
float total_in = norm(roll_in, pitch_in);
|
2015-11-27 13:11:58 -04:00
|
|
|
float angle_max = MIN(attitude_control.get_althold_lean_angle_max(), aparm.angle_max);
|
2015-10-08 08:13:53 -03:00
|
|
|
if (total_in > angle_max) {
|
|
|
|
float ratio = angle_max / total_in;
|
|
|
|
roll_in *= ratio;
|
|
|
|
pitch_in *= ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrap yaw request
|
2016-04-27 06:35:18 -03:00
|
|
|
float yaw_in = wrap_180_cd(guided_angle_state.yaw_cd);
|
2015-10-08 08:13:53 -03:00
|
|
|
|
|
|
|
// constrain climb rate
|
|
|
|
float climb_rate_cms = constrain_float(guided_angle_state.climb_rate_cms, -fabs(wp_nav.get_speed_down()), wp_nav.get_speed_up());
|
|
|
|
|
|
|
|
// check for timeout - set lean angles and climb rate to zero if no updates received for 3 seconds
|
|
|
|
uint32_t tnow = millis();
|
2015-10-10 09:41:42 -03:00
|
|
|
if (tnow - guided_angle_state.update_time_ms > GUIDED_ATTITUDE_TIMEOUT_MS) {
|
2015-10-08 08:13:53 -03:00
|
|
|
roll_in = 0.0f;
|
|
|
|
pitch_in = 0.0f;
|
|
|
|
climb_rate_cms = 0.0f;
|
|
|
|
}
|
|
|
|
|
2016-01-13 03:10:45 -04:00
|
|
|
// set motors to full range
|
2016-02-02 08:19:25 -04:00
|
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_THROTTLE_UNLIMITED);
|
2016-01-13 03:10:45 -04:00
|
|
|
|
2015-10-08 08:13:53 -03:00
|
|
|
// call attitude controller
|
2015-11-28 13:57:14 -04:00
|
|
|
attitude_control.input_euler_angle_roll_pitch_yaw(roll_in, pitch_in, yaw_in, true);
|
2015-10-08 08:13:53 -03:00
|
|
|
|
|
|
|
// call position controller
|
2015-10-27 10:06:50 -03:00
|
|
|
pos_control.set_alt_target_from_climb_rate_ff(climb_rate_cms, G_Dt, false);
|
2015-10-08 08:13:53 -03:00
|
|
|
pos_control.update_z_controller();
|
|
|
|
}
|
|
|
|
|
2014-10-13 05:41:48 -03:00
|
|
|
// Guided Limit code
|
|
|
|
|
|
|
|
// guided_limit_clear - clear/turn off guided limits
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_limit_clear()
|
2014-10-13 05:41:48 -03:00
|
|
|
{
|
|
|
|
guided_limit.timeout_ms = 0;
|
|
|
|
guided_limit.alt_min_cm = 0.0f;
|
|
|
|
guided_limit.alt_max_cm = 0.0f;
|
|
|
|
guided_limit.horiz_max_cm = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// guided_limit_set - set guided timeout and movement limits
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_limit_set(uint32_t timeout_ms, float alt_min_cm, float alt_max_cm, float horiz_max_cm)
|
2014-10-13 05:41:48 -03:00
|
|
|
{
|
|
|
|
guided_limit.timeout_ms = timeout_ms;
|
|
|
|
guided_limit.alt_min_cm = alt_min_cm;
|
|
|
|
guided_limit.alt_max_cm = alt_max_cm;
|
|
|
|
guided_limit.horiz_max_cm = horiz_max_cm;
|
|
|
|
}
|
|
|
|
|
|
|
|
// guided_limit_init_time_and_pos - initialise guided start time and position as reference for limit checking
|
|
|
|
// only called from AUTO mode's auto_nav_guided_start function
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::guided_limit_init_time_and_pos()
|
2014-10-13 05:41:48 -03:00
|
|
|
{
|
|
|
|
// initialise start time
|
2015-11-19 23:04:45 -04:00
|
|
|
guided_limit.start_time = AP_HAL::millis();
|
2014-10-13 05:41:48 -03:00
|
|
|
|
|
|
|
// initialise start position from current position
|
|
|
|
guided_limit.start_pos = inertial_nav.get_position();
|
|
|
|
}
|
|
|
|
|
|
|
|
// guided_limit_check - returns true if guided mode has breached a limit
|
|
|
|
// used when guided is invoked from the NAV_GUIDED_ENABLE mission command
|
2015-05-29 23:12:49 -03:00
|
|
|
bool Copter::guided_limit_check()
|
2014-10-13 05:41:48 -03:00
|
|
|
{
|
|
|
|
// check if we have passed the timeout
|
|
|
|
if ((guided_limit.timeout_ms > 0) && (millis() - guided_limit.start_time >= guided_limit.timeout_ms)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get current location
|
|
|
|
const Vector3f& curr_pos = inertial_nav.get_position();
|
|
|
|
|
|
|
|
// check if we have gone below min alt
|
2015-05-04 23:34:21 -03:00
|
|
|
if (!is_zero(guided_limit.alt_min_cm) && (curr_pos.z < guided_limit.alt_min_cm)) {
|
2014-10-13 05:41:48 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we have gone above max alt
|
2015-05-04 23:34:21 -03:00
|
|
|
if (!is_zero(guided_limit.alt_max_cm) && (curr_pos.z > guided_limit.alt_max_cm)) {
|
2014-10-13 05:41:48 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we have gone beyond horizontal limit
|
|
|
|
if (guided_limit.horiz_max_cm > 0.0f) {
|
|
|
|
float horiz_move = pv_get_horizontal_distance_cm(guided_limit.start_pos, curr_pos);
|
|
|
|
if (horiz_move > guided_limit.horiz_max_cm) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got this far we must be within limits
|
|
|
|
return false;
|
|
|
|
}
|