Skip to content

Commit b79fe60

Browse files
committed
2 parents 2f63934 + f1d1048 commit b79fe60

7 files changed

Lines changed: 423 additions & 31 deletions

File tree

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
"usbd_cdc.h": "c",
77
"usbd_conf.h": "c",
88
"usbd_desc.h": "c",
9-
"usbd_cdc_if.h": "c"
9+
"usbd_cdc_if.h": "c",
10+
"chassis.h": "c",
11+
"remote_control.h": "c",
12+
"arm_math.h": "c",
13+
"can_comm.h": "c",
14+
"dji_motor.h": "c",
15+
"bsp_log.h": "c"
1016
}
1117
}

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ modules/motor/DMmotor/dmmotor.c \
139139
modules/motor/step_motor/step_motor.c \
140140
modules/motor/servo_motor/servo_motor.c \
141141
modules/motor/motor_task.c \
142+
modules/motor/power_control.c \
142143
modules/oled/oled.c \
143144
modules/referee/crc_ref.c \
144145
modules/referee/rm_referee.c \

application/chassis/chassis.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "chassis.h"
1515
#include "robot_def.h"
16-
#include "dji_motor.h"
16+
#include "power_control.h"
1717
#include "super_cap.h"
1818
#include "message_center.h"
1919
#include "referee_task.h"
@@ -42,7 +42,8 @@ static Subscriber_t *chassis_sub; // 用于订阅底盘的控
4242
static Chassis_Ctrl_Cmd_s chassis_cmd_recv; // 底盘接收到的控制命令
4343
static Chassis_Upload_Data_s chassis_feedback_data; // 底盘回传的反馈数据
4444

45-
static referee_info_t* referee_data; // 用于获取裁判系统的数据
45+
static PIDInstance buffer_PID; // 用于底盘的缓冲能量PID
46+
static referee_info_t *referee_data; // 用于获取裁判系统的数据
4647
static Referee_Interactive_info_t ui_data; // UI数据,将底盘中的数据传入此结构体的对应变量中,UI会自动检测是否变化,对应显示UI
4748

4849
static SuperCapInstance *cap; // 超级电容
@@ -52,8 +53,8 @@ static DJIMotorInstance *motor_lf, *motor_rf, *motor_lb, *motor_rb; // left righ
5253
// static float t;
5354

5455
/* 私有函数计算的中介变量,设为静态避免参数传递的开销 */
55-
static float chassis_vx, chassis_vy; // 将云台系的速度投影到底盘
56-
static float vt_lf, vt_rf, vt_lb, vt_rb; // 底盘速度解算后的临时输出,待进行限幅
56+
static float chassis_vx, chassis_vy; // 将云台系的速度投影到底盘
57+
static float vt_lf, vt_rf, vt_lb, vt_rb; // 底盘速度解算后的临时输出,待进行限幅
5758

5859
void ChassisInit()
5960
{
@@ -62,49 +63,53 @@ void ChassisInit()
6263
.can_init_config.can_handle = &hcan1,
6364
.controller_param_init_config = {
6465
.speed_PID = {
65-
.Kp = 10, // 4.5
66-
.Ki = 0, // 0
67-
.Kd = 0, // 0
68-
.IntegralLimit = 3000,
69-
.Improve = PID_Trapezoid_Intergral | PID_Integral_Limit | PID_Derivative_On_Measurement,
70-
.MaxOut = 12000,
71-
},
72-
.current_PID = {
73-
.Kp = 0.5, // 0.4
66+
.Kp = 4.5, // 4.5
7467
.Ki = 0, // 0
75-
.Kd = 0,
68+
.Kd = 0, // 0
7669
.IntegralLimit = 3000,
7770
.Improve = PID_Trapezoid_Intergral | PID_Integral_Limit | PID_Derivative_On_Measurement,
7871
.MaxOut = 15000,
72+
.Output_LPF_RC = 0.3,
7973
},
8074
},
8175
.controller_setting_init_config = {
8276
.angle_feedback_source = MOTOR_FEED,
8377
.speed_feedback_source = MOTOR_FEED,
84-
.outer_loop_type = SPEED_LOOP,
85-
.close_loop_type = SPEED_LOOP | CURRENT_LOOP,
78+
.outer_loop_type = SPEED_LOOP, // 设置为开环,电机设定值由下面的功率控制设定,不走普通的pid
79+
.close_loop_type = SPEED_LOOP,
8680
},
8781
.motor_type = M3508,
8882
};
8983
// @todo: 当前还没有设置电机的正反转,仍然需要手动添加reference的正负号,需要电机module的支持,待修改.
84+
//使用功率控制的电机需要使用PowerControlInit()函数初始化,因为电机的控制方式不同
9085
chassis_motor_config.can_init_config.tx_id = 1;
91-
chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_REVERSE;
92-
motor_lf = DJIMotorInit(&chassis_motor_config);
86+
chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_NORMAL;
87+
motor_lf = PowerControlInit(&chassis_motor_config);
9388

9489
chassis_motor_config.can_init_config.tx_id = 2;
95-
chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_REVERSE;
96-
motor_rf = DJIMotorInit(&chassis_motor_config);
90+
chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_NORMAL;
91+
motor_rf = PowerControlInit(&chassis_motor_config);
9792

9893
chassis_motor_config.can_init_config.tx_id = 4;
99-
chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_REVERSE;
100-
motor_lb = DJIMotorInit(&chassis_motor_config);
94+
chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_NORMAL;
95+
motor_lb = PowerControlInit(&chassis_motor_config);
10196

10297
chassis_motor_config.can_init_config.tx_id = 3;
103-
chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_REVERSE;
104-
motor_rb = DJIMotorInit(&chassis_motor_config);
98+
chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_NORMAL;
99+
motor_rb = PowerControlInit(&chassis_motor_config);
105100

106-
referee_data = UITaskInit(&huart6,&ui_data); // 裁判系统初始化,会同时初始化UI
101+
referee_data = UITaskInit(&huart6, &ui_data); // 裁判系统初始化,会同时初始化UI
107102

103+
/* Buffer环暂未测试,逻辑是计算期望buffer与实际buffer的差值,转换为冗余的功率,todo:输入给功率控制部分,待完善 */
104+
PID_Init_Config_s Buffer_pid_conf = {
105+
.Kp = 0.1,
106+
.Ki = 0,
107+
.Kd = 0,
108+
.IntegralLimit = 1000,
109+
.Improve = PID_Trapezoid_Intergral | PID_Integral_Limit | PID_Derivative_On_Measurement,
110+
.MaxOut = 1000,
111+
};
112+
PIDInit(&buffer_PID, &Buffer_pid_conf); // 缓冲能量PID初始化
108113
SuperCap_Init_Config_s cap_conf = {
109114
.can_config = {
110115
.can_handle = &hcan2,
@@ -192,6 +197,7 @@ void ChassisTask()
192197
chassis_cmd_recv = *(Chassis_Ctrl_Cmd_s *)CANCommGet(chasiss_can_comm);
193198
#endif // CHASSIS_BOARD
194199

200+
SetPowerLimit(referee_data->GameRobotState.chassis_power_limit);//设置功率限制
195201
if (chassis_cmd_recv.chassis_mode == CHASSIS_ZERO_FORCE)
196202
{ // 如果出现重要模块离线或遥控器设置为急停,让电机停止
197203
DJIMotorStop(motor_lf);

application/robot.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ void RobotInit()
3131

3232
#if defined(ONE_BOARD) || defined(GIMBAL_BOARD)
3333
RobotCMDInit();
34-
GimbalInit();
35-
ShootInit();
34+
// GimbalInit();
35+
// ShootInit();
3636
#endif
3737

3838
#if defined(ONE_BOARD) || defined(CHASSIS_BOARD)
@@ -49,8 +49,8 @@ void RobotTask()
4949
{
5050
#if defined(ONE_BOARD) || defined(GIMBAL_BOARD)
5151
RobotCMDTask();
52-
GimbalTask();
53-
ShootTask();
52+
// GimbalTask();
53+
// ShootTask();
5454
#endif
5555

5656
#if defined(ONE_BOARD) || defined(CHASSIS_BOARD)

modules/motor/motor_task.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
#include "dji_motor.h"
55
#include "step_motor.h"
66
#include "servo_motor.h"
7+
#include "power_control.h"
78

89
void MotorControlTask()
910
{
1011
// static uint8_t cnt = 0; 设定不同电机的任务频率
1112
// if(cnt%5==0) //200hz
1213
// if(cnt%10==0) //100hz
1314
DJIMotorControl();
14-
15+
PowerControl();
1516
/* 如果有对应的电机则取消注释,可以加入条件编译或者register对应的idx判断是否注册了电机 */
1617
LKMotorControl();
1718

0 commit comments

Comments
 (0)