Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AC_AttitudeControl/AC_AttitudeControl_Multi_6DoF.cpp
Views: 1798
#include <AP_Scripting/AP_Scripting_config.h>12#if AP_SCRIPTING_ENABLED34#include "AC_AttitudeControl_Multi_6DoF.h"5#include <AP_HAL/AP_HAL.h>6#include <AP_Math/AP_Math.h>78// 6DoF control is extracted from the existing copter code by treating desired angles as thrust angles rather than vehicle attitude.9// Vehicle attitude is then set separately, typically the vehicle would maintain 0 roll and pitch.10// rate commands result in the vehicle behaving as a ordinary copter.1112// run lowest level body-frame rate controller and send outputs to the motors13void AC_AttitudeControl_Multi_6DoF::rate_controller_run() {1415// pass current offsets to motors and run baseclass controller16// motors require the offsets to know which way is up17float roll_deg = roll_offset_deg;18float pitch_deg = pitch_offset_deg;19// if 6DoF control, always point directly up20// this stops horizontal drift due to error between target and true attitude21if (lateral_enable) {22roll_deg = degrees(AP::ahrs().get_roll());23}24if (forward_enable) {25pitch_deg = degrees(AP::ahrs().get_pitch());26}27_motors.set_roll_pitch(roll_deg,pitch_deg);2829AC_AttitudeControl_Multi::rate_controller_run();30}3132/*33override all input to the attitude controller and convert desired angles into thrust angles and substitute34*/3536// Command an euler roll and pitch angle and an euler yaw rate with angular velocity feedforward and smoothing37void AC_AttitudeControl_Multi_6DoF::input_euler_angle_roll_pitch_euler_rate_yaw(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_rate_cds) {3839set_forward_lateral(euler_pitch_angle_cd, euler_roll_angle_cd);4041AC_AttitudeControl_Multi::input_euler_angle_roll_pitch_euler_rate_yaw(euler_roll_angle_cd, euler_pitch_angle_cd, euler_yaw_rate_cds);42}4344// Command an euler roll, pitch and yaw angle with angular velocity feedforward and smoothing45void AC_AttitudeControl_Multi_6DoF::input_euler_angle_roll_pitch_yaw(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_angle_cd, bool slew_yaw) {4647set_forward_lateral(euler_pitch_angle_cd, euler_roll_angle_cd);4849AC_AttitudeControl_Multi::input_euler_angle_roll_pitch_yaw(euler_roll_angle_cd, euler_pitch_angle_cd, euler_yaw_angle_cd, slew_yaw);50}5152// Command a thrust vector and heading rate53void AC_AttitudeControl_Multi_6DoF::input_thrust_vector_rate_heading(const Vector3f& thrust_vector, float heading_rate_cds, bool slew_yaw)54{55// convert thrust vector to a roll and pitch angles56// this negates the advantage of using thrust vector control, but works just fine57Vector3f angle_target = attitude_from_thrust_vector(thrust_vector, _ahrs.yaw).to_vector312();5859input_euler_angle_roll_pitch_euler_rate_yaw(degrees(angle_target.x) * 100.0f, degrees(angle_target.y) * 100.0f, heading_rate_cds);60}6162// Command a thrust vector, heading and heading rate63void AC_AttitudeControl_Multi_6DoF::input_thrust_vector_heading(const Vector3f& thrust_vector, float heading_angle_cd, float heading_rate_cds)64{65// convert thrust vector to a roll and pitch angles66Vector3f angle_target = attitude_from_thrust_vector(thrust_vector, _ahrs.yaw).to_vector312();6768// note that we are throwing away heading rate here69input_euler_angle_roll_pitch_yaw(degrees(angle_target.x) * 100.0f, degrees(angle_target.y) * 100.0f, heading_angle_cd, true);70}7172void AC_AttitudeControl_Multi_6DoF::set_forward_lateral(float &euler_pitch_angle_cd, float &euler_roll_angle_cd)73{74// pitch/forward75if (forward_enable) {76_motors.set_forward(-sinf(radians(euler_pitch_angle_cd * 0.01f)));77euler_pitch_angle_cd = pitch_offset_deg * 100.0f;78} else {79_motors.set_forward(0.0f);80euler_pitch_angle_cd += pitch_offset_deg * 100.0f;81}82euler_pitch_angle_cd = wrap_180_cd(euler_pitch_angle_cd);8384// roll/lateral85if (lateral_enable) {86_motors.set_lateral(sinf(radians(euler_roll_angle_cd * 0.01f)));87euler_roll_angle_cd = roll_offset_deg * 100.0f;88} else {89_motors.set_lateral(0.0f);90euler_roll_angle_cd += roll_offset_deg * 100.0f;91}92euler_roll_angle_cd = wrap_180_cd(euler_roll_angle_cd);93}9495/*96all other input functions should zero thrust vectoring97*/9899// Command euler yaw rate and pitch angle with roll angle specified in body frame100// (used only by tailsitter quadplanes)101void AC_AttitudeControl_Multi_6DoF::input_euler_rate_yaw_euler_angle_pitch_bf_roll(bool plane_controls, float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_rate_cds) {102_motors.set_lateral(0.0f);103_motors.set_forward(0.0f);104105AC_AttitudeControl_Multi::input_euler_rate_yaw_euler_angle_pitch_bf_roll(plane_controls, euler_roll_angle_cd, euler_pitch_angle_cd, euler_yaw_rate_cds);106}107108// Command an euler roll, pitch, and yaw rate with angular velocity feedforward and smoothing109void AC_AttitudeControl_Multi_6DoF::input_euler_rate_roll_pitch_yaw(float euler_roll_rate_cds, float euler_pitch_rate_cds, float euler_yaw_rate_cds) {110_motors.set_lateral(0.0f);111_motors.set_forward(0.0f);112113AC_AttitudeControl_Multi::input_euler_rate_roll_pitch_yaw(euler_roll_rate_cds, euler_pitch_rate_cds, euler_yaw_rate_cds);114}115116// Command an angular velocity with angular velocity feedforward and smoothing117void AC_AttitudeControl_Multi_6DoF::input_rate_bf_roll_pitch_yaw(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds) {118_motors.set_lateral(0.0f);119_motors.set_forward(0.0f);120121AC_AttitudeControl_Multi::input_rate_bf_roll_pitch_yaw(roll_rate_bf_cds, pitch_rate_bf_cds, yaw_rate_bf_cds);122}123124// Command an angular velocity with angular velocity feedforward and smoothing125void AC_AttitudeControl_Multi_6DoF::input_rate_bf_roll_pitch_yaw_2(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds) {126_motors.set_lateral(0.0f);127_motors.set_forward(0.0f);128129AC_AttitudeControl_Multi::input_rate_bf_roll_pitch_yaw_2(roll_rate_bf_cds, pitch_rate_bf_cds, yaw_rate_bf_cds);130}131132// Command an angular velocity with angular velocity smoothing using rate loops only with integrated rate error stabilization133void AC_AttitudeControl_Multi_6DoF::input_rate_bf_roll_pitch_yaw_3(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds) {134_motors.set_lateral(0.0f);135_motors.set_forward(0.0f);136137AC_AttitudeControl_Multi::input_rate_bf_roll_pitch_yaw_3(roll_rate_bf_cds, pitch_rate_bf_cds, yaw_rate_bf_cds);138}139140// Command an angular step (i.e change) in body frame angle141void AC_AttitudeControl_Multi_6DoF::input_angle_step_bf_roll_pitch_yaw(float roll_angle_step_bf_cd, float pitch_angle_step_bf_cd, float yaw_angle_step_bf_cd) {142_motors.set_lateral(0.0f);143_motors.set_forward(0.0f);144145AC_AttitudeControl_Multi::input_angle_step_bf_roll_pitch_yaw(roll_angle_step_bf_cd, pitch_angle_step_bf_cd, yaw_angle_step_bf_cd);146}147148// Command a Quaternion attitude with feedforward and smoothing149// attitude_desired_quat: is updated on each time_step (_dt) by the integral of the angular velocity150void AC_AttitudeControl_Multi_6DoF::input_quaternion(Quaternion& attitude_desired_quat, Vector3f ang_vel_body) {151#if CONFIG_HAL_BOARD == HAL_BOARD_SITL152AP_HAL::panic("input_quaternion not implemented AC_AttitudeControl_Multi_6DoF");153#endif154155_motors.set_lateral(0.0f);156_motors.set_forward(0.0f);157158AC_AttitudeControl_Multi::input_quaternion(attitude_desired_quat, ang_vel_body);159}160161162AC_AttitudeControl_Multi_6DoF *AC_AttitudeControl_Multi_6DoF::_singleton = nullptr;163164#endif // AP_SCRIPTING_ENABLED165166167