这个spi读编码器绝对好使
This commit is contained in:
parent
4d94d15052
commit
d56405a1ba
@ -102,7 +102,7 @@ void MX_USART6_UART_Init(void)
|
|||||||
|
|
||||||
/* USER CODE END USART6_Init 1 */
|
/* USER CODE END USART6_Init 1 */
|
||||||
huart6.Instance = USART6;
|
huart6.Instance = USART6;
|
||||||
huart6.Init.BaudRate = 4000000;
|
huart6.Init.BaudRate = 115200;
|
||||||
huart6.Init.WordLength = UART_WORDLENGTH_8B;
|
huart6.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
huart6.Init.StopBits = UART_STOPBITS_1;
|
huart6.Init.StopBits = UART_STOPBITS_1;
|
||||||
huart6.Init.Parity = UART_PARITY_NONE;
|
huart6.Init.Parity = UART_PARITY_NONE;
|
||||||
|
10
MDK-ARM/.vscode/keil-assistant.log
vendored
10
MDK-ARM/.vscode/keil-assistant.log
vendored
@ -48,3 +48,13 @@
|
|||||||
|
|
||||||
[info] Log at : 2025/3/13|14:46:01|GMT+0800
|
[info] Log at : 2025/3/13|14:46:01|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/3/13|19:24:02|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/3/13|21:58:39|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/3/14|16:14:48|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/3/14|16:14:59|GMT+0800
|
||||||
|
|
||||||
|
[info] Log at : 2025/3/14|20:12:19|GMT+0800
|
||||||
|
|
||||||
|
3
MDK-ARM/.vscode/settings.json
vendored
3
MDK-ARM/.vscode/settings.json
vendored
@ -16,6 +16,7 @@
|
|||||||
"ball.h": "c",
|
"ball.h": "c",
|
||||||
"shoot.h": "c",
|
"shoot.h": "c",
|
||||||
"dji.h": "c",
|
"dji.h": "c",
|
||||||
"calc_lib.h": "c"
|
"calc_lib.h": "c",
|
||||||
|
"odrive_shoot.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
13
MDK-ARM/.vscode/uv4.log
vendored
13
MDK-ARM/.vscode/uv4.log
vendored
@ -1,3 +1,10 @@
|
|||||||
Load "mycode1\\mycode1.axf"
|
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin'
|
||||||
Erase Done.Programming Done.Verify OK.Application running ...
|
Build target 'mycode1'
|
||||||
Flash Load finished at 19:18:06
|
compiling read_spi.c...
|
||||||
|
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
|
||||||
|
2
MDK-ARM/.vscode/uv4.log.lock
vendored
2
MDK-ARM/.vscode/uv4.log.lock
vendored
@ -1 +1 @@
|
|||||||
2025/3/13 19:18:07
|
2025/3/14 20:41:26
|
@ -205,6 +205,41 @@
|
|||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>basketball,0x0A</ItemText>
|
<ItemText>basketball,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>11</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>angleo,0x0A</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>12</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>shoot</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>13</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>multi_turn_angle,0x0A</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>14</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>angle_encoder</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>15</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>back_angle,0x0A</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>
|
||||||
</WatchWindow1>
|
</WatchWindow1>
|
||||||
<WatchWindow2>
|
<WatchWindow2>
|
||||||
<Ww>
|
<Ww>
|
||||||
@ -287,7 +322,7 @@
|
|||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>Application/User/Core</GroupName>
|
<GroupName>Application/User/Core</GroupName>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>1</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
@ -1083,7 +1118,7 @@
|
|||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>User/task</GroupName>
|
<GroupName>User/task</GroupName>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>1</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
|
@ -40,41 +40,31 @@ uint16_t AS5047_read(uint16_t add)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void Update_MultiTurn_Angle(void)
|
void Encoder_Init(Encoder_t *ptr) {
|
||||||
// {
|
ptr->round_cnt = 0;
|
||||||
// uint16_t current_angle = AS5047_read(ANGLEUNC);
|
ptr->ecd = AS5047_read(ANGLEUNC);
|
||||||
// int16_t angle_diff = current_angle - last_angle;
|
ptr->last_ecd = ptr->ecd;
|
||||||
|
ptr->offset_ecd = ptr->ecd;
|
||||||
// // 检测角度跳变
|
ptr->total_angle = 0.0;
|
||||||
// if (angle_diff > 8192) // 角度从低到高跳变
|
}
|
||||||
// {
|
|
||||||
// multi_turn_angle -= (16384 - angle_diff);
|
void Update_Encoder(Encoder_t *ptr) {
|
||||||
// }
|
ptr->ecd = AS5047_read(ANGLEUNC);
|
||||||
// else if (angle_diff < -8192) // 角度从高到低跳变
|
|
||||||
// {
|
if (ptr->ecd - ptr->last_ecd > 4096) {
|
||||||
// multi_turn_angle += (16384 + angle_diff);
|
ptr->round_cnt--;
|
||||||
// }
|
} else if (ptr->ecd - ptr->last_ecd < -4096) {
|
||||||
// else
|
ptr->round_cnt++;
|
||||||
// {
|
}
|
||||||
// multi_turn_angle += angle_diff;
|
|
||||||
// }
|
ptr->total_angle = (double)((ptr->round_cnt * 8192 + ptr->ecd - ptr->offset_ecd) );
|
||||||
|
ptr->last_ecd = ptr->ecd;
|
||||||
// last_angle = current_angle;
|
}
|
||||||
// }
|
|
||||||
void Update_MultiTurn_Angle(void)
|
int32_t Get_Encoder_Rounds(Encoder_t *ptr) {
|
||||||
{
|
return ptr->round_cnt;
|
||||||
uint16_t current_angle = AS5047_read(ANGLEUNC);
|
}
|
||||||
int16_t angle_diff = current_angle - last_angle;
|
|
||||||
|
double Get_Encoder_Angle(Encoder_t *ptr) {
|
||||||
// 检测角度跳变
|
return ptr->total_angle;
|
||||||
if (angle_diff > 8192) // 角度从低到高跳变
|
|
||||||
{
|
|
||||||
multi_turn_angle -= 1;
|
|
||||||
}
|
|
||||||
else if (angle_diff < -8192) // 角度从高到低跳变
|
|
||||||
{
|
|
||||||
multi_turn_angle += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_angle = current_angle;
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,14 @@
|
|||||||
#define SETTINGS1 0x0018
|
#define SETTINGS1 0x0018
|
||||||
#define SETTINGS2 0x0019
|
#define SETTINGS2 0x0019
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t round_cnt;
|
||||||
|
uint16_t ecd;
|
||||||
|
uint16_t last_ecd;
|
||||||
|
uint16_t offset_ecd;
|
||||||
|
double total_angle;
|
||||||
|
} Encoder_t;
|
||||||
|
|
||||||
#define AS5407P_CS_H() \
|
#define AS5407P_CS_H() \
|
||||||
HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET)
|
HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET)
|
||||||
#define AS5407P_CS_L() \
|
#define AS5407P_CS_L() \
|
||||||
@ -26,6 +34,11 @@
|
|||||||
uint16_t Parity_bit_Calculate(uint16_t data_2_cal);
|
uint16_t Parity_bit_Calculate(uint16_t data_2_cal);
|
||||||
uint16_t SPI_ReadWrite_OneByte(uint16_t _txdata);
|
uint16_t SPI_ReadWrite_OneByte(uint16_t _txdata);
|
||||||
uint16_t AS5047_read(uint16_t add);
|
uint16_t AS5047_read(uint16_t add);
|
||||||
void Update_MultiTurn_Angle(void);
|
|
||||||
|
|
||||||
|
void Encoder_Init(Encoder_t *ptr);
|
||||||
|
void Update_Encoder(Encoder_t *ptr);
|
||||||
|
int32_t Get_Encoder_Rounds(Encoder_t *ptr);
|
||||||
|
double Get_Encoder_Angle(Encoder_t *ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <cmsis_os2.h>
|
#include <cmsis_os2.h>
|
||||||
#include "read_spi.h"
|
#include "read_spi.h"
|
||||||
|
|
||||||
|
#include "vofa.h"
|
||||||
|
|
||||||
extern RC_mess_t RC_mess;
|
extern RC_mess_t RC_mess;
|
||||||
|
|
||||||
extern float angle_encoder;
|
extern float angle_encoder;
|
||||||
@ -12,31 +14,28 @@ extern volatile uint16_t last_angle ;
|
|||||||
|
|
||||||
#define POS_SET -10.6
|
#define POS_SET -10.6
|
||||||
#define POS_ZERO 2.705
|
#define POS_ZERO 2.705
|
||||||
#define ACCEL_SEND 10//梯形加速度
|
#define ACCEL_SEND 100//梯形加速度
|
||||||
#define ACCEL_BACK 5//返回时的加速度
|
#define ACCEL_BACK 100//返回时的加速度
|
||||||
#define DELAY 1000
|
#define DELAY 1000
|
||||||
|
|
||||||
fp32 shoot = 10;
|
fp32 shoot = 0;
|
||||||
|
fp32 back_angle = 0;
|
||||||
|
float vofa_spi[8];
|
||||||
|
|
||||||
void shootStep(void)
|
void shootStep(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// back_angle=Get_Angle();
|
||||||
angle_encoder=AS5047_read(ANGLEUNC);
|
// angle_encoder=AS5047_read(ANGLEUNC);
|
||||||
Update_MultiTurn_Angle();
|
// Update_MultiTurn_Angle();
|
||||||
|
|
||||||
odrive_accel_cmd(AXIS0_NODE,ACCEL_SEND,ACCEL_SEND);
|
odrive_accel_cmd(AXIS0_NODE,ACCEL_SEND,ACCEL_SEND);
|
||||||
// osDelay(2);//不知道为什么要延时
|
// osDelay(2);//不知道为什么要延时
|
||||||
odrive_pos_cmd(AXIS0_NODE,shoot);
|
odrive_pos_cmd(AXIS0_NODE,shoot);
|
||||||
|
|
||||||
|
// vofa_spi[0]=shoot;
|
||||||
// osDelay(5000);
|
// vofa_spi[0]=multi_turn_angle;
|
||||||
// odrive_accel_cmd(AXIS0_NODE,5,5);
|
// vofa_tx_main(vofa_spi);
|
||||||
// odrive_pos_cmd(AXIS0_NODE,10);
|
|
||||||
// osDelay(DELAY);
|
|
||||||
// odrive_accel_cmd(AXIS1_NODE,ACCEL_BACK,ACCEL_BACK);
|
|
||||||
// odrive_pos_cmd(AXIS1_NODE,POS_ZERO);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,5 +44,6 @@ void shootBack(void)
|
|||||||
odrive_accel_cmd(AXIS0_NODE,ACCEL_BACK,ACCEL_BACK);
|
odrive_accel_cmd(AXIS0_NODE,ACCEL_BACK,ACCEL_BACK);
|
||||||
osDelay(2);
|
osDelay(2);
|
||||||
odrive_pos_cmd(AXIS0_NODE,POS_ZERO);
|
odrive_pos_cmd(AXIS0_NODE,POS_ZERO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ extern RC_mess_t RC_mess;
|
|||||||
extern motor_measure_t *trigger_motor_data;//3508电机数据
|
extern motor_measure_t *trigger_motor_data;//3508电机数据
|
||||||
|
|
||||||
|
|
||||||
#define GO1_SHOOT 1
|
#define GO1_SHOOT 0
|
||||||
#define ODRIVE_SHOOT 0
|
#define ODRIVE_SHOOT 1
|
||||||
|
|
||||||
#define KP 0.12
|
#define KP 0.12
|
||||||
#define KD 0.008
|
#define KD 0.008
|
||||||
@ -59,18 +59,33 @@ void shoot_ball(int key)
|
|||||||
|
|
||||||
|
|
||||||
#elif ODRIVE_SHOOT == 1
|
#elif ODRIVE_SHOOT == 1
|
||||||
|
//初始位置在最上面, 有球放过来, 电机转动到最下面等待发射
|
||||||
|
//发射指令,当到最高点时,扳机离合
|
||||||
|
//返回扳机,远动到最下面
|
||||||
|
|
||||||
void shoot_odrive(void)
|
extern float angle_encoder;
|
||||||
|
extern volatile int32_t multi_turn_angle ;
|
||||||
|
extern volatile uint16_t last_angle ;
|
||||||
|
|
||||||
|
void shoot_odrive(int angle)
|
||||||
{
|
{
|
||||||
//扳机
|
// if(ball)
|
||||||
if(trigger_motor_data->real_angle == 60)
|
// {
|
||||||
{
|
// if(multi_turn_angle==8)
|
||||||
trigger_pos(0);
|
// {
|
||||||
}
|
// //di
|
||||||
else
|
// odrive_accel_cmd(AXIS0_NODE,200,200);
|
||||||
{
|
// odrive_pos_cmd(AXIS0_NODE,0);
|
||||||
trigger_pos(60);
|
// }
|
||||||
}
|
// else if(multi_turn_angle==0)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
odrive_accel_cmd(AXIS0_NODE,200,200);
|
||||||
|
osDelay(2);
|
||||||
|
odrive_pos_cmd(AXIS0_NODE,angle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,5 +22,6 @@ typedef struct
|
|||||||
|
|
||||||
void shooterInit(void);
|
void shooterInit(void);
|
||||||
void shoot_ball(int key);
|
void shoot_ball(int key);
|
||||||
|
void shoot_odrive(int angle);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,14 +16,14 @@ void Task_Go(void *argument)
|
|||||||
#if GOUSE==1
|
#if GOUSE==1
|
||||||
|
|
||||||
//HAL_Delay(2000);
|
//HAL_Delay(2000);
|
||||||
gimbalInit();
|
// gimbalInit();
|
||||||
//HAL_GPIO_WritePin(ledGreen_GPIO_Port,ledGreen_Pin,GPIO_PIN_RESET);
|
//HAL_GPIO_WritePin(ledGreen_GPIO_Port,ledGreen_Pin,GPIO_PIN_RESET);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
|
||||||
LED_green();
|
LED_green();
|
||||||
gimbalFlow();
|
// gimbalFlow();
|
||||||
osDelay(1);
|
osDelay(1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -12,7 +12,7 @@ void Task_Led(void *argument) {
|
|||||||
|
|
||||||
// LED_red();
|
// LED_red();
|
||||||
// LED_bule();
|
// LED_bule();
|
||||||
see_you_again();
|
// see_you_again();
|
||||||
// LED_green();
|
// LED_green();
|
||||||
|
|
||||||
// osDelay(500);
|
// osDelay(500);
|
||||||
|
@ -5,16 +5,22 @@
|
|||||||
#include <cmsis_os2.h>
|
#include <cmsis_os2.h>
|
||||||
#include "remote_control.h"
|
#include "remote_control.h"
|
||||||
#include "shoot.h"
|
#include "shoot.h"
|
||||||
|
#include "odrive_shoot.h"
|
||||||
|
#include "read_spi.h"
|
||||||
|
|
||||||
extern RC_mess_t RC_mess;
|
extern RC_mess_t RC_mess;
|
||||||
|
Encoder_t encoder;
|
||||||
#define GO1_SHOOT 1
|
double angles;
|
||||||
#define ODRIVE_SHOOT 0
|
int32_t rounds;
|
||||||
|
int angleo = 0; //发射角度
|
||||||
|
#define GO1_SHOOT 0
|
||||||
|
#define ODRIVE_SHOOT 1
|
||||||
|
|
||||||
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
|
||||||
@ -29,8 +35,10 @@ void Task_Shoot(void *argument)
|
|||||||
|
|
||||||
#elif ODRIVE_SHOOT == 1
|
#elif ODRIVE_SHOOT == 1
|
||||||
shootStep();
|
shootStep();
|
||||||
|
//shoot_odrive(angleo);
|
||||||
#endif
|
#endif
|
||||||
|
// 更新编码器数据
|
||||||
|
Update_Encoder(&encoder);
|
||||||
|
|
||||||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */
|
osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */
|
||||||
|
Loading…
Reference in New Issue
Block a user