user_motor.h
3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef __USER_MOTOR_H
#define __USER_MOTOR_H
#include "bsp.h"
/*四个驱动轮设置和返回ID编号*/
typedef struct
{
int *setFlagOffset;//需要置位的标志位的地址
u8 *compareBuffer; //需要比较的buffer
u8 compareNum; //需要比较的长度
u8 noResponseNum; //没有响应次数
int enable; //已经使能则为 1 没有使能则为0
int enableDelay; //开使能后延迟启动,以防止抱闸未来得及开启。
int realEnable; //在有返回速度的时候才会置位1 代表真正使能上了
int motorState; //错误状态
int currentMode; //当前模式
int tarFlag; //需要将enable或者currentMode标志位置为1则填写1
u16 driverID; //驱动器ID
int driverDir; //驱动器反向
int canSelect; //can口选择
u8 driverBrand; //驱动器品牌
int setSpeed; //驱动器已经更新的速度
int responseValue; //应答标志位
float lastSpeed; //上次发送的速度
u8 initStep; //是否初始化完成
u8 initSubStep; //初始化延迟
u8 sendStep;
u8 readAmpereCount;//读电流计数
u8 sendHeartBeatCount;//发送频率记录
u8 readStateCount;
u8 dir; //兴颂驱动器 运行方向
u8 sendBuffer[8]; //兴颂驱动器 发送
u8 slaveID; //兴颂驱动器 从站地址
float sendSpeedCoefficient; //发送速度系数
float getSpeedCoefficient; //获取速度系数
float sendPosCoefficient; //发送位置系数
double getPoseCoefficient; //获取位置系数
}DriverPrivateInfo;
typedef struct
{
int encoderValue; //编码值
float encoderSpeed; //当前速度
int encoderPose; //当前编码器位置
short torque; //当前扭矩
float ampere; //当前驱动器真实电流
float voltage; //电压
u8 errorState; //错误状态
}DriverPublicInfo;
typedef struct
{
float pose; //目标位置或角度
float speed; //目标速度
float speedSlope;//设置加速度
u8 mode; //速度模式/位置模式
int clrPos; //清位置
}DriverCommandInfo;
typedef struct
{
u32 *driverShareErrorInfo;//由于结构体不能定义static 变量 此变量为所有驱动器可读写的变量 代表有驱动出现错误
DriverCommandInfo Command;//给电机发指令
DriverPrivateInfo Private;//电机模块内部数据,用户不需要读写
DriverPublicInfo Public;//电机反馈的数据
}DriverStruct;
extern DriverStruct DriverMotor1;//行走电机1
extern DriverStruct DriverMotor2;//行走电机2
extern DriverStruct DriverMotor3;//行走电机3
extern DriverStruct DriverMotor4;//行走电机4
extern DriverStruct DriverSteering1;//舵机 单转向或行走加转向
extern DriverStruct DriverSteering2;
extern DriverStruct DriverSteering3;
extern DriverStruct DriverSteering4;
extern DriverStruct DriverLifter1;//举升电机
extern DriverStruct DriverLifter2;
extern DriverStruct DriverLifter3;
extern DriverStruct DriverLifter4;
extern DriverStruct DriverShifter1;//移轴电机
extern DriverStruct DriverShifter2;
extern DriverStruct DriverShifter3;
extern DriverStruct DriverPusher1;//推杆电机
extern DriverStruct DriverPusher2;
extern DriverStruct DriverPusher3;
extern bool allDriverEnable;//所有驱动在速度为0时候不关使能
extern void initDriverParam(void);
extern void init_driver(DriverStruct *Motor);
extern void set_speed_model(DriverStruct *Motor);
extern void set_pos_model(DriverStruct *Motor);
extern u8 set_speed(DriverStruct *Motor);
extern u8 set_steering_speed(DriverStruct *Motor,DriverStruct *refMotor);
extern void get_actual_speed(DriverStruct *Motor);
extern void get_actual_pos(DriverStruct *Motor);
extern void get_driver_state(DriverStruct *Motor);
extern void get_driver_ampere(DriverStruct *Motor);
extern void clr_actual_pos(DriverStruct *Motor);
extern void send_heartbeat(DriverStruct *Motor);
extern void DriverDataProcess(DriverStruct *Motor,CanRxMsg *CanRxMsg);
extern void hins_driver_proc(DriverStruct *Motor);
extern void curtis_driver_proc(DriverStruct *Motor);
extern void get_driver_state(DriverStruct *Motor);
extern void DriverState(DriverStruct *Motor,float speedThreshold);
#endif