Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "rotors_control/rate_controller.h"
00022
00023 RateController::RateController()
00024 : gravity_(9.81),
00025 mass_(1.56779) {
00026 }
00027 RateController::~RateController() {}
00028
00029 std::shared_ptr<ControllerBase> RateController::Clone() {
00030 std::shared_ptr<ControllerBase> controller(new RateController);
00031 return controller;
00032 }
00033
00034 void RateController::InitializeParams() {
00035
00036 gain_angular_rate_(0) = 0.52;
00037 gain_angular_rate_(1) = 0.52;
00038 gain_angular_rate_(2) = 0.025;
00039
00040 amount_rotors_ = 6;
00041 allocation_matrix_.resize(4,amount_rotors_);
00042 allocation_matrix_ << sin(M_PI/6), 1, sin(M_PI/6), -sin(M_PI/6), -1, -sin(M_PI/6),
00043 -cos(M_PI/6), 0, cos(M_PI/6), cos(M_PI/6), 0, -cos(M_PI/6),
00044 -1, 1, -1, 1, -1, 1,
00045 1, 1, 1, 1, 1, 1;
00046
00047 inertia_matrix_<< 0.0347563, 0, 0,
00048 0, 0.0458929, 0,
00049 0, 0, 0.0977;
00050
00051
00052 gain_angular_rate_ = gain_angular_rate_.transpose() * inertia_matrix_.inverse();
00053
00054 const double rotor_force_constant = 0.00000854858;
00055 const double rotor_moment_constant = 0.016;
00056
00057 angular_acc_to_rotor_velocities_.resize(amount_rotors_, 4);
00058 const double arm_length = 0.215;
00059
00060 Eigen::Matrix4d K;
00061 K.setZero();
00062 K(0, 0) = arm_length * rotor_force_constant;
00063 K(1, 1) = arm_length * rotor_force_constant;
00064 K(2, 2) = rotor_force_constant * rotor_moment_constant;
00065 K(3, 3) = rotor_force_constant;
00066
00067 Eigen::Matrix4d I;
00068 I.setZero();
00069 I.block<3, 3>(0, 0) = inertia_matrix_;
00070 I(3, 3) = 1;
00071 angular_acc_to_rotor_velocities_ = allocation_matrix_.transpose()
00072 * (allocation_matrix_ * allocation_matrix_.transpose()).inverse() * K.inverse() * I;
00073 initialized_params_ = true;
00074 }
00075
00076 void RateController::CalculateRotorVelocities(Eigen::VectorXd* rotor_velocities) const {
00077 assert(rotor_velocities);
00078 assert(initialized_params_);
00079
00080 rotor_velocities->resize(amount_rotors_);
00081
00082 Eigen::Vector3d angular_acceleration;
00083 ComputeDesiredAngularAcc(&angular_acceleration);
00084
00085 Eigen::Vector4d angular_acceleration_thrust;
00086 angular_acceleration_thrust.block<3,1>(0,0) = angular_acceleration;
00087 angular_acceleration_thrust(3) = control_rate_thrust_reference_(3);
00088
00089 *rotor_velocities = angular_acc_to_rotor_velocities_ * angular_acceleration_thrust;
00090 *rotor_velocities = rotor_velocities->cwiseMax(Eigen::VectorXd::Zero(rotor_velocities->rows()));
00091 *rotor_velocities = rotor_velocities->cwiseSqrt();
00092 }
00093
00094
00095
00096 void RateController::ComputeDesiredAngularAcc(Eigen::Vector3d* angular_acceleration) const {
00097 assert(angular_acceleration);
00098
00099 Eigen::Vector3d angular_rate_des(Eigen::Vector3d::Zero());
00100 angular_rate_des[0] = control_rate_thrust_reference_(0);
00101 angular_rate_des[1] = control_rate_thrust_reference_(1);
00102 angular_rate_des[2] = control_rate_thrust_reference_(2);
00103
00104 Eigen::Vector3d angular_rate_error = angular_rate_ - angular_rate_des;
00105
00106 *angular_acceleration = - angular_rate_error.cwiseProduct(gain_angular_rate_)
00107 + angular_rate_.cross(angular_rate_);
00108 }
00109
00110
00111 ROTORS_CONTROL_REGISTER_CONTROLLER(RateController);
rotors_control
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Thu Apr 18 2019 02:43:38