update some motor defs

This commit is contained in:
NeoZng
2022-10-30 22:19:13 +08:00
parent 5f59ebb916
commit 6441982964
11 changed files with 224 additions and 53 deletions

View File

@@ -36,11 +36,11 @@ static void DecodeJoint(can_instance* motor_instance)
}
}
joint_instance* HTMotorInit(CAN_HandleTypeDef* _hcan,uint8_t tx_id,uint8_t rx_id)
joint_instance* HTMotorInit(can_instance_config config)
{
static uint8_t idx;
joint_motor_info[idx]=(joint_instance*)malloc(sizeof(joint_instance));
joint_motor_info[idx++]->motor_can_instace=CANRegister(tx_id,rx_id,_hcan,DecodeJoint);
joint_motor_info[idx++]->motor_can_instace=CANRegister(config);
}
void JointControl(joint_instance* _instance,float current)

View File

@@ -32,7 +32,7 @@ typedef enum
CMD_ZERO_POSITION = 0xfe
} joint_mode;
joint_instance* HTMotorInit(CAN_HandleTypeDef* _hcan,uint8_t tx_id,uint8_t rx_id);
joint_instance* HTMotorInit(can_instance_config config);
void JointControl(joint_instance* _instance,float current);

View File

@@ -11,6 +11,7 @@
#define LIMIT_MIN_MAX(x,min,max) (x) = (((x)<=(min))?(min):(((x)>=(max))?(max):(x)))
typedef struct //9025
{
uint16_t last_ecd;

View File

@@ -1,7 +1,57 @@
#include "dji_motor.h"
static dji_motor_instance* dji_motor_info[DJI_MOTOR_CNT];
static dji_motor_instance* dji_motor_info[DJI_MOTOR_CNT]={NULL};
// can1: [0]:0x1FF,[1]:0x200,[2]:0x2FF
// can2: [0]:0x1FF,[1]:0x200,[2]:0x2FF
static can_instance sender_assignment[6]=
{
[0]={.can_handle=&hcan1,.txconf.StdId=0x1ff,.txconf.IDE=CAN_ID_STD,.txconf.RTR=CAN_RTR_DATA,.txconf.DLC=0x08,.tx_buff={0}},
[1]={.can_handle=&hcan1,.txconf.StdId=0x200,.txconf.IDE=CAN_ID_STD,.txconf.RTR=CAN_RTR_DATA,.txconf.DLC=0x08,.tx_buff={0}},
[2]={.can_handle=&hcan1,.txconf.StdId=0x2ff,.txconf.IDE=CAN_ID_STD,.txconf.RTR=CAN_RTR_DATA,.txconf.DLC=0x08,.tx_buff={0}},
[3]={.can_handle=&hcan2,.txconf.StdId=0x1ff,.txconf.IDE=CAN_ID_STD,.txconf.RTR=CAN_RTR_DATA,.txconf.DLC=0x08,.tx_buff={0}},
[4]={.can_handle=&hcan2,.txconf.StdId=0x200,.txconf.IDE=CAN_ID_STD,.txconf.RTR=CAN_RTR_DATA,.txconf.DLC=0x08,.tx_buff={0}},
[5]={.can_handle=&hcan2,.txconf.StdId=0x2ff,.txconf.IDE=CAN_ID_STD,.txconf.RTR=CAN_RTR_DATA,.txconf.DLC=0x08,.tx_buff={0}},
};
/**
* @brief
*
* @param idx
*/
static void MotorSenderGrouping(uint8_t idx,can_instance_config config)
{
uint8_t motor_id=config.tx_id;
uint8_t motor_rx_id;
uint8_t motor_send_num;
uint8_t motor_grouping;
switch (dji_motor_info[idx]->motor_type)
{
case M2006:
case M3508:
if(motor_id<5)
{
}
else
{
}
break;
case GM6020:
if(motor_id<5)
{
}
else
{
}
break;
}
}
static void DecodeDJIMotor(can_instance* _instance)
{
@@ -19,17 +69,44 @@ static void DecodeDJIMotor(can_instance* _instance)
}
}
dji_motor_instance* DJIMotorInit(CAN_HandleTypeDef* _hcan,uint16_t tx_id,uint16_t rx_id)
dji_motor_instance* DJIMotorInit(can_instance_config config,
Motor_Controller_s controller_config,
Motor_Control_Setting_s motor_setting,
Motor_Controller_Init_s controller_init,
Motor_Type_e type)
{
static uint8_t idx;
static uint8_t idx; // register idx
dji_motor_info[idx]=(dji_motor_instance*)malloc(sizeof(dji_motor_instance));
dji_motor_info[idx++]->motor_can_instance=CANRegister(tx_id,rx_id,_hcan,DecodeDJIMotor);
// motor setting
dji_motor_info[idx]->motor_type=type;
dji_motor_info[idx]->motor_settings=motor_setting;
// motor controller init @todo : PID init
dji_motor_info[idx]->motor_settings.angle_feedback_source=motor_setting.angle_feedback_source;
dji_motor_info[idx]->motor_settings.speed_feedback_source=motor_setting.speed_feedback_source;
// group motors, because 4 motors share the same CAN control message
MotorSenderGrouping(idx,config);
// register motor to CAN bus
dji_motor_info[idx]->motor_can_instance=CANRegister(config);
return dji_motor_info[idx++];
}
void DJIMotorSetRef();
void DJIMotorSetRef()
{
}
void DJIMotorControl()
{
for (size_t i = 0; i < DJI_MOTOR_CNT; i++)
{
}
}

View File

@@ -7,8 +7,13 @@
#include "controller.h"
#include "motor_def.h"
/**
* @brief DJI intelligent motor typedef
*
*/
typedef struct
{
/* motor measurement recv from CAN feedback */
struct
{
uint16_t ecd;
@@ -20,25 +25,29 @@ typedef struct
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;
/* basic config of a motor*/
Motor_Control_Setting_s motor_settings;
float* other_angle_feedback_ptr;
float* other_speed_feedback_ptr;
PID_t* current_PID;
PID_t* speed_PID;
PID_t* angle_PID;
/* controller used in the motor (3 loops)*/
Motor_Controller_s motor_controller;
/* the CAN instance own by motor instance*/
can_instance *motor_can_instance;
/* sender assigment*/
uint8_t sender_group;
uint8_t message_num;
Motor_Type_e motor_type;
} dji_motor_instance;
dji_motor_instance* DJIMotorInit(CAN_HandleTypeDef* _hcan,uint16_t tx_id,uint16_t rx_id);
dji_motor_instance* DJIMotorInit(can_instance_config config,
Motor_Controller_s controller_config,
Motor_Control_Setting_s motor_setting,
Motor_Controller_Init_s controller_init,
Motor_Type_e type);
void DJIMotorSetRef();

View File

@@ -6,19 +6,65 @@ typedef enum
CURRENT=0,
SPEED=1,
ANGLE=2
} closeloop_e;
} Closeloop_Type_e;
typedef enum
{
MOTOR=0,
OTHER=1
} feedback_source_e;
} Feedback_Source_e;
typedef enum
{
CLOCKWISE=0,
COUNTER_CLOCKWISE=1
} reverse_flag_e;
} Reverse_Flag_e;
typedef struct
{
Closeloop_Type_e close_loop_type;
Reverse_Flag_e reverse_flag;
Feedback_Source_e angle_feedback_source;
Feedback_Source_e speed_feedback_source;
} Motor_Control_Setting_s;
typedef struct
{
float* other_angle_feedback_ptr;
float* other_speed_feedback_ptr;
PID_t* current_PID;
PID_t* speed_PID;
PID_t* angle_PID;
} Motor_Controller_s;
typedef enum
{
GM6020=0,
M3508=1,
M2006=2,
LK9025=3,
HT04=4
} Motor_Type_e;
typedef struct
{
/* data */
} PID_config_s;
typedef struct
{
float* other_angle_feedback_ptr;
float* other_speed_feedback_ptr;
PID_config_s current_PID;
PID_config_s speed_PID;
PID_config_s angle_PID;
} Motor_Controller_Init_s;

View File

@@ -4,15 +4,9 @@
#include "LK9025.h"
#include "HT04.h"
#include "dji_motor.h"
#include "motor_def.h"
typedef enum
{
GM6020=0,
M3508=1,
M2006=2,
LK9025=3,
HT04=4
} Motor_Type_e;
void MotorControlTask();