roll_pitch_yawrate_thrust_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 
23 namespace rotors_control {
24 
26  : initialized_params_(false),
27  controller_active_(false) {
29 }
30 
32 
35  // To make the tuning independent of the inertia matrix we divide here.
37  * vehicle_parameters_.inertia_.inverse();
38  // To make the tuning independent of the inertia matrix we divide here.
40  * vehicle_parameters_.inertia_.inverse();
41 
42  Eigen::Matrix4d I;
43  I.setZero();
44  I.block<3, 3>(0, 0) = vehicle_parameters_.inertia_;
45  I(3, 3) = 1;
47  // Calculate the pseude-inverse A^{ \dagger} and then multiply by the inertia matrix I.
48  // A^{ \dagger} = A^T*(A*A^T)^{-1}
51  * controller_parameters_.allocation_matrix_.transpose()).inverse() * I;
52  initialized_params_ = true;
53 }
54 
55 void RollPitchYawrateThrustController::CalculateRotorVelocities(Eigen::VectorXd* rotor_velocities) const {
56  assert(rotor_velocities);
57  assert(initialized_params_);
58 
59  rotor_velocities->resize(vehicle_parameters_.rotor_configuration_.rotors.size());
60  // Return 0 velocities on all rotors, until the first command is received.
61  if (!controller_active_) {
62  *rotor_velocities = Eigen::VectorXd::Zero(rotor_velocities->rows());
63  return;
64  }
65 
66  Eigen::Vector3d angular_acceleration;
67  ComputeDesiredAngularAcc(&angular_acceleration);
68 
69  Eigen::Vector4d angular_acceleration_thrust;
70  angular_acceleration_thrust.block<3, 1>(0, 0) = angular_acceleration;
71  angular_acceleration_thrust(3) = roll_pitch_yawrate_thrust_.thrust.z();
72 
73  *rotor_velocities = angular_acc_to_rotor_velocities_ * angular_acceleration_thrust;
74  *rotor_velocities = rotor_velocities->cwiseMax(Eigen::VectorXd::Zero(rotor_velocities->rows()));
75  *rotor_velocities = rotor_velocities->cwiseSqrt();
76 }
77 
79  odometry_ = odometry;
80 }
81 
83  const mav_msgs::EigenRollPitchYawrateThrust& roll_pitch_yawrate_thrust) {
84  roll_pitch_yawrate_thrust_ = roll_pitch_yawrate_thrust;
85  controller_active_ = true;
86 }
87 
88 // Implementation from the T. Lee et al. paper
89 // Control of complex maneuvers for a quadrotor UAV using geometric methods on SE(3)
90 void RollPitchYawrateThrustController::ComputeDesiredAngularAcc(Eigen::Vector3d* angular_acceleration) const {
91  assert(angular_acceleration);
92 
93  Eigen::Matrix3d R = odometry_.orientation.toRotationMatrix();
94  double yaw = atan2(R(1, 0), R(0, 0));
95 
96  // Get the desired rotation matrix.
97  Eigen::Matrix3d R_des;
98  R_des = Eigen::AngleAxisd(yaw, Eigen::Vector3d::UnitZ()) // yaw
99  * Eigen::AngleAxisd(roll_pitch_yawrate_thrust_.roll, Eigen::Vector3d::UnitX()) // roll
100  * Eigen::AngleAxisd(roll_pitch_yawrate_thrust_.pitch, Eigen::Vector3d::UnitY()); // pitch
101 
102  // Angle error according to lee et al.
103  Eigen::Matrix3d angle_error_matrix = 0.5 * (R_des.transpose() * R - R.transpose() * R_des);
104  Eigen::Vector3d angle_error;
105  vectorFromSkewMatrix(angle_error_matrix, &angle_error);
106 
107  // TODO(burrimi) include angular rate references at some point.
108  Eigen::Vector3d angular_rate_des(Eigen::Vector3d::Zero());
109  angular_rate_des[2] = roll_pitch_yawrate_thrust_.yaw_rate;
110 
111  Eigen::Vector3d angular_rate_error = odometry_.angular_velocity - R_des.transpose() * R * angular_rate_des;
112 
113  *angular_acceleration = -1 * angle_error.cwiseProduct(normalized_attitude_gain_)
114  - angular_rate_error.cwiseProduct(normalized_angular_rate_gain_)
115  + odometry_.angular_velocity.cross(odometry_.angular_velocity); // we don't need the inertia matrix here
116 }
117 }
Eigen::Vector3d angular_velocity
Definition: common.h:68
RotorConfiguration rotor_configuration_
Definition: parameters.h:83
void ComputeDesiredAngularAcc(Eigen::Vector3d *angular_acceleration) const
void vectorFromSkewMatrix(Eigen::Matrix3d &skew_matrix, Eigen::Vector3d *vector)
Definition: common.h:116
std::vector< Rotor > rotors
Definition: parameters.h:69
Eigen::Quaterniond orientation
Definition: common.h:66
RollPitchYawrateThrustControllerParameters controller_parameters_
void SetRollPitchYawrateThrust(const mav_msgs::EigenRollPitchYawrateThrust &roll_pitch_yawrate_thrust)
void calculateAllocationMatrix(const RotorConfiguration &rotor_configuration, Eigen::Matrix4Xd *allocation_matrix)
Definition: common.h:79
void CalculateRotorVelocities(Eigen::VectorXd *rotor_velocities) const


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