@ -24,8 +24,10 @@ struct {
@@ -24,8 +24,10 @@ struct {
float pitch_cd ;
float yaw_cd ;
float yaw_rate_cds ;
float climb_rate_cms ;
float climb_rate_cms ; // climb rate in cms. Used if use_thrust is false
float thrust ; // thrust from -1 to 1. Used if use_thrust is true
bool use_yaw_rate ;
bool use_thrust ;
} static guided_angle_state ;
struct Guided_Limit {
@ -310,8 +312,8 @@ bool ModeGuided::set_destination_posvel(const Vector3f& destination, const Vecto
@@ -310,8 +312,8 @@ bool ModeGuided::set_destination_posvel(const Vector3f& destination, const Vecto
return true ;
}
// set guided mode angle target
void ModeGuided : : set_angle ( const Quaternion & q , float climb_rate_cms , bool use_yaw_rate , float yaw_rate_rads )
// set guided mode angle target and climbrate
void ModeGuided : : set_angle ( const Quaternion & q , float climb_rate_cms_or_thrust , bool use_yaw_rate , float yaw_rate_rads , bool use_thrust )
{
// check we are in velocity control mode
if ( guided_mode ! = Guided_Angle ) {
@ -326,18 +328,26 @@ void ModeGuided::set_angle(const Quaternion &q, float climb_rate_cms, bool use_y
@@ -326,18 +328,26 @@ void ModeGuided::set_angle(const Quaternion &q, float climb_rate_cms, bool use_y
guided_angle_state . yaw_rate_cds = ToDeg ( yaw_rate_rads ) * 100.0f ;
guided_angle_state . use_yaw_rate = use_yaw_rate ;
guided_angle_state . climb_rate_cms = climb_rate_cms ;
guided_angle_state . use_thrust = use_thrust ;
if ( use_thrust ) {
guided_angle_state . thrust = climb_rate_cms_or_thrust ;
guided_angle_state . climb_rate_cms = 0.0f ;
} else {
guided_angle_state . thrust = 0.0f ;
guided_angle_state . climb_rate_cms = climb_rate_cms_or_thrust ;
}
guided_angle_state . update_time_ms = millis ( ) ;
// interpret positive climb rate as triggering take-off
if ( motors - > armed ( ) & & ! copter . ap . auto_armed & & ( guided_angle_state . climb_rate_cms > 0.0f ) ) {
// interpret positive climb rate or thrust as triggering take-off
if ( motors - > armed ( ) & & ! copter . ap . auto_armed & & is_positive ( climb_rate_cms_or_thrust ) ) {
copter . set_auto_armed ( true ) ;
}
// log target
copter . 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 ) ) ;
Vector3f ( 0.0f , 0.0f , climb_rate_cms_or_thrust ) ) ;
}
// guided_run - runs the guided controller
@ -567,11 +577,14 @@ void ModeGuided::angle_control_run()
@@ -567,11 +577,14 @@ void ModeGuided::angle_control_run()
float yaw_in = wrap_180_cd ( guided_angle_state . yaw_cd ) ;
float yaw_rate_in = wrap_180_cd ( guided_angle_state . yaw_rate_cds ) ;
float climb_rate_cms = 0.0f ;
if ( ! guided_angle_state . use_thrust ) {
// constrain climb rate
float climb_rate_cms = constrain_float ( guided_angle_state . climb_rate_cms , - fabsf ( wp_nav - > get_default_speed_down ( ) ) , wp_nav - > get_default_speed_up ( ) ) ;
climb_rate_cms = constrain_float ( guided_angle_state . climb_rate_cms , - fabsf ( wp_nav - > get_default_speed_down ( ) ) , wp_nav - > get_default_speed_up ( ) ) ;
// get avoidance adjusted climb rate
climb_rate_cms = get_avoidance_adjusted_climbrate ( climb_rate_cms ) ;
}
// check for timeout - set lean angles and climb rate to zero if no updates received for 3 seconds
uint32_t tnow = millis ( ) ;
@ -580,6 +593,7 @@ void ModeGuided::angle_control_run()
@@ -580,6 +593,7 @@ void ModeGuided::angle_control_run()
pitch_in = 0.0f ;
climb_rate_cms = 0.0f ;
yaw_rate_in = 0.0f ;
guided_angle_state . use_thrust = false ;
}
// if not armed set throttle to zero and exit immediately
@ -611,8 +625,12 @@ void ModeGuided::angle_control_run()
@@ -611,8 +625,12 @@ void ModeGuided::angle_control_run()
}
// call position controller
if ( guided_angle_state . use_thrust ) {
attitude_control - > set_throttle_out ( guided_angle_state . thrust , true , copter . g . throttle_filt ) ;
} else {
pos_control - > set_alt_target_from_climb_rate_ff ( climb_rate_cms , G_Dt , false ) ;
pos_control - > update_z_controller ( ) ;
}
}
// helper function to update position controller's desired velocity while respecting acceleration limits