mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
add motor
This commit is contained in:
@@ -9,11 +9,11 @@ static void DecodeDJIMotor(can_instance* _instance)
|
||||
{
|
||||
if(dji_motor_info[i]->motor_can_instance==_instance)
|
||||
{
|
||||
dji_motor_info[i]->last_ecd = dji_motor_info[i]->ecd;
|
||||
dji_motor_info[i]->ecd = (uint16_t)(_instance->rx_buff[0] << 8 | _instance->rx_buff[1]);
|
||||
dji_motor_info[i]->speed_rpm = (uint16_t)(_instance->rx_buff[2] << 8 | _instance->rx_buff[3]);
|
||||
dji_motor_info[i]->given_current = (uint16_t)(_instance->rx_buff[4] << 8 | _instance->rx_buff[5]);
|
||||
dji_motor_info[i]->temperate = _instance->rx_buff[6];
|
||||
dji_motor_info[i]->motor_measure.last_ecd = dji_motor_info[i]->motor_measure.ecd;
|
||||
dji_motor_info[i]->motor_measure.ecd = (uint16_t)(_instance->rx_buff[0] << 8 | _instance->rx_buff[1]);
|
||||
dji_motor_info[i]->motor_measure.speed_rpm = (uint16_t)(_instance->rx_buff[2] << 8 | _instance->rx_buff[3]);
|
||||
dji_motor_info[i]->motor_measure.given_current = (uint16_t)(_instance->rx_buff[4] << 8 | _instance->rx_buff[5]);
|
||||
dji_motor_info[i]->motor_measure.temperate = _instance->rx_buff[6];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,9 @@ dji_motor_instance* DJIMotorInit(CAN_HandleTypeDef* _hcan,uint16_t tx_id,uint16_
|
||||
dji_motor_info[idx++]->motor_can_instance=CANRegister(tx_id,rx_id,_hcan,DecodeDJIMotor);
|
||||
}
|
||||
|
||||
void DJIMotorSetRef();
|
||||
|
||||
|
||||
void DJIMotorControl()
|
||||
{
|
||||
|
||||
|
||||
@@ -5,25 +5,46 @@
|
||||
|
||||
#include "bsp_can.h"
|
||||
#include "controller.h"
|
||||
#include "motor_def.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t ecd;
|
||||
int16_t speed_rpm;
|
||||
int16_t given_current;
|
||||
uint8_t temperate;
|
||||
int16_t last_ecd;
|
||||
struct
|
||||
{
|
||||
uint16_t ecd;
|
||||
uint16_t last_ecd;
|
||||
int16_t speed_rpm;
|
||||
int16_t given_current;
|
||||
uint8_t temperate;
|
||||
int16_t total_round;
|
||||
int32_t total_angle;
|
||||
} motor_measure;
|
||||
|
||||
struct
|
||||
{
|
||||
closeloop_e close_loop_type;
|
||||
reverse_flag_e reverse_flag;
|
||||
feedback_source_e angle_feedback_source;
|
||||
feedback_source_e speed_feedback_source;
|
||||
} controll_state;
|
||||
|
||||
float* other_angle_feedback_ptr;
|
||||
float* other_speed_feedback_ptr;
|
||||
|
||||
PID_t* current_PID;
|
||||
PID_t* speed_PID;
|
||||
PID_t* angle_PID;
|
||||
|
||||
PID_t motor_pid;
|
||||
can_instance *motor_can_instance;
|
||||
|
||||
} dji_motor_instance;
|
||||
|
||||
dji_motor_instance* DJIMotorInit(CAN_HandleTypeDef* _hcan,uint16_t tx_id,uint16_t rx_id);
|
||||
|
||||
void DJIMotorSetRef();
|
||||
|
||||
void DJIMotorControl();
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // !DJI_MOTOR_H
|
||||
#endif // !DJI_MOTOR_H
|
||||
|
||||
26
modules/motor/motor_def.h
Normal file
26
modules/motor/motor_def.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef MOTOR_DEF_H
|
||||
#define MOTOR_DEF_H
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CURRENT=0,
|
||||
SPEED=1,
|
||||
ANGLE=2
|
||||
} closeloop_e;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MOTOR=0,
|
||||
OTHER=1
|
||||
} feedback_source_e;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CLOCKWISE=0,
|
||||
COUNTER_CLOCKWISE=1
|
||||
} reverse_flag_e;
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // !MOTOR_DEF_H
|
||||
@@ -10,20 +10,21 @@ void RegisterMotor(Motor_Type_e motor_type,void* motor_instance)
|
||||
static uint8_t dji_idx,joint_idx,driven_idx;
|
||||
switch (motor_type)
|
||||
{
|
||||
case GM6020:
|
||||
case M3508:
|
||||
case M2006:
|
||||
dji_motor_info[dji_idx++]=(dji_motor_instance*)motor_instance;
|
||||
break;
|
||||
case LK9025:
|
||||
driven_motor_info[driven_idx++]=(driven_instance*)motor_instance;
|
||||
break;
|
||||
case HT04:
|
||||
joint_motor_info[joint_idx++]=(joint_instance*)motor_instance;
|
||||
break;
|
||||
case GM6020:
|
||||
case M3508:
|
||||
case M2006:
|
||||
dji_motor_info[dji_idx++]=(dji_motor_instance*)motor_instance;
|
||||
break;
|
||||
case LK9025:
|
||||
driven_motor_info[driven_idx++]=(driven_instance*)motor_instance;
|
||||
break;
|
||||
case HT04:
|
||||
joint_motor_info[joint_idx++]=(joint_instance*)motor_instance;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MotorControlTask()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user