Compare commits

..

2 Commits

Author SHA1 Message Date
ws
25bdadf878 速度大了会卡死 2025-03-27 23:02:19 +08:00
ws
24eb09e2f7 test 2025-03-26 20:15:44 +08:00
13 changed files with 170 additions and 45 deletions

View File

@ -62,3 +62,9 @@
[info] Log at : 2025/3/19|14:10:22|GMT+0800
[info] Log at : 2025/3/26|14:58:18|GMT+0800
[info] Log at : 2025/3/26|15:24:15|GMT+0800
[info] Log at : 2025/3/26|17:13:53|GMT+0800

View File

@ -1,8 +1,8 @@
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin'
Build target 'mycode1'
compiling shoot_task.c...
compiling shoot.c...
linking...
Program Size: Code=26332 RO-data=1904 RW-data=280 ZI-data=22472
Program Size: Code=25844 RO-data=1904 RW-data=248 ZI-data=22512
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/19 14:04:20
2025/3/26 20:14:55

View File

@ -230,6 +230,11 @@
<WinNumber>1</WinNumber>
<ItemText>trigger_angle_o</ItemText>
</Ww>
<Ww>
<count>16</count>
<WinNumber>1</WinNumber>
<ItemText>speed_6384,0x0A</ItemText>
</Ww>
</WatchWindow1>
<WatchWindow2>
<Ww>
@ -868,7 +873,7 @@
<Group>
<GroupName>User/device</GroupName>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
@ -1004,7 +1009,7 @@
<Group>
<GroupName>User/module</GroupName>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>

View File

@ -2,7 +2,7 @@
## r1上层
1. **odrive**推射 **can1** **id 010** **spi2**读取as5047p
1. **vesc** **can1 id:77** **spi2**读取as5047p
2. go1 RS485模块 01翻转 02云台
3. 爪子 左三PC6
4. 接球 左一左2 PI7 PI6

View File

@ -303,28 +303,36 @@ void CAN_cmd_2FF(int16_t motor1, int16_t motor2, int16_t motor3, CAN_HandleTypeD
HAL_CAN_AddTxMessage(hcan, &tx_meessage_2ff, can_send_data_2ff, &send_mail_box);
}
/**************************************
*
**************************************/
/**
* @brief
* @param[in] i:
* @retval
*/
motor_measure_t *get_motor_point(uint8_t i)
{
return &motor_chassis[i];
}
/**
* @brief vesc电机转速
* @param[in/out] rpm: vesce电机转速
* @retval none
*
* rpm的绝对值大于wtrcfg_VESC_COMMAND_ERPM_MAX,
* rpm的值设置为wtrcfg_VESC_COMMAND_ERPM_MAX或-wtrcfg_VESC_COMMAND_ERPM_MAX
*/
void assert_param_rpm(float *rpm){
if( fabsf(*rpm) > wtrcfg_VESC_COMMAND_ERPM_MAX )
*rpm = *rpm > 0 ? wtrcfg_VESC_COMMAND_ERPM_MAX : - wtrcfg_VESC_COMMAND_ERPM_MAX ;
}
/**
* @brief
* @param[in] i:
* @retval
* @brief 使vesc电机进入转速模式
* @param[in] controller_id: vesc电机控制器id
* @param[in] RPM:
* @retval RPM1000-50000
*/
motor_measure_t *get_motor_point(uint8_t i)
{
return &motor_chassis[i];
}
/*
controller_id65RPM1000-50000
*/
void CAN_VESC_RPM(uint8_t controller_id, float RPM)
{
uint32_t id;
@ -347,3 +355,23 @@ void CAN_VESC_RPM(uint8_t controller_id, float RPM)
HAL_CAN_AddTxMessage(&hcan1, &vesc_tx_message, vesc_send_data, &send_mail_box);
}
/**
* @brief 使vesc电机进入制动模式
* @param[in] controller_id: vesc电机控制器id
* @retval none
*/
void CAN_VESC_HEAD(uint8_t controller_id)
{
uint32_t id;
uint32_t send_mail_box;
id = controller_id | ((uint32_t)CAN_PACKET_SET_CURRENT_BRAKE << 8);
vesc_tx_message.ExtId = id;
vesc_tx_message.IDE = CAN_ID_EXT;
vesc_tx_message.RTR = CAN_RTR_DATA;
vesc_tx_message.DLC = 0x04;
HAL_CAN_AddTxMessage(&hcan1, &vesc_tx_message, vesc_send_data, &send_mail_box);
}

View File

@ -166,6 +166,8 @@ void vescMotorEncode(void);
void CAN_VESC_RPM(uint8_t controller_id, float RPM);
void CAN_VESC_HEAD(uint8_t controller_id);
#ifdef __cplusplus
}
#endif

View File

@ -61,6 +61,25 @@ void Update_Encoder(Encoder_t *ptr) {
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) {
return ptr->round_cnt;
}

View File

@ -19,7 +19,7 @@
#define SETTINGS2 0x0019
typedef struct {
int32_t round_cnt;
float round_cnt;
uint16_t ecd;
uint16_t last_ecd;
uint16_t offset_ecd;

View File

@ -1,9 +1,82 @@
#include "shoot.h"
#include "remote_control.h"
#include "read_spi.h"
extern RC_mess_t RC_mess;
extern Encoder_t encoder;
extern motor_measure_t *trigger_motor_data;//3508电机数据
int mode=0;
int shoot=0;
int xxx=0;
#define Stop 0
#define Hasten 1
#define Slow 2
#define Shoot 3
#define VESC_ID 77
int speed_6384=-1500;
void control_clutch_shoot(void)
{
if(mode == Stop)
{
if(encoder.round_cnt == 0)
{
CAN_VESC_HEAD(VESC_ID);
}
}
else if(mode == Hasten)
{
if(shoot ==0)
{
if(encoder.round_cnt <= 2)
{
xxx=1;
CAN_VESC_RPM(VESC_ID, speed_6384);
}
}
else if(shoot ==Shoot)
{
if(encoder.round_cnt <= 3)
{
xxx=3;
HAL_GPIO_WritePin(key_GPIO_Port,key_Pin,GPIO_PIN_SET);
CAN_VESC_RPM(VESC_ID, speed_6384);
}
// 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);
CAN_VESC_HEAD(VESC_ID);
}
}
else if(shoot == Slow)
{
CAN_VESC_HEAD(VESC_ID);
}
}
}

View File

@ -5,8 +5,8 @@
#include "djiMotor.h"
#include "calc_lib.h"
#include "pid.h"
#include "main.h"
void control_clutch_shoot(void);
#endif

View File

@ -13,13 +13,10 @@ extern RC_mess_t RC_mess;
extern int16_t result;
extern int16_t t_result;
extern motor_measure_t *trigger_motor_data;
Encoder_t encoder;
float vofa[8];
int speed=0;
float m=0;
float trigger_angle_o=0;
int mode=0;
/**
* \brief
*
@ -32,19 +29,13 @@ void Task_Motor(void *argument)
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CTRL_CHASSIS;
motor_init();
Encoder_Init(&encoder);
uint32_t tick = osKernelGetTickCount();
while(1)
{
//收到消息队列新数据
// 更新编码器数据
Update_Encoder(&encoder);
m=trigger_angle_o*(8191/360);
CAN_cmd_200(t_result,0,0,0,&hcan1);
osDelay(2);

View File

@ -10,27 +10,28 @@
#include "djiMotor.h"
extern RC_mess_t RC_mess;
extern Encoder_t encoder;
extern motor_measure_t *trigger_motor_data;//3508电机数据
extern int mode;
int speed_6384=10000;
Encoder_t encoder;
void Task_Shoot(void *argument)
{
(void)argument; /* 未使用argument消除警告 */
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN;
Encoder_Init(&encoder);
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计算 */
while(1)
{
CAN_VESC_RPM(77, speed_6384);
//收到消息队列新数据
// 更新编码器数据
Update_Encoder(&encoder);
control_clutch_shoot();
tick += delay_tick; /* 计算下一个唤醒时刻 */
osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */
}