From 3c509ee09e4b1c0ec0538dcdae56e30c4a16c7d4 Mon Sep 17 00:00:00 2001 From: Shotaro Itahara Date: Thu, 2 Nov 2023 15:57:59 +0900 Subject: [PATCH] [Control] enabled switching of control methods form config --- .../fully_actuated_nobend_controller.h | 2 + .../fully_actuated_nobend_controller.cpp | 112 ++++++++++++------ 2 files changed, 81 insertions(+), 33 deletions(-) diff --git a/aerial_robot_control/include/aerial_robot_control/control/fully_actuated_nobend_controller.h b/aerial_robot_control/include/aerial_robot_control/control/fully_actuated_nobend_controller.h index 1a87bcd7b..8e7ed2cf2 100644 --- a/aerial_robot_control/include/aerial_robot_control/control/fully_actuated_nobend_controller.h +++ b/aerial_robot_control/include/aerial_robot_control/control/fully_actuated_nobend_controller.h @@ -95,6 +95,8 @@ namespace aerial_robot_control double wrench_allocation_matrix_pub_interval_; void rosParamInit(); + int control_method; + }; } //namespace aerial_robot_control diff --git a/aerial_robot_control/src/control/fully_actuated_nobend_controller.cpp b/aerial_robot_control/src/control/fully_actuated_nobend_controller.cpp index 95a153da8..e4dae591e 100644 --- a/aerial_robot_control/src/control/fully_actuated_nobend_controller.cpp +++ b/aerial_robot_control/src/control/fully_actuated_nobend_controller.cpp @@ -115,48 +115,93 @@ namespace aerial_robot_control //Step0.5: obtain the normal vectors of thrusts std::vector rotors_normal = robot_model_->getRotorsNormalFromCog(); - // Step1: create new Q-matrix - - Eigen::MatrixXd Q_new(7,8); - Q_new<calcWrenchMatrixOnCoG(); + Eigen::MatrixXd q_bottom_q1(3,8), q_bottom_q2(3,8), q1_bottom(3,8), q2_bottom(3,8); + + q_bottom_q1 = WrenchMatrixOnCoG.bottomRows(3); + q_bottom_q2 = WrenchMatrixOnCoG.bottomRows(3); + + Eigen::VectorXd Q_row6 = Eigen::VectorXd::Zero(8), Q_row7 = Eigen::VectorXd::Zero(8); + + for(int i=0;i<4;i++){ + Q_row6(i) = ( (rotors_origin[i]-pCoG_1).cross(rotors_normal[i]) ).y(); + Q_row7(i+4) = ( (rotors_origin[i+4]-pCoG_2).cross(rotors_normal[i+4]) ).y(); + } - double sr_inverse_sigma = 0.1; - Eigen::MatrixXd q = Q_new_test; - Eigen::MatrixXd q_q_t = q * q.transpose(); - Eigen::MatrixXd sr_inv = q.transpose() * (q_q_t + sr_inverse_sigma* Eigen::MatrixXd::Identity(q_q_t.cols(), q_q_t.rows())).inverse(); + q_bottom_q1.row(1)=Q_row6; + q_bottom_q2.row(1)=Q_row7; - q_mat_inv_=sr_inv; - - //step3: calculate thrust accounting for softness & linear acc + q1_bottom = inertia_inv * q_bottom_q1; + q2_bottom = inertia_inv * q_bottom_q2; - tf::Vector3 gravity_world(0, - 0, - -9.8); - //gravity_world(3) = -9.8; - tf::Vector3 gravity_cog = uav_rot.inverse() * gravity_world; - Eigen::Vector3d gravity_CoG(gravity_cog.x(), gravity_cog.y(), gravity_cog.z() ); - Eigen::VectorXd thrust_constant = Eigen::VectorXd::Zero(8); - thrust_constant << 0,0,0,0,0,(mass/2)*(pCoG_1.cross(gravity_CoG)).y(),(mass/2)*(pCoG_2.cross(gravity_CoG)).y(); + //ROS_INFO_STREAM(rotors_normal[0]); + Eigen::MatrixXd Q_new_test(7,8); + Q_new_test<(control_nh, "torque_allocation_matrix_inv_pub_interval", torque_allocation_matrix_inv_pub_interval_, 0.05); getParam(control_nh, "wrench_allocation_matrix_pub_interval", wrench_allocation_matrix_pub_interval_, 0.1); + getParam(control_nh, "control_method", control_method, 0); } void FullyActuatedNobendController::setAttitudeGains()