rm_controllers
Loading...
Searching...
No Matches
balance.h
Go to the documentation of this file.
1//
2// Created by yezi on 2022/11/15.
3//
4
5#pragma once
6
7#include <rm_common/lqr.h>
8#include <controller_interface/multi_interface_controller.h>
9#include <hardware_interface/imu_sensor_interface.h>
10#include <hardware_interface/joint_command_interface.h>
11#include <rm_msgs/BalanceState.h>
12
14
16{
17using Eigen::Matrix;
18class BalanceController : public ChassisBase<rm_control::RobotStateInterface, hardware_interface::ImuSensorInterface,
19 hardware_interface::EffortJointInterface>
20{
21 enum BalanceMode
22 {
23 NORMAL,
24 BLOCK
25 };
26
27public:
28 BalanceController() = default;
29 bool init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh) override;
30
31private:
32 void moveJoint(const ros::Time& time, const ros::Duration& period) override;
33 void normal(const ros::Time& time, const ros::Duration& period);
34 void block(const ros::Time& time, const ros::Duration& period);
35 geometry_msgs::Twist odometry() override;
36 static const int STATE_DIM = 10;
37 static const int CONTROL_DIM = 4;
38 Eigen::Matrix<double, CONTROL_DIM, STATE_DIM> k_{};
39 Eigen::Matrix<double, STATE_DIM, STATE_DIM> a_{}, q_{};
40 Eigen::Matrix<double, STATE_DIM, CONTROL_DIM> b_{};
41 Eigen::Matrix<double, CONTROL_DIM, CONTROL_DIM> r_{};
42 Eigen::Matrix<double, STATE_DIM, 1> x_;
43 double wheel_radius_, wheel_base_;
44 double position_des_ = 0;
45 double position_offset_ = 0.;
46 double position_clear_threshold_ = 0.;
47 double yaw_des_ = 0;
48
49 int balance_mode_;
50 ros::Time block_time_, last_block_time_;
51 double block_angle_, block_duration_, block_velocity_, block_effort_, anti_block_effort_, block_overtime_;
52 bool balance_state_changed_ = false, maybe_block_ = false;
53
54 hardware_interface::ImuSensorHandle imu_handle_;
55 hardware_interface::JointHandle left_wheel_joint_handle_, right_wheel_joint_handle_,
56 left_momentum_block_joint_handle_, right_momentum_block_joint_handle_;
57
58 typedef std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::BalanceState>> RtpublisherPtr;
59 RtpublisherPtr state_pub_;
60 geometry_msgs::Vector3 angular_vel_base_;
61 double roll_, pitch_, yaw_;
62};
63
64} // namespace rm_chassis_controllers
bool init(hardware_interface::RobotHW *robot_hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh) override
Definition balance.cpp:17
Definition chassis_base.h:95
Definition active_suspension.h:16