135class Controller :
public controller_interface::MultiInterfaceController<rm_control::RobotStateInterface,
136 hardware_interface::ImuSensorInterface,
137 hardware_interface::EffortJointInterface>
141 bool init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh)
override;
142 void starting(
const ros::Time& time)
override;
143 void update(
const ros::Time& time,
const ros::Duration& period)
override;
144 void setDes(
const ros::Time& time,
double yaw_des,
double pitch_des,
double traject_yaw_des,
bool update_yaw =
true,
145 bool update_pitch =
true);
148 void rate(
const ros::Time& time,
const ros::Duration& period);
149 void track(
const ros::Time& time);
150 void direct(
const ros::Time& time);
151 void traj(
const ros::Time& time);
152 bool setDesIntoLimit(
double& angle,
const urdf::JointConstSharedPtr& joint_urdf,
bool update,
double current_angle);
153 void moveJoint(
const ros::Time& time,
const ros::Duration& period);
154 void updateChassisVel();
155 void updateBallisticSolution(
const ros::Time& time);
156 double gravityFeedForward(
const ros::Time& time);
157 double updateCompensation(
double chassis_vel_angular_z);
158 void commandCB(
const rm_msgs::GimbalCmdConstPtr& msg);
159 void trackCB(
const rm_msgs::TrackDataConstPtr& msg);
160 void ballisticSolverRequestCB(
const std_msgs::BoolConstPtr& msg);
161 void reconfigCB(rm_gimbal_controllers::GimbalBaseConfig& config, uint32_t);
162 std::string getGimbalFrameID(std::unordered_map<int, urdf::JointConstSharedPtr> joint_urdfs);
163 std::string getBaseFrameID(std::unordered_map<int, urdf::JointConstSharedPtr> joint_urdfs);
165 rm_control::RobotStateHandle robot_state_handle_;
166 hardware_interface::ImuSensorHandle imu_sensor_handle_;
167 std::unordered_map<int, std::unique_ptr<effort_controllers::JointVelocityController>> ctrls_;
168 std::unordered_map<int, std::unique_ptr<control_toolbox::Pid>> pid_pos_;
169 std::unordered_map<int, urdf::JointConstSharedPtr> joint_urdfs_;
170 std::unordered_map<int, bool> pos_des_in_limit_;
171 bool has_imu_ =
true;
172 double ballistic_yaw_{}, ballistic_pitch_{};
174 std::shared_ptr<BulletSolver> bullet_solver_;
175 std::shared_ptr<BallisticSolver> ballistic_solver_;
178 ros::Time last_publish_time_{};
179 ros::Time last_ballistic_publish_time_{};
180 std::unordered_map<int, std::unique_ptr<realtime_tools::RealtimePublisher<rm_msgs::GimbalPosState>>> pos_state_pub_;
181 std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::GimbalDesError>> error_pub_;
182 std::shared_ptr<realtime_tools::RealtimePublisher<std_msgs::Float32MultiArray>> ballistic_solution_pub_;
183 ros::Subscriber cmd_gimbal_sub_;
184 ros::Subscriber data_track_sub_;
185 ros::Subscriber ballistic_solver_request_sub_;
186 realtime_tools::RealtimeBuffer<rm_msgs::GimbalCmd> cmd_rt_buffer_;
187 realtime_tools::RealtimeBuffer<rm_msgs::TrackData> track_rt_buffer_;
188 realtime_tools::RealtimeBuffer<std_msgs::Bool> ballistic_track_rt_buffer_;
190 rm_msgs::GimbalCmd cmd_gimbal_;
191 rm_msgs::TrackData data_track_;
192 std::string gimbal_des_frame_id_{}, imu_name_{}, gimbal_traject_des_frame_id_;
193 double publish_rate_{};
194 bool state_changed_{};
198 geometry_msgs::TransformStamped odom2gimbal_des_, odom2gimbal_, odom2base_, last_odom2base_, base2gimbal_,
199 odom2gimbal_traject_des_;
202 geometry_msgs::Vector3 mass_origin_;
204 bool enable_gravity_compensation_{};
207 std::shared_ptr<ChassisVel> chassis_vel_;
208 double chassis_compensation_{};
210 bool dynamic_reconfig_initialized_{};
211 GimbalConfig config_{};
212 realtime_tools::RealtimeBuffer<GimbalConfig> config_rt_buffer_;
213 dynamic_reconfigure::Server<rm_gimbal_controllers::GimbalBaseConfig>* d_srv_{};
224 double pos_real[3]{ 0. };
225 double pos_des[3]{ 0. }, vel_des[3]{ 0. }, angle_error[3]{ 0. }, traject_pos_des[3]{ 0. },
226 traject_angle_error[3]{ 0. };