修复舵机发热问题
This commit is contained in:
1 parent
2ccbd44b51
commit
3b94aa4d1c
5 files changed
+170
-48
No files matched your search
@@ -371,58 +371,50 @@ void loop()
|
||||
web_loop(); // Web数据更新
|
||||
mpu6050.update(); // IMU数据更新
|
||||
|
||||
// 设置电机目标为0,停止电机
|
||||
motor1.target = 0;
|
||||
motor2.target = 0;
|
||||
motor1.loopFOC();
|
||||
motor2.loopFOC();
|
||||
motor1.move();
|
||||
motor2.move();
|
||||
|
||||
// 如果正在执行坐下动作,逐步调整角度零点让小车向后倒
|
||||
if (sitting_down) {
|
||||
// 缓慢调整角度零点,使小车向后倒
|
||||
static int sit_counter = 0;
|
||||
sit_counter++;
|
||||
|
||||
if (sit_counter < 100) { // 分100步完成坐下动作
|
||||
// 逐步将角度零点从原始值调整到-15(向后倒)
|
||||
angle_zeropoint = original_angle_zeropoint - (sit_counter * (original_angle_zeropoint + 15) / 100);
|
||||
|
||||
// 同时逐步降低腿部高度
|
||||
int target_height = 60 - (sit_counter * 60 / 100); // 从60降到0
|
||||
|
||||
// 计算舵机位置
|
||||
Position[0] = 2048 + 12 + 8.4 * (target_height - LEG_HEIGHT_BASE);
|
||||
Position[1] = 2048 - 12 - 8.4 * (target_height - LEG_HEIGHT_BASE);
|
||||
|
||||
// 限制舵机位置范围
|
||||
if (Position[0] < SERVO1_MIN) Position[0] = SERVO1_MIN;
|
||||
if (Position[0] > SERVO1_MAX) Position[0] = SERVO1_MAX;
|
||||
if (Position[1] > SERVO2_MIN) Position[1] = SERVO2_MIN;
|
||||
if (Position[1] < SERVO2_MAX) Position[1] = SERVO2_MAX;
|
||||
|
||||
// 设置舵机速度较慢,确保平稳坐下
|
||||
// 先给个向后退脉冲
|
||||
if (sit_counter < 30) {
|
||||
// 设置电机目标为正,使小车向后运动
|
||||
motor1.target = -1.0; // 2V电压,向后转(轮子向前转,小车向后运动)
|
||||
motor2.target = -1.0;
|
||||
} else {
|
||||
// 阶段2:停止电机,让小车自然向后倒
|
||||
motor1.target = 0;
|
||||
motor2.target = 0;
|
||||
}
|
||||
motor1.loopFOC();
|
||||
motor2.loopFOC();
|
||||
motor1.move();
|
||||
motor2.move();
|
||||
|
||||
// 当sit_counter为0时,设置舵机到最低位置
|
||||
if (sit_counter == 0) {
|
||||
Position[0] = SERVO1_MIN;
|
||||
Position[1] = SERVO2_MIN;
|
||||
Speed[0] = 100;
|
||||
Speed[1] = 100;
|
||||
ACC[0] = 5;
|
||||
ACC[1] = 5;
|
||||
|
||||
sms_sts.SyncWritePosEx(ID, 2, Position, Speed, ACC);
|
||||
}
|
||||
|
||||
if (sit_counter < 100) { // 分100步完成坐下动作
|
||||
// 逐步将平衡零点变成负数,小车抬头(向后倒)
|
||||
angle_zeropoint -- ;
|
||||
} else {
|
||||
// 坐下动作完成,设置到最低位置和最终角度零点
|
||||
sit_counter = 0;
|
||||
sitting_down = false;
|
||||
angle_zeropoint = -15; // 最终的角度零点,确保小车向后倒
|
||||
Position[0] = SERVO1_MIN;
|
||||
Position[1] = SERVO2_MIN;
|
||||
sms_sts.SyncWritePosEx(ID, 2, Position, Speed, ACC);
|
||||
angle_zeropoint = -20; // 最终的角度零点,确保小车向后倒
|
||||
}
|
||||
} else {
|
||||
// 已经坐下,保持最低位置和向后倒的角度零点
|
||||
angle_zeropoint = -15; // 保持向后倒的角度零点
|
||||
Position[0] = SERVO1_MIN;
|
||||
Position[1] = SERVO2_MIN;
|
||||
sms_sts.SyncWritePosEx(ID, 2, Position, Speed, ACC);
|
||||
}
|
||||
|
||||
return; // 跳过其他控制
|
||||
@@ -460,7 +452,7 @@ void loop()
|
||||
= pid_speed( (-0.5) * (motor1.shaft_velocity + motor2.shaft_velocity) - 0.1 * lpf_joyy(wrobot.joyy))
|
||||
//LQR_u与实际shaft_velocity速度正相关
|
||||
*/
|
||||
motor1.target = (-0.5) * (LQR_u + YAW_output); // 负数小车向前,正数小车向后,取
|
||||
motor1.target = (-0.5) * (LQR_u + YAW_output); // 负数小车向前,正数小车向后,取负号是因为电机是反的
|
||||
motor2.target = (-0.5) * (LQR_u - YAW_output);
|
||||
|
||||
// 查看角度信息, 屁股向后倒 -33~-34度,舵机2048的时候-42度,头向前到底 75度,完全垂直88度
|
||||
|
||||
Reference in new issue
Block a user