速度大了会卡死
This commit is contained in:
parent
24eb09e2f7
commit
25bdadf878
@ -61,6 +61,25 @@ void Update_Encoder(Encoder_t *ptr) {
|
|||||||
ptr->last_ecd = ptr->ecd;
|
ptr->last_ecd = ptr->ecd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void Update_Encoder(Encoder_t *ptr) {
|
||||||
|
// ptr->ecd = AS5047_read(ANGLEUNC);
|
||||||
|
|
||||||
|
// // 检测编码器的圈数变化
|
||||||
|
// if (ptr->ecd - ptr->last_ecd > 4096) {
|
||||||
|
// ptr->round_cnt -= 1.0f; // 减去一圈
|
||||||
|
// } else if (ptr->ecd - ptr->last_ecd < -4096) {
|
||||||
|
// ptr->round_cnt += 1.0f; // 加上一圈
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 计算总角度
|
||||||
|
// ptr->total_angle = (double)((ptr->round_cnt * 8192 + ptr->ecd - ptr->offset_ecd));
|
||||||
|
|
||||||
|
// // 更新 round_cnt 为小数圈数
|
||||||
|
// ptr->round_cnt = (float)(ptr->total_angle / 8192.0f); // 将总角度转换为圈数(浮点数)
|
||||||
|
|
||||||
|
// ptr->last_ecd = ptr->ecd;
|
||||||
|
// }
|
||||||
|
|
||||||
int32_t Get_Encoder_Rounds(Encoder_t *ptr) {
|
int32_t Get_Encoder_Rounds(Encoder_t *ptr) {
|
||||||
return ptr->round_cnt;
|
return ptr->round_cnt;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#define SETTINGS2 0x0019
|
#define SETTINGS2 0x0019
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t round_cnt;
|
float round_cnt;
|
||||||
uint16_t ecd;
|
uint16_t ecd;
|
||||||
uint16_t last_ecd;
|
uint16_t last_ecd;
|
||||||
uint16_t offset_ecd;
|
uint16_t offset_ecd;
|
||||||
|
@ -8,6 +8,7 @@ extern motor_measure_t *trigger_motor_data;//3508电机数据
|
|||||||
|
|
||||||
int mode=0;
|
int mode=0;
|
||||||
int shoot=0;
|
int shoot=0;
|
||||||
|
int xxx=0;
|
||||||
|
|
||||||
#define Stop 0
|
#define Stop 0
|
||||||
#define Hasten 1
|
#define Hasten 1
|
||||||
@ -15,7 +16,7 @@ int shoot=0;
|
|||||||
#define Shoot 3
|
#define Shoot 3
|
||||||
#define VESC_ID 77
|
#define VESC_ID 77
|
||||||
|
|
||||||
int speed_6384=10000;
|
int speed_6384=-1500;
|
||||||
|
|
||||||
void control_clutch_shoot(void)
|
void control_clutch_shoot(void)
|
||||||
{
|
{
|
||||||
@ -35,9 +36,10 @@ void control_clutch_shoot(void)
|
|||||||
{
|
{
|
||||||
if(shoot ==0)
|
if(shoot ==0)
|
||||||
{
|
{
|
||||||
if(encoder.round_cnt <= 4)
|
if(encoder.round_cnt <= 2)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
xxx=1;
|
||||||
CAN_VESC_RPM(VESC_ID, speed_6384);
|
CAN_VESC_RPM(VESC_ID, speed_6384);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -45,22 +47,35 @@ void control_clutch_shoot(void)
|
|||||||
}
|
}
|
||||||
else if(shoot ==Shoot)
|
else if(shoot ==Shoot)
|
||||||
{
|
{
|
||||||
if(encoder.round_cnt <= 4)
|
if(encoder.round_cnt <= 3)
|
||||||
{
|
{
|
||||||
|
xxx=3;
|
||||||
HAL_GPIO_WritePin(key_GPIO_Port,key_Pin,GPIO_PIN_SET);
|
HAL_GPIO_WritePin(key_GPIO_Port,key_Pin,GPIO_PIN_SET);
|
||||||
|
|
||||||
CAN_VESC_RPM(VESC_ID, speed_6384);
|
CAN_VESC_RPM(VESC_ID, speed_6384);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(encoder.round_cnt >= 4)
|
|
||||||
|
// xxx=3;
|
||||||
|
// HAL_GPIO_WritePin(key_GPIO_Port,key_Pin,GPIO_PIN_SET);
|
||||||
|
// CAN_VESC_RPM(VESC_ID, speed_6384);
|
||||||
|
|
||||||
|
if(encoder.round_cnt >= 3)
|
||||||
{
|
{
|
||||||
|
xxx=4;
|
||||||
|
shoot=Slow;
|
||||||
HAL_GPIO_WritePin(key_GPIO_Port,key_Pin,GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(key_GPIO_Port,key_Pin,GPIO_PIN_RESET);
|
||||||
|
|
||||||
CAN_VESC_HEAD(VESC_ID);
|
CAN_VESC_HEAD(VESC_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(shoot == Slow)
|
||||||
|
{
|
||||||
|
|
||||||
|
CAN_VESC_HEAD(VESC_ID);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
void control_clutch_shoot(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,7 +30,7 @@ void Task_Shoot(void *argument)
|
|||||||
// 更新编码器数据
|
// 更新编码器数据
|
||||||
Update_Encoder(&encoder);
|
Update_Encoder(&encoder);
|
||||||
|
|
||||||
|
control_clutch_shoot();
|
||||||
|
|
||||||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */
|
osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */
|
||||||
|
Loading…
Reference in New Issue
Block a user