Skip to content

Commit c831752

Browse files
author
Summer
authored
Merge pull request #186 from 1moule/2yaw
Optimize gimbal controller code
2 parents 76654ad + cf6517e commit c831752

2 files changed

Lines changed: 229 additions & 209 deletions

File tree

rm_gimbal_controllers/include/rm_gimbal_controllers/gimbal_base.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <urdf/model.h>
5656
#include <dynamic_reconfigure/server.h>
5757
#include <realtime_tools/realtime_publisher.h>
58+
#include <unordered_map>
5859

5960
namespace rm_gimbal_controllers
6061
{
@@ -143,44 +144,46 @@ class Controller : public controller_interface::MultiInterfaceController<rm_cont
143144
void track(const ros::Time& time);
144145
void direct(const ros::Time& time);
145146
void traj(const ros::Time& time);
146-
bool setDesIntoLimit(double& real_des, double current_des, double base2gimbal_current_des,
147-
const urdf::JointConstSharedPtr& joint_urdf);
147+
bool setDesIntoLimit(const tf2::Quaternion& base2gimbal_des, const urdf::JointConstSharedPtr& joint_urdf,
148+
tf2::Quaternion& base2new_des);
148149
void moveJoint(const ros::Time& time, const ros::Duration& period);
149-
double feedForward(const ros::Time& time);
150150
void updateChassisVel();
151+
double feedForward(const ros::Time& time);
151152
double updateCompensation(double chassis_vel_angular_z);
152153
void commandCB(const rm_msgs::GimbalCmdConstPtr& msg);
153154
void trackCB(const rm_msgs::TrackDataConstPtr& msg);
154155
void reconfigCB(rm_gimbal_controllers::GimbalBaseConfig& config, uint32_t);
156+
std::string getGimbalFrameID(std::unordered_map<int, urdf::JointConstSharedPtr> joint_urdfs);
157+
std::string getBaseFrameID(std::unordered_map<int, urdf::JointConstSharedPtr> joint_urdfs);
155158

156159
rm_control::RobotStateHandle robot_state_handle_;
157160
hardware_interface::ImuSensorHandle imu_sensor_handle_;
161+
std::unordered_map<int, std::unique_ptr<effort_controllers::JointVelocityController>> ctrls_;
162+
std::unordered_map<int, std::unique_ptr<control_toolbox::Pid>> pid_pos_;
163+
std::unordered_map<int, urdf::JointConstSharedPtr> joint_urdfs_;
164+
std::unordered_map<int, bool> pos_des_in_limit_;
158165
bool has_imu_ = true;
159-
effort_controllers::JointVelocityController ctrl_yaw_, ctrl_pitch_;
160-
control_toolbox::Pid pid_yaw_pos_, pid_pitch_pos_;
161166

162167
std::shared_ptr<BulletSolver> bullet_solver_;
163168

164169
// ROS Interface
165170
ros::Time last_publish_time_{};
166-
std::unique_ptr<realtime_tools::RealtimePublisher<rm_msgs::GimbalPosState>> yaw_pos_state_pub_, pitch_pos_state_pub_;
171+
std::unordered_map<int, std::unique_ptr<realtime_tools::RealtimePublisher<rm_msgs::GimbalPosState>>> pos_state_pub_;
167172
std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::GimbalDesError>> error_pub_;
168173
ros::Subscriber cmd_gimbal_sub_;
169174
ros::Subscriber data_track_sub_;
170175
realtime_tools::RealtimeBuffer<rm_msgs::GimbalCmd> cmd_rt_buffer_;
171176
realtime_tools::RealtimeBuffer<rm_msgs::TrackData> track_rt_buffer_;
172-
urdf::JointConstSharedPtr pitch_joint_urdf_, yaw_joint_urdf_;
173177

174178
rm_msgs::GimbalCmd cmd_gimbal_;
175179
rm_msgs::TrackData data_track_;
176180
std::string gimbal_des_frame_id_{}, imu_name_{};
177181
double publish_rate_{};
178182
bool state_changed_{};
179-
bool pitch_des_in_limit_{}, yaw_des_in_limit_{};
180183
int loop_count_{};
181184

182185
// Transform
183-
geometry_msgs::TransformStamped odom2gimbal_des_, odom2pitch_, odom2base_, last_odom2base_;
186+
geometry_msgs::TransformStamped odom2gimbal_des_, odom2gimbal_, odom2base_, last_odom2base_;
184187

185188
// Gravity Compensation
186189
geometry_msgs::Vector3 mass_origin_;
@@ -196,8 +199,6 @@ class Controller : public controller_interface::MultiInterfaceController<rm_cont
196199
realtime_tools::RealtimeBuffer<GimbalConfig> config_rt_buffer_;
197200
dynamic_reconfigure::Server<rm_gimbal_controllers::GimbalBaseConfig>* d_srv_{};
198201

199-
RampFilter<double>*ramp_rate_pitch_{}, *ramp_rate_yaw_{};
200-
201202
enum
202203
{
203204
RATE,

0 commit comments

Comments
 (0)