可用三摩擦
This commit is contained in:
parent
f0931e76d2
commit
a609af6ba4
@ -94,7 +94,7 @@ void MX_GPIO_Init(void)
|
|||||||
|
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = KEY_Pin;
|
GPIO_InitStruct.Pin = KEY_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
HAL_GPIO_Init(KEY_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(KEY_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
@ -279,8 +279,8 @@ void USART1_IRQHandler(void)
|
|||||||
/**
|
/**
|
||||||
* @brief This function handles USART3 global interrupt.
|
* @brief This function handles USART3 global interrupt.
|
||||||
*/
|
*/
|
||||||
//void USART3_IRQHandler(void)
|
// void USART3_IRQHandler(void)
|
||||||
//{
|
// {
|
||||||
// /* USER CODE BEGIN USART3_IRQn 0 */
|
// /* USER CODE BEGIN USART3_IRQn 0 */
|
||||||
|
|
||||||
// /* USER CODE END USART3_IRQn 0 */
|
// /* USER CODE END USART3_IRQn 0 */
|
||||||
@ -288,7 +288,7 @@ void USART1_IRQHandler(void)
|
|||||||
// /* USER CODE BEGIN USART3_IRQn 1 */
|
// /* USER CODE BEGIN USART3_IRQn 1 */
|
||||||
|
|
||||||
// /* USER CODE END USART3_IRQn 1 */
|
// /* USER CODE END USART3_IRQn 1 */
|
||||||
//}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles DMA2 stream1 global interrupt.
|
* @brief This function handles DMA2 stream1 global interrupt.
|
||||||
|
@ -188,44 +188,71 @@
|
|||||||
<Ww>
|
<Ww>
|
||||||
<count>7</count>
|
<count>7</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>ball,0x0A</ItemText>
|
<ItemText>cnt1,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>8</count>
|
<count>8</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>cnt1,0x0A</ItemText>
|
<ItemText>cmd_fromnuc</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>9</count>
|
<count>9</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>cmd_fromnuc</ItemText>
|
<ItemText>nucbuf</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>10</count>
|
<count>10</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>nucbuf</ItemText>
|
<ItemText>nucData</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>11</count>
|
<count>11</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>nucData</ItemText>
|
<ItemText>send,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>12</count>
|
<count>12</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>send,0x0A</ItemText>
|
<ItemText>speed1,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>13</count>
|
<count>13</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>speed1,0x0A</ItemText>
|
<ItemText>abc,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>14</count>
|
<count>14</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>\\R1_shooter\../User/task/ballTask.cpp\ball,0x0A</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>15</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>speedm,0x0A</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>16</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>abc,0x0A</ItemText>
|
<ItemText>abc,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>17</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>flag,0x0A</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>18</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>ball_state,0x0A</ItemText>
|
||||||
|
</Ww>
|
||||||
</WatchWindow1>
|
</WatchWindow1>
|
||||||
|
<WatchWindow2>
|
||||||
|
<Ww>
|
||||||
|
<count>0</count>
|
||||||
|
<WinNumber>2</WinNumber>
|
||||||
|
<ItemText>ball,0x0A</ItemText>
|
||||||
|
</Ww>
|
||||||
|
</WatchWindow2>
|
||||||
<Tracepoint>
|
<Tracepoint>
|
||||||
<THDelay>0</THDelay>
|
<THDelay>0</THDelay>
|
||||||
</Tracepoint>
|
</Tracepoint>
|
||||||
@ -1060,7 +1087,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>
|
||||||
|
@ -174,8 +174,9 @@ NVIC.USART1_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
|
|||||||
NVIC.USART3_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
|
NVIC.USART3_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
|
||||||
NVIC.USART6_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
|
NVIC.USART6_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
|
||||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
||||||
PA0-WKUP.GPIOParameters=GPIO_PuPd,GPIO_Label
|
PA0-WKUP.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI
|
||||||
PA0-WKUP.GPIO_Label=KEY
|
PA0-WKUP.GPIO_Label=KEY
|
||||||
|
PA0-WKUP.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
|
||||||
PA0-WKUP.GPIO_PuPd=GPIO_PULLUP
|
PA0-WKUP.GPIO_PuPd=GPIO_PULLUP
|
||||||
PA0-WKUP.Locked=true
|
PA0-WKUP.Locked=true
|
||||||
PA0-WKUP.Signal=GPXTI0
|
PA0-WKUP.Signal=GPXTI0
|
||||||
|
@ -7,12 +7,16 @@ extern RC_ctrl_t rc_ctrl;
|
|||||||
extern int key;
|
extern int key;
|
||||||
|
|
||||||
// 定义状态机变量
|
// 定义状态机变量
|
||||||
BallState_t currentBallState = BALL_IDLE;
|
BallState_t currentState1 = BALL_IDLE; // 当前状态
|
||||||
|
uint32_t startTime = 0; // 用于记录延时的起始时间
|
||||||
|
int speedm=0;
|
||||||
|
|
||||||
#define MOTOR_SPEED 1000
|
#define MOTOR_SPEED 1000
|
||||||
|
|
||||||
const fp32 Ball:: M3508_speed_PID[3] = {5, 0, 0};
|
const fp32 Ball:: M3508_speed_PID[3] = {5, 0, 0};
|
||||||
|
|
||||||
|
//PE11 气缸
|
||||||
|
|
||||||
//三摩擦轮运球!!!
|
//三摩擦轮运球!!!
|
||||||
|
|
||||||
Ball ::Ball()
|
Ball ::Ball()
|
||||||
@ -45,46 +49,90 @@ void Ball ::Spin(float speed)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CAN_cmd_200(result[MOTOR_1],result[MOTOR_2],result[MOTOR_3],0,&hcan1);
|
|
||||||
osDelay(1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int flag =0;
|
||||||
|
int ball_state = 0;
|
||||||
void Ball::ballHadling(void)
|
void Ball::ballHadling(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ball_state =HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);//有球 0 无球 1
|
||||||
|
switch (currentState1)
|
||||||
|
{
|
||||||
|
case BALL_IDLE:
|
||||||
|
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET);
|
||||||
if (key > 0) // 检测按键是否被按下
|
if (key > 0) // 检测按键是否被按下
|
||||||
{
|
{
|
||||||
if (key % 2 == 1) // key 为奇数,摩擦轮正转
|
speedm=-4000;
|
||||||
{
|
currentState1 = BALL_FORWARD; // 切换到正转状态
|
||||||
Spin(5000); // 正转
|
|
||||||
}
|
}
|
||||||
else if (key % 2 == 0) // key 为偶数,摩擦轮反转
|
break;
|
||||||
|
|
||||||
|
case BALL_FORWARD:
|
||||||
|
|
||||||
|
if ( hand_Motor[MOTOR_1]->speed_rpm > 3980&&hand_Motor[MOTOR_1]->speed_rpm <= 4010&&
|
||||||
|
hand_Motor[MOTOR_2]->speed_rpm <= -3980&&hand_Motor[MOTOR_2]->speed_rpm >= -4010&&
|
||||||
|
hand_Motor[MOTOR_3]->speed_rpm <= -3980&&hand_Motor[MOTOR_2]->speed_rpm >= -4010 )
|
||||||
{
|
{
|
||||||
Spin(-5000); // 反转
|
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET);// 打开气缸
|
||||||
|
currentState1 = BALL_DROP; // 切换到球下落状态
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BALL_DROP:
|
||||||
|
|
||||||
|
if (ball_state == 1)
|
||||||
|
{
|
||||||
|
osDelay(200); // 延时50ms
|
||||||
|
speedm=2500;
|
||||||
|
currentState1 = BALL_REVERSE; // 切换到反转状态
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BALL_REVERSE:
|
||||||
|
|
||||||
|
if (ball_state == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
flag=2;
|
||||||
|
speedm=0;
|
||||||
|
currentState1 = BALL_CLOSE; // 切换到完成状态
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BALL_CLOSE:
|
||||||
|
osDelay(200); // 延时50ms
|
||||||
|
if (flag == 2)
|
||||||
|
{
|
||||||
|
if(ball_state == 0)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET);
|
||||||
|
currentState1 = BALL_FINISH; // 切换到完成状态
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BALL_FINISH:
|
||||||
|
osDelay(200); // 延时50ms
|
||||||
|
key = 0; // 重置按键状态
|
||||||
|
flag=0;
|
||||||
|
speedm=0;
|
||||||
|
currentState1 = BALL_IDLE; // 回到空闲状态
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
currentState1 = BALL_IDLE; // 默认回到空闲状态
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void Ball::ballHadling(void)
|
void Ball::Send_control()
|
||||||
// {
|
{
|
||||||
// static bool isReversed = false; // 静态变量,记录当前摩擦轮状态,初始为正转
|
CAN_cmd_200(result[MOTOR_1],result[MOTOR_2],result[MOTOR_3],0,&hcan1);
|
||||||
|
|
||||||
// if (key > 0) // 检测按键是否被按下
|
}
|
||||||
// {
|
|
||||||
// key = 0; // 重置按键状态,防止重复触发
|
|
||||||
|
|
||||||
// if (isReversed)
|
|
||||||
// {
|
|
||||||
// // 当前为反转,切换为正转
|
|
||||||
// Spin(MOTOR_SPEED); // 正转
|
|
||||||
// isReversed = false;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// // 当前为正转,切换为反转
|
|
||||||
// Spin(-MOTOR_SPEED); // 反转
|
|
||||||
// isReversed = true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
@ -10,11 +10,11 @@
|
|||||||
// 定义状态枚举
|
// 定义状态枚举
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BALL_IDLE, // 空闲状态
|
BALL_IDLE, // 空闲状态
|
||||||
BALL_RELEASE, // 下球气缸弹出,爪子张开
|
BALL_FORWARD, // 正转状态
|
||||||
BALL_JOINT_REVERSE, // 关节电机反转置水平位置
|
BALL_DROP, // 球下落状态
|
||||||
BALL_FALLING, // 球加速落下
|
BALL_REVERSE, // 反转状态
|
||||||
BALL_WAIT_BOUNCE, // 等待光电检测反弹
|
BALL_CLOSE, // 关闭状态
|
||||||
BALL_NET_CLOSE // 收网状态
|
BALL_FINISH // 完成状态
|
||||||
} BallState_t;
|
} BallState_t;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@ -35,14 +35,15 @@ public:
|
|||||||
Ball();
|
Ball();
|
||||||
void Spin(float speed);
|
void Spin(float speed);
|
||||||
void ballHadling(void);
|
void ballHadling(void);
|
||||||
|
void Send_control(void);
|
||||||
void ballStateMachine(void);
|
void ballStateMachine(void);
|
||||||
|
|
||||||
int16_t result[MOTOR_NUM];
|
int16_t result[MOTOR_NUM];
|
||||||
|
motor_measure_t *hand_Motor[MOTOR_NUM];
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int up_ball_state; //上球状态 0:无球 1:有球
|
int up_ball_state; //上球状态 0:无球 1:有球
|
||||||
motor_measure_t *hand_Motor[MOTOR_NUM];
|
|
||||||
//三个摩擦轮
|
//三个摩擦轮
|
||||||
static const float M3508_speed_PID[3];
|
static const float M3508_speed_PID[3];
|
||||||
static const float M3508_angle_PID[3];
|
static const float M3508_angle_PID[3];
|
||||||
|
@ -10,6 +10,7 @@ Ball ball;
|
|||||||
int abc=0;
|
int abc=0;
|
||||||
int c30=0;
|
int c30=0;
|
||||||
int speed1=500;
|
int speed1=500;
|
||||||
|
extern int speedm;
|
||||||
|
|
||||||
void FunctionBall(void *argument)
|
void FunctionBall(void *argument)
|
||||||
{
|
{
|
||||||
@ -23,10 +24,10 @@ void FunctionBall(void *argument)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
task_struct.stack_water_mark.ball = osThreadGetStackSpace(osThreadGetId());
|
task_struct.stack_water_mark.ball = osThreadGetStackSpace(osThreadGetId());
|
||||||
#endif
|
#endif
|
||||||
abc=HAL_GPIO_ReadPin(STOP_GPIO_Port, STOP_Pin);
|
abc=HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);
|
||||||
ball.ballHadling(); // 处理摩擦轮转动
|
ball.ballHadling(); // 处理摩擦轮转动
|
||||||
// ball.Spin(speed1);
|
ball.Spin(speedm);
|
||||||
osDelay(3);
|
ball.Send_control();
|
||||||
|
|
||||||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
osDelayUntil(tick);
|
osDelayUntil(tick);
|
||||||
|
Loading…
Reference in New Issue
Block a user