Compare commits

..

2 Commits

Author SHA1 Message Date
ws
f50817a218 DJI解析 2025-03-15 16:42:56 +08:00
ws
83a9c93e16 离合初试 2025-03-14 23:57:48 +08:00
9 changed files with 89 additions and 53 deletions

View File

@ -17,6 +17,8 @@
"shoot.h": "c", "shoot.h": "c",
"dji.h": "c", "dji.h": "c",
"calc_lib.h": "c", "calc_lib.h": "c",
"odrive_shoot.h": "c" "odrive_shoot.h": "c",
"remote_control.h": "c",
"dji_task.h": "c"
} }
} }

View File

@ -1,10 +1,3 @@
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin' Load "mycode1\\mycode1.axf"
Build target 'mycode1' Erase Done.Programming Done.Verify OK.Application running ...
compiling read_spi.c... Flash Load finished at 22:03:22
compiling odrive_shoot.c...
compiling shoot_task.c...
linking...
Program Size: Code=26528 RO-data=1904 RW-data=280 ZI-data=22496
FromELF: creating hex file...
"mycode1\mycode1.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:03

View File

@ -1 +1 @@
2025/3/14 20:41:26 2025/3/14 22:03:23

View File

@ -208,37 +208,27 @@
<Ww> <Ww>
<count>11</count> <count>11</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>angleo,0x0A</ItemText> <ItemText>encoder,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>12</count> <count>12</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>shoot</ItemText> <ItemText>mode,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>13</count> <count>13</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>multi_turn_angle,0x0A</ItemText> <ItemText>m</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>14</count> <count>14</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>angle_encoder</ItemText> <ItemText>trigger_motor_data,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>15</count> <count>15</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>back_angle,0x0A</ItemText> <ItemText>trigger_angle_o</ItemText>
</Ww>
<Ww>
<count>16</count>
<WinNumber>1</WinNumber>
<ItemText>encoder,0x0A</ItemText>
</Ww>
<Ww>
<count>17</count>
<WinNumber>1</WinNumber>
<ItemText>angles</ItemText>
</Ww> </Ww>
</WatchWindow1> </WatchWindow1>
<WatchWindow2> <WatchWindow2>
@ -322,7 +312,7 @@
<Group> <Group>
<GroupName>Application/User/Core</GroupName> <GroupName>Application/User/Core</GroupName>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>

View File

@ -37,7 +37,7 @@
(ptr)->temperate = (data)[6]; \ (ptr)->temperate = (data)[6]; \
(ptr)->ecd - (ptr)->last_ecd > 4096 ? ((ptr)->round_cnt--) : ((ptr)->round_cnt=(ptr)->round_cnt); \ (ptr)->ecd - (ptr)->last_ecd > 4096 ? ((ptr)->round_cnt--) : ((ptr)->round_cnt=(ptr)->round_cnt); \
(ptr)->ecd - (ptr)->last_ecd < -4096 ? ((ptr)->round_cnt++) : ((ptr)->round_cnt=(ptr)->round_cnt); \ (ptr)->ecd - (ptr)->last_ecd < -4096 ? ((ptr)->round_cnt++) : ((ptr)->round_cnt=(ptr)->round_cnt); \
(ptr)->total_angle = (fp64)((ptr)->round_cnt * 8192 + (ptr)->ecd - (ptr)->offset_ecd ) * MOTOR_ECD_TO_ANGLE; \ (ptr)->total_angle = (fp64)((ptr)->round_cnt * 8192 + (ptr)->ecd - (ptr)->offset_ecd ) * MOTOR_ECD_TO_ANGLE_3508; \
}//ptr指向电机测量数据结构体的指针data包含电机测量数据的数组. }//ptr指向电机测量数据结构体的指针data包含电机测量数据的数组.
/*(ptr)->real_angle = (ptr)->real_angle % 360; */ /*(ptr)->real_angle = (ptr)->real_angle % 360; */
#define get_motor_offset(ptr, data) \ #define get_motor_offset(ptr, data) \
@ -55,6 +55,17 @@
(ptr)->ecd - (ptr)->last_ecd > 4096 ? ((ptr)->round_cnt--) : ((ptr)->round_cnt=(ptr)->round_cnt); \ (ptr)->ecd - (ptr)->last_ecd > 4096 ? ((ptr)->round_cnt--) : ((ptr)->round_cnt=(ptr)->round_cnt); \
(ptr)->ecd - (ptr)->last_ecd < -4096 ? ((ptr)->round_cnt++) : ((ptr)->round_cnt=(ptr)->round_cnt); \ (ptr)->ecd - (ptr)->last_ecd < -4096 ? ((ptr)->round_cnt++) : ((ptr)->round_cnt=(ptr)->round_cnt); \
(ptr)->total_angle = (fp64)((ptr)->round_cnt * 8192 + (ptr)->ecd - (ptr)->offset_ecd ) * MOTOR_ECD_TO_ANGLE_6020; \ (ptr)->total_angle = (fp64)((ptr)->round_cnt * 8192 + (ptr)->ecd - (ptr)->offset_ecd ) * MOTOR_ECD_TO_ANGLE_6020; \
}
#define get_2006_motor_measure(ptr, data) \
{ \
(ptr)->last_ecd = (ptr)->ecd; \
(ptr)->ecd = (uint16_t)((data)[0] << 8 | (data)[1]); \
(ptr)->speed_rpm = (uint16_t)((data)[2] << 8 | (data)[3]); \
(ptr)->given_current = (uint16_t)((data)[4] << 8 | (data)[5]); \
(ptr)->temperate = (data)[6]; \
(ptr)->ecd - (ptr)->last_ecd > 4096 ? ((ptr)->round_cnt--) : ((ptr)->round_cnt=(ptr)->round_cnt); \
(ptr)->ecd - (ptr)->last_ecd < -4096 ? ((ptr)->round_cnt++) : ((ptr)->round_cnt=(ptr)->round_cnt); \
(ptr)->total_angle = (fp64)((ptr)->round_cnt * 8192 + (ptr)->ecd - (ptr)->offset_ecd ) * MOTOR_ECD_TO_ANGLE_2006; \
} }
// 解析出初始编码器值 // 解析出初始编码器值
// #define get_5065motor_measure(ptr, data) \ // #define get_5065motor_measure(ptr, data) \
@ -132,7 +143,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
} }
#else #else
static osEventFlagsId_t eventReceive; static osEventFlagsId_t eventReceive;//事件标志
/** /**
* @brief * @brief
* @param[in] none * @param[in] none

View File

@ -47,7 +47,8 @@ typedef struct
//motor calc ecd to angle //motor calc ecd to angle
#define MOTOR_ECD_TO_ANGLE (360.0 / 8191.0 / (3591.0/187.0)) #define MOTOR_ECD_TO_ANGLE_3508 (360.0 / 8191.0 / (3591.0/187.0))
#define MOTOR_ECD_TO_ANGLE_2006 (360.0 / 8191.0 / 36)
#define MOTOR_ECD_TO_RAD 0.000766990394f #define MOTOR_ECD_TO_RAD 0.000766990394f
#define MOTOR_ECD_TO_ANGLE_6020 (360.0 / 8191.0 ) #define MOTOR_ECD_TO_ANGLE_6020 (360.0 / 8191.0 )

View File

@ -5,22 +5,26 @@
#include <cmsis_os2.h> #include <cmsis_os2.h>
#include "remote_control.h" #include "remote_control.h"
#include "dji.h" #include "dji.h"
#include "read_spi.h"
#include "vofa.h" #include "vofa.h"
extern RC_mess_t RC_mess; extern RC_mess_t RC_mess;
extern int16_t result; extern int16_t result;
extern int16_t t_result; extern int16_t t_result;
extern motor_measure_t *motor_3508_data; extern motor_measure_t *trigger_motor_data;
Encoder_t encoder;
float vofa[8]; float vofa[8];
int speed=0;
float m=0;
float trigger_angle_o=0;
int mode=0;
/** /**
* \brief * \brief
* *
* \param argument 使 * \param argument 使
*/ */
int speed=0;
float angle=0;
float m;
void Task_Motor(void *argument) void Task_Motor(void *argument)
{ {
(void)argument; /* 未使用argument消除警告 */ (void)argument; /* 未使用argument消除警告 */
@ -28,6 +32,7 @@ void Task_Motor(void *argument)
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CTRL_CHASSIS; const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CTRL_CHASSIS;
motor_init(); motor_init();
Encoder_Init(&encoder);
uint32_t tick = osKernelGetTickCount(); uint32_t tick = osKernelGetTickCount();
@ -35,12 +40,28 @@ void Task_Motor(void *argument)
{ {
//收到消息队列新数据 //收到消息队列新数据
//电机控制 // 更新编码器数据
//motor_speed(speed); Update_Encoder(&encoder);
m=angle*(8191/360); m=trigger_angle_o*(8191/360);
// motor_pos(m); if( mode == THREE )
{
//当最高点时进入离合
if(encoder.round_cnt>=8)
{
trigger_angle_o=2;
trigger_pos(m); trigger_pos(m);
//CAN_cmd_200(result[MOTOR_UP],result[MOTOR_UP],result[MOTOR_UP],result[MOTOR_UP],&hcan1); }
}
else if( mode == DZ )
{
//退出离合
trigger_angle_o=0;
trigger_pos(m);
}
CAN_cmd_200(t_result,0,0,0,&hcan1); CAN_cmd_200(t_result,0,0,0,&hcan1);
osDelay(2); osDelay(2);

View File

@ -2,4 +2,7 @@
#define _DJI_TASK_H_ #define _DJI_TASK_H_
#define THREE 3
#define DZ 0
#endif #endif

View File

@ -7,20 +7,27 @@
#include "shoot.h" #include "shoot.h"
#include "odrive_shoot.h" #include "odrive_shoot.h"
#include "read_spi.h" #include "read_spi.h"
#include "dji_task.h"
extern RC_mess_t RC_mess; extern RC_mess_t RC_mess;
Encoder_t encoder; extern Encoder_t encoder;
double angles; extern motor_measure_t *trigger_motor_data;//3508电机数据
int32_t rounds; extern int mode;
int angleo = 0; //发射角度
#define GO1_SHOOT 0 #define GO1_SHOOT 0
#define ODRIVE_SHOOT 1 #define ODRIVE_SHOOT 1
//odrive发射
#define SHOOT3 12
#define TOP 6
#define MIDDLE 3
#define BOTTOM 0
void Task_Shoot(void *argument) void Task_Shoot(void *argument)
{ {
(void)argument; /* 未使用argument消除警告 */ (void)argument; /* 未使用argument消除警告 */
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN; const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN;
Encoder_Init(&encoder);
#if GO1_SHOOT == 1 #if GO1_SHOOT == 1
shooterInit(); shooterInit();
#endif #endif
@ -34,12 +41,20 @@ void Task_Shoot(void *argument)
shoot_ball(0); shoot_ball(0);
#elif ODRIVE_SHOOT == 1 #elif ODRIVE_SHOOT == 1
shootStep(); if(mode == THREE)
//shoot_odrive(angleo); {
#endif shoot_odrive(SHOOT3);
// 更新编码器数据 }
Update_Encoder(&encoder); else if(mode == DZ)
{
if(trigger_motor_data->total_angle ==0)//扳机已闭合
{
shoot_odrive(BOTTOM);
}
}
#endif
tick += delay_tick; /* 计算下一个唤醒时刻 */ tick += delay_tick; /* 计算下一个唤醒时刻 */
osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */ osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */
} }