@ -93,7 +93,8 @@ void UUVAttitudeControl::parameters_update(bool force)
}
}
}
}
void UUVAttitudeControl : : constrain_actuator_commands ( float roll_u , float pitch_u , float yaw_u , float thrust_u )
void UUVAttitudeControl : : constrain_actuator_commands ( float roll_u , float pitch_u , float yaw_u ,
float thrust_x , float thrust_y , float thrust_z )
{
{
if ( PX4_ISFINITE ( roll_u ) ) {
if ( PX4_ISFINITE ( roll_u ) ) {
roll_u = math : : constrain ( roll_u , - 1.0f , 1.0f ) ;
roll_u = math : : constrain ( roll_u , - 1.0f , 1.0f ) ;
@ -119,13 +120,29 @@ void UUVAttitudeControl::constrain_actuator_commands(float roll_u, float pitch_u
_actuators . control [ actuator_controls_s : : INDEX_YAW ] = 0.0f ;
_actuators . control [ actuator_controls_s : : INDEX_YAW ] = 0.0f ;
}
}
if ( PX4_ISFINITE ( thrust_u ) ) {
if ( PX4_ISFINITE ( thrust_x ) ) {
thrust_u = math : : constrain ( thrust_u , - 1.0f , 1.0f ) ;
thrust_x = math : : constrain ( thrust_x , - 1.0f , 1.0f ) ;
_actuators . control [ actuator_controls_s : : INDEX_THROTTLE ] = thrust_u ;
_actuators . control [ actuator_controls_s : : INDEX_THROTTLE ] = thrust_x ;
} else {
} else {
_actuators . control [ actuator_controls_s : : INDEX_THROTTLE ] = 0.0f ;
_actuators . control [ actuator_controls_s : : INDEX_THROTTLE ] = 0.0f ;
}
}
if ( PX4_ISFINITE ( thrust_y ) ) {
thrust_y = math : : constrain ( thrust_y , - 1.0f , 1.0f ) ;
_actuators . control [ actuator_controls_s : : INDEX_FLAPS ] = thrust_y ;
} else {
_actuators . control [ actuator_controls_s : : INDEX_FLAPS ] = 0.0f ;
}
if ( PX4_ISFINITE ( thrust_z ) ) {
thrust_z = math : : constrain ( thrust_z , - 1.0f , 1.0f ) ;
_actuators . control [ actuator_controls_s : : INDEX_SPOILERS ] = thrust_z ;
} else {
_actuators . control [ actuator_controls_s : : INDEX_SPOILERS ] = 0.0f ;
}
}
}
void UUVAttitudeControl : : control_attitude_geo ( const vehicle_attitude_s & attitude ,
void UUVAttitudeControl : : control_attitude_geo ( const vehicle_attitude_s & attitude ,
@ -143,7 +160,9 @@ void UUVAttitudeControl::control_attitude_geo(const vehicle_attitude_s &attitude
float roll_u ;
float roll_u ;
float pitch_u ;
float pitch_u ;
float yaw_u ;
float yaw_u ;
float thrust_u ;
float thrust_x ;
float thrust_y ;
float thrust_z ;
float roll_body = attitude_setpoint . roll_body ;
float roll_body = attitude_setpoint . roll_body ;
float pitch_body = attitude_setpoint . pitch_body ;
float pitch_body = attitude_setpoint . pitch_body ;
@ -191,9 +210,12 @@ void UUVAttitudeControl::control_attitude_geo(const vehicle_attitude_s &attitude
yaw_u = torques ( 2 ) ;
yaw_u = torques ( 2 ) ;
// take thrust as
// take thrust as
thrust_u = attitude_setpoint . thrust_body [ 0 ] ;
thrust_x = attitude_setpoint . thrust_body [ 0 ] ;
thrust_y = attitude_setpoint . thrust_body [ 1 ] ;
thrust_z = attitude_setpoint . thrust_body [ 2 ] ;
constrain_actuator_commands ( roll_u , pitch_u , yaw_u , thrust_u ) ;
constrain_actuator_commands ( roll_u , pitch_u , yaw_u , thrust_x , thr ust_y , thrust_z ) ;
/* Geometric Controller END*/
/* Geometric Controller END*/
}
}
@ -235,6 +257,8 @@ void UUVAttitudeControl::Run()
_attitude_setpoint . pitch_body = _param_direct_pitch . get ( ) ;
_attitude_setpoint . pitch_body = _param_direct_pitch . get ( ) ;
_attitude_setpoint . yaw_body = _param_direct_yaw . get ( ) ;
_attitude_setpoint . yaw_body = _param_direct_yaw . get ( ) ;
_attitude_setpoint . thrust_body [ 0 ] = _param_direct_thrust . get ( ) ;
_attitude_setpoint . thrust_body [ 0 ] = _param_direct_thrust . get ( ) ;
_attitude_setpoint . thrust_body [ 1 ] = 0.f ;
_attitude_setpoint . thrust_body [ 2 ] = 0.f ;
}
}
/* Geometric Control*/
/* Geometric Control*/
@ -242,7 +266,7 @@ void UUVAttitudeControl::Run()
if ( skip_controller ) {
if ( skip_controller ) {
constrain_actuator_commands ( _rates_setpoint . roll , _rates_setpoint . pitch , _rates_setpoint . yaw ,
constrain_actuator_commands ( _rates_setpoint . roll , _rates_setpoint . pitch , _rates_setpoint . yaw ,
_rates_setpoint . thrust_body [ 0 ] ) ;
_rates_setpoint . thrust_body [ 0 ] , _rates_setpoint . thrust_body [ 1 ] , _rates_setpoint . thrust_body [ 2 ] ) ;
} else {
} else {
control_attitude_geo ( attitude , _attitude_setpoint , angular_velocity , _rates_setpoint ) ;
control_attitude_geo ( attitude , _attitude_setpoint , angular_velocity , _rates_setpoint ) ;
@ -257,7 +281,8 @@ void UUVAttitudeControl::Run()
if ( _vcontrol_mode . flag_control_manual_enabled & & ! _vcontrol_mode . flag_control_rates_enabled ) {
if ( _vcontrol_mode . flag_control_manual_enabled & & ! _vcontrol_mode . flag_control_rates_enabled ) {
/* manual/direct control */
/* manual/direct control */
constrain_actuator_commands ( _manual_control_setpoint . y , - _manual_control_setpoint . x ,
constrain_actuator_commands ( _manual_control_setpoint . y , - _manual_control_setpoint . x ,
_manual_control_setpoint . r , _manual_control_setpoint . z ) ;
_manual_control_setpoint . r ,
_manual_control_setpoint . z , 0.f , 0.f ) ;
}
}
}
}