feat: add 0xA9 feedforward frame and wire feedforward controller to motor output
- host 0xA9 frame → master_machine decode → robot_cmd publish via gimbal_feedforward topic → gimbal subscribe → yaw_motor.feed_input - add DM_Feedforward_Controller_s with Kp and feed_input fields - add feedforward term (Kp * feed_input) to motor control output - add DM_Feedforward_Kp to motor init config
This commit is contained in:
@@ -11,6 +11,7 @@ static Publisher_t *gimbal_pub;
|
||||
static Subscriber_t *gimbal_sub;
|
||||
static Subscriber_t *motor_enable_sub;
|
||||
static Subscriber_t *motor_pid_sub;
|
||||
static Subscriber_t *feedforward_sub;
|
||||
static Gimbal_Upload_Data_s gimbal_feedback_data;
|
||||
static Gimbal_Ctrl_Cmd_s gimbal_cmd_recv;
|
||||
|
||||
@@ -25,6 +26,7 @@ void GimbalInit()
|
||||
gimbal_sub = SubRegister("gimbal_cmd", sizeof(Gimbal_Ctrl_Cmd_s));
|
||||
motor_enable_sub = SubRegister("motor_enable", sizeof(Motor_Enable_s));
|
||||
motor_pid_sub = SubRegister("motor_pid", sizeof(Motor_PID_Tune_s));
|
||||
feedforward_sub = SubRegister("gimbal_feedforward", sizeof(Gimbal_Feedforward_s));
|
||||
|
||||
/* ---- Yaw: DM-G6220, CAN1, TX=0x01, RX=0xF1, Velocity模式 ---- */
|
||||
DM_Motor_Init_Config_s yaw_config = {
|
||||
@@ -50,6 +52,7 @@ void GimbalInit()
|
||||
.motor_type = DM_MOTOR,
|
||||
},
|
||||
.ctrl_mode = DM_MODE_VELOCITY,
|
||||
.DM_Feedforward_Kp = 0.9f,
|
||||
.mit_kp = 0, .mit_kd = 0,
|
||||
};
|
||||
yaw_motor = DMMotorInit(&yaw_config);
|
||||
@@ -87,10 +90,19 @@ void GimbalInit()
|
||||
|
||||
void GimbalTask()
|
||||
{
|
||||
SubGetMessage(gimbal_sub, &gimbal_cmd_recv);
|
||||
|
||||
DMMotorSetRef(yaw_motor, gimbal_cmd_recv.yaw);
|
||||
DMMotorSetRef(pitch_motor, gimbal_cmd_recv.pitch);
|
||||
/* 角度环参考值设定 */
|
||||
if(SubGetMessage(gimbal_sub, &gimbal_cmd_recv))
|
||||
{
|
||||
DMMotorSetRef(yaw_motor, gimbal_cmd_recv.yaw);
|
||||
DMMotorSetRef(pitch_motor, gimbal_cmd_recv.pitch);
|
||||
}
|
||||
|
||||
/* 前馈输入 */
|
||||
static Gimbal_Feedforward_s feedforward_msg;
|
||||
if (SubGetMessage(feedforward_sub, &feedforward_msg))
|
||||
{
|
||||
yaw_motor->feedforward_controller.feed_input = feedforward_msg.feedforward;
|
||||
}
|
||||
|
||||
/* 电机使能/失能控制 */
|
||||
static Motor_Enable_s enable_msg;
|
||||
|
||||
Reference in New Issue
Block a user