更新注释

main
詹力 2024-07-03 17:43:24 +08:00
parent 94b2281895
commit 9549fa8184
2 changed files with 10 additions and 1 deletions

View File

@ -30,6 +30,8 @@ public:
hardware_interface::VelocityJointInterface velocity_joint_interface;
// The units for wheels are radians (pos), radians per second (vel,cmd), and Netwton metres (eff)
// 轮子的单位是弧度(位置)、弧度每秒(速度和命令)、牛顿米(扭矩)
// Joint关节一般机械臂里面控制用的较多
struct Joint {
std_msgs::Float64 pos;
std_msgs::Float64 vel;

View File

@ -164,6 +164,7 @@ void Hoverboard::protocol_recv (char byte) {
temp_pub.publish(f);
// 转换 RPM to RAD/S
// direction_correction 这个参数默认为1根据ros的调整进行更新
joints[0].vel.data = direction_correction * (abs(msg.speedL_meas) * 0.10472);
joints[1].vel.data = direction_correction * (abs(msg.speedR_meas) * 0.10472);
@ -194,10 +195,15 @@ void Hoverboard::write(const ros::Time& time, const ros::Duration& period) {
// 计算PID输出
double pid_outputs[2];
// 这里的PID控制器测量速度、预期速度、控制周期
// 这里调用的是PID::operator()
// cmd.data应该是预期的速度
pid_outputs[0] = pids[0](joints[0].vel.data, joints[0].cmd.data, period);
pid_outputs[1] = pids[1](joints[1].vel.data, joints[1].cmd.data, period);
// Convert PID outputs in RAD/S to RPM
// PID输出的是弧度每秒需要转为转每分钟
// RPM=RAD/sec × (2*pi)/60 = RAD/sec * *(2*3.141592) / 60 = 0.1047197
double set_speed[2] = {
pid_outputs[0] / 0.10472,
pid_outputs[1] / 0.10472
@ -205,6 +211,7 @@ void Hoverboard::write(const ros::Time& time, const ros::Duration& period) {
// Calculate steering from difference of left and right
// 根据左右差计算转向
// 机器人底层的控制应该是采用差速控制模型
const double speed = (set_speed[0] + set_speed[1]) / 2.0;
const double steer = (set_speed[0] - speed) * 2.0;