50 hardware_interface::EffortJointInterface>,
55 bool init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh)
override;
56 void moveJoint(
const ros::Time& time,
const ros::Duration& period)
override;
57 void stopping(
const ros::Time& time)
override;
63 Eigen::Matrix<double, 4, CONTROL_DIM * STATE_DIM>
getCoeffs()
override {
return coeffs_; }
64 const std::shared_ptr<ModelParams>&
getModelParams()
const override {
return model_params_; }
65 const std::shared_ptr<ControlParams>&
getControlParams()
const override {
return control_params_; }
66 const std::shared_ptr<BiasParams>&
getBiasParams()
const override {
return bias_params_; }
67 const std::shared_ptr<LegStateThresholdParams>&
getLegThresholdParams()
const override {
return leg_threshold_params_; }
69 double getLegCmd()
const override {
return legCmd_; }
74 inline bool getMoveFlag()
const override {
return move_flag_; }
75 inline void setMoveFlag(
const bool& move_flag)
override { move_flag_ = move_flag; }
78 inline bool getDown5cmStairFlag()
const override {
return down_5cm_stair_flag_.load(std::memory_order_acquire); }
79 inline void setDown5cmStairFlag(
bool flag)
override { down_5cm_stair_flag_.store(flag, std::memory_order_release); }
80 inline void setStateChange(
bool state)
override { balance_state_changed_ = state; }
83 void setMode(
int mode)
override { balance_mode_ = mode; }
87 void pubLQRStatus(Eigen::Matrix<double, STATE_DIM, 1> left_error, Eigen::Matrix<double, STATE_DIM, 1> right_error,
88 Eigen::Matrix<double, STATE_DIM, 1> left_ref, Eigen::Matrix<double, STATE_DIM, 1> right_ref,
89 Eigen::Matrix<double, CONTROL_DIM, 1> u_left, Eigen::Matrix<double, CONTROL_DIM, 1> u_right,
90 Eigen::Matrix<double, CONTROL_DIM, 1> F_leg_,
const bool unstick[2])
const override;
93 void pubDebugData(
const std::string& name,
double value)
override{ debugPub_->add(name, value); };
96 double getLegThetaOffset(
const double& leg_len)
override {
return leg_theta_offset_interp_.output(leg_len); }
99 void updateEstimation(
const ros::Time& time,
const ros::Duration& period);
101 bool setupLQR(ros::NodeHandle& controller_nh);
102 bool setupParams(ros::NodeHandle& controller_nh);
103 bool setupModelParams(ros::NodeHandle& controller_nh);
104 bool setupControlParams(ros::NodeHandle& controller_nh);
105 bool setupBiasParams(ros::NodeHandle& controller_nh);
106 bool setupThresholdParams(ros::NodeHandle& controller_nh);
107 bool setupSpringParams(ros::NodeHandle& controller_nh);
108 bool setupChassisGeometryParams(ros::NodeHandle& controller_nh);
109 void polyfit(
const std::vector<Eigen::Matrix<double, 2, 6>>& Ks,
const std::vector<double>& L0s,
110 Eigen::Matrix<double, 4, 12>& coeffs);
111 void triggerDown5cmStairAction()
113 down_5cm_stair_flag_.store(
true, std::memory_order_release);
115 bool down5cmStairSrvCallback(std_srvs::Trigger::Request& req, std_srvs::Trigger::Response& res);
116 geometry_msgs::Twist odometry()
override;
118 void reconfigCB(rm_chassis_controllers::LQRWeightConfig& config, uint32_t level);
120 Eigen::Matrix<double, 4, CONTROL_DIM * STATE_DIM> coeffs_;
121 Eigen::Matrix<double, STATE_DIM, STATE_DIM> q_{};
122 Eigen::Matrix<double, CONTROL_DIM, CONTROL_DIM> r_{};
124 std::shared_ptr<ModelParams> model_params_;
125 std::shared_ptr<ControlParams> control_params_;
126 std::shared_ptr<BiasParams> bias_params_;
127 std::shared_ptr<SpringParams> spring_params_;
128 std::shared_ptr<ChassisGeometryParams> chassis_geometry_params_;
129 std::shared_ptr<LegStateThresholdParams> leg_threshold_params_;
132 bool balance_state_changed_ =
false;
133 std::shared_ptr<ModeManager> mode_manager_;
136 double leftWheelVel{}, rightWheelVel{}, leftWheelVelAbsolute{}, rightWheelVelAbsolute{}, slip_alpha_{ 2.0 },
137 slip_R_wheel_{}, R_wheel_{};
138 int itor = 0, sample_times_ = 0;
139 bool slip_flag_{
false };
140 Eigen::Matrix<double, 2, 2> A_, B_, H_, Q_, R_;
141 Eigen::Matrix<double, 2, 1> X_, U_;
142 std::shared_ptr<KalmanFilter<double>> kalmanFilterPtr_;
144 ChassisState chassis_state_;
145 LegState leg_state_[2];
147 rm_common::LinearInterp leg_theta_offset_interp_;
148 double default_leg_length_{ 0.12 };
149 bool move_flag_{
false };
150 std::atomic_bool down_5cm_stair_flag_{
false };
152 bool complete_stand_ =
false, overturn_ =
false;
154 bool recovery_leg_spd_turnback_{
false };
157 hardware_interface::ImuSensorHandle imu_handle_, gimbal_imu_handle_;
158 hardware_interface::JointHandle left_wheel_joint_handle_, right_wheel_joint_handle_;
159 hardware_interface::JointHandle left_hip_joint_handle_, left_knee_joint_handle_, right_hip_joint_handle_,
160 right_knee_joint_handle_;
161 std::vector<hardware_interface::JointHandle*> joint_handles_;
164 double legCmd_{ 0.2 };
165 bool jumpCmd_{
false };
168 dynamic_reconfigure::Server<rm_chassis_controllers::LQRWeightConfig>* d_srv_;
169 realtime_tools::RealtimeBuffer<LQRConfig> config_rt_buffer_;
171 bool dynamic_reconfig_initialized_{
false };
172 ros::Subscriber leg_cmd_sub_, recovery_leg_spd_turnback_sub_;
173 ros::Publisher unstick_pub_, upstair_status_pub_;
174 std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::LeggedChassisStatus>> legged_chassis_status_pub_;
175 std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::LeggedChassisMode>> legged_chassis_mode_pub_;
176 std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::LeggedLQRStatus>> lqr_status_pub_;
177 ros::Time cmd_update_time_;
178 std::shared_ptr<DebugDataPublisher> debugPub_;
179 ros::ServiceServer down_5cm_stair_srv_;
void pubLQRStatus(Eigen::Matrix< double, STATE_DIM, 1 > left_error, Eigen::Matrix< double, STATE_DIM, 1 > right_error, Eigen::Matrix< double, STATE_DIM, 1 > left_ref, Eigen::Matrix< double, STATE_DIM, 1 > right_ref, Eigen::Matrix< double, CONTROL_DIM, 1 > u_left, Eigen::Matrix< double, CONTROL_DIM, 1 > u_right, Eigen::Matrix< double, CONTROL_DIM, 1 > F_leg_, const bool unstick[2]) const override
Definition controller.cpp:585