rate_controller.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Fadri Furrer, ASL, ETH Zurich, Switzerland
3  * Copyright 2015 Michael Burri, ASL, ETH Zurich, Switzerland
4  * Copyright 2015 Mina Kamel, ASL, ETH Zurich, Switzerland
5  * Copyright 2015 Janosch Nikolic, ASL, ETH Zurich, Switzerland
6  * Copyright 2015 Markus Achtelik, ASL, ETH Zurich, Switzerland
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
22 
24  : gravity_(9.81),
25  mass_(1.56779) {
26 }
28 
29 std::shared_ptr<ControllerBase> RateController::Clone() {
30  std::shared_ptr<ControllerBase> controller(new RateController);
31  return controller;
32 }
33 
35 
36  gain_angular_rate_(0) = 0.52;//0.6;
37  gain_angular_rate_(1) = 0.52;//0.6;
38  gain_angular_rate_(2) = 0.025;
39 
40  amount_rotors_ = 6;
41  allocation_matrix_.resize(4,amount_rotors_);
42  allocation_matrix_ << sin(M_PI/6), 1, sin(M_PI/6), -sin(M_PI/6), -1, -sin(M_PI/6),
43  -cos(M_PI/6), 0, cos(M_PI/6), cos(M_PI/6), 0, -cos(M_PI/6),
44  -1, 1, -1, 1, -1, 1,
45  1, 1, 1, 1, 1, 1;
46 
47  inertia_matrix_<< 0.0347563, 0, 0,
48  0, 0.0458929, 0,
49  0, 0, 0.0977;
50 
51  // to make the tuning independent of the inertia matrix we divide here
52  gain_angular_rate_ = gain_angular_rate_.transpose() * inertia_matrix_.inverse();
53 
54  const double rotor_force_constant = 0.00000854858; //F_i = k_n * rotor_velocity_i^2
55  const double rotor_moment_constant = 0.016; // M_i = k_m * F_i
56 
57  angular_acc_to_rotor_velocities_.resize(amount_rotors_, 4);
58  const double arm_length = 0.215;
59 
60  Eigen::Matrix4d K;
61  K.setZero();
62  K(0, 0) = arm_length * rotor_force_constant;
63  K(1, 1) = arm_length * rotor_force_constant;
64  K(2, 2) = rotor_force_constant * rotor_moment_constant;
65  K(3, 3) = rotor_force_constant;
66 
67  Eigen::Matrix4d I;
68  I.setZero();
69  I.block<3, 3>(0, 0) = inertia_matrix_;
70  I(3, 3) = 1;
72  * (allocation_matrix_ * allocation_matrix_.transpose()).inverse() * K.inverse() * I;
73  initialized_params_ = true;
74 }
75 
76 void RateController::CalculateRotorVelocities(Eigen::VectorXd* rotor_velocities) const {
77  assert(rotor_velocities);
78  assert(initialized_params_);
79 
80  rotor_velocities->resize(amount_rotors_);
81 
82  Eigen::Vector3d angular_acceleration;
83  ComputeDesiredAngularAcc(&angular_acceleration);
84 
85  Eigen::Vector4d angular_acceleration_thrust;
86  angular_acceleration_thrust.block<3,1>(0,0) = angular_acceleration;
87  angular_acceleration_thrust(3) = control_rate_thrust_reference_(3);
88 
89  *rotor_velocities = angular_acc_to_rotor_velocities_ * angular_acceleration_thrust;
90  *rotor_velocities = rotor_velocities->cwiseMax(Eigen::VectorXd::Zero(rotor_velocities->rows()));
91  *rotor_velocities = rotor_velocities->cwiseSqrt();
92 }
93 
94 // Implementation from the T. Lee et al. paper
95 // Control of complex maneuvers for a quadrotor UAV using geometric methods on SE(3)
96 void RateController::ComputeDesiredAngularAcc(Eigen::Vector3d* angular_acceleration) const {
97  assert(angular_acceleration);
98 
99  Eigen::Vector3d angular_rate_des(Eigen::Vector3d::Zero());
100  angular_rate_des[0] = control_rate_thrust_reference_(0);
101  angular_rate_des[1] = control_rate_thrust_reference_(1);
102  angular_rate_des[2] = control_rate_thrust_reference_(2);
103 
104  Eigen::Vector3d angular_rate_error = angular_rate_ - angular_rate_des;
105 
106  *angular_acceleration = - angular_rate_error.cwiseProduct(gain_angular_rate_)
107  + angular_rate_.cross(angular_rate_); // we don't need the inertia matrix here
108 }
109 
110 
Eigen::Matrix4Xd allocation_matrix_
void ComputeDesiredAngularAcc(Eigen::Vector3d *angular_acceleration) const
virtual void InitializeParams()
virtual std::shared_ptr< ControllerBase > Clone()
virtual ~RateController()
Eigen::MatrixX4d angular_acc_to_rotor_velocities_
virtual void CalculateRotorVelocities(Eigen::VectorXd *rotor_velocities) const
Eigen::Matrix3d inertia_matrix_
Eigen::Vector3d gain_angular_rate_
ROTORS_CONTROL_REGISTER_CONTROLLER(RateController)


rotors_control
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Mon Feb 28 2022 23:38:55