暂存一下
This commit is contained in:
parent
a609af6ba4
commit
36ad4c7c96
@ -7,7 +7,7 @@ int key=0;
|
||||
void detect_exit(void)
|
||||
{
|
||||
|
||||
delay_ms(100); // 延时10ms
|
||||
delay_ms(10); // 延时10ms
|
||||
key++; // 按键按下时变量自增
|
||||
__HAL_GPIO_EXTI_CLEAR_IT(KEY_Pin); // 清除中断标志位
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ extern int key;
|
||||
BallState_t currentState1 = BALL_IDLE; // 当前状态
|
||||
uint32_t startTime = 0; // 用于记录延时的起始时间
|
||||
int speedm=0;
|
||||
int speedm1=0;
|
||||
|
||||
#define MOTOR_SPEED 1000
|
||||
|
||||
@ -36,18 +37,24 @@ Ball ::Ball()
|
||||
|
||||
}
|
||||
|
||||
void Ball ::Spin(float speed)
|
||||
void Ball ::Spin(float speed,float speed2)
|
||||
{
|
||||
|
||||
speedSet[MOTOR_1] = -speed;
|
||||
result[MOTOR_1] = PID_calc(&speed_pid[MOTOR_1],hand_Motor[MOTOR_1]->speed_rpm,speedSet[MOTOR_1]);
|
||||
|
||||
for(int i = 1;i < MOTOR_NUM;i ++)
|
||||
{
|
||||
speedSet[i] = speed;
|
||||
result[i] = PID_calc(&speed_pid[i],hand_Motor[i]->speed_rpm,speedSet[i]);
|
||||
speedSet[MOTOR_2] = speed2;
|
||||
result[MOTOR_2] = PID_calc(&speed_pid[MOTOR_2],hand_Motor[MOTOR_2]->speed_rpm,speedSet[MOTOR_2]);
|
||||
|
||||
}
|
||||
speedSet[MOTOR_3] = speed;
|
||||
result[MOTOR_3] = PID_calc(&speed_pid[MOTOR_3],hand_Motor[MOTOR_3]->speed_rpm,speedSet[MOTOR_3]);
|
||||
|
||||
// for(int i = 1;i < MOTOR_NUM;i ++)
|
||||
// {
|
||||
// speedSet[i] = speed;
|
||||
// result[i] = PID_calc(&speed_pid[i],hand_Motor[i]->speed_rpm,speedSet[i]);
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -60,19 +67,20 @@ void Ball::ballHadling(void)
|
||||
switch (currentState1)
|
||||
{
|
||||
case BALL_IDLE:
|
||||
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET);//确保闭合气缸
|
||||
if (key > 0) // 检测按键是否被按下
|
||||
{
|
||||
speedm=-4000;
|
||||
speedm=-4500;
|
||||
speedm1=-3500;
|
||||
currentState1 = BALL_FORWARD; // 切换到正转状态
|
||||
}
|
||||
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 )
|
||||
if ( hand_Motor[MOTOR_1]->speed_rpm >= 4480&&hand_Motor[MOTOR_1]->speed_rpm <= 4520 &&
|
||||
hand_Motor[MOTOR_2]->speed_rpm <= -2980-500&&hand_Motor[MOTOR_2]->speed_rpm >= -3020-500 &&
|
||||
hand_Motor[MOTOR_3]->speed_rpm <= -4480&&hand_Motor[MOTOR_3]->speed_rpm >= -4020-1000 )
|
||||
{
|
||||
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET);// 打开气缸
|
||||
currentState1 = BALL_DROP; // 切换到球下落状态
|
||||
@ -81,10 +89,11 @@ void Ball::ballHadling(void)
|
||||
|
||||
case BALL_DROP:
|
||||
|
||||
if (ball_state == 1)
|
||||
if (ball_state == 1) //读光电 有球 0 无球 1
|
||||
{
|
||||
osDelay(200); // 延时50ms
|
||||
speedm=2500;
|
||||
osDelay(200); // 延时200ms
|
||||
speedm=3000;
|
||||
speedm1=3000;
|
||||
currentState1 = BALL_REVERSE; // 切换到反转状态
|
||||
}
|
||||
|
||||
@ -95,8 +104,9 @@ void Ball::ballHadling(void)
|
||||
if (ball_state == 0)
|
||||
{
|
||||
|
||||
flag=2;
|
||||
speedm=0;
|
||||
flag=2; //抽象的计次
|
||||
speedm=0; // 停止电机
|
||||
speedm1=0;
|
||||
currentState1 = BALL_CLOSE; // 切换到完成状态
|
||||
}
|
||||
|
||||
@ -120,6 +130,7 @@ void Ball::ballHadling(void)
|
||||
key = 0; // 重置按键状态
|
||||
flag=0;
|
||||
speedm=0;
|
||||
speedm1=0;
|
||||
currentState1 = BALL_IDLE; // 回到空闲状态
|
||||
break;
|
||||
|
||||
|
@ -33,7 +33,7 @@ class Ball
|
||||
{
|
||||
public:
|
||||
Ball();
|
||||
void Spin(float speed);
|
||||
void Spin(float speed,float speed2);
|
||||
void ballHadling(void);
|
||||
void Send_control(void);
|
||||
void ballStateMachine(void);
|
||||
|
@ -7,10 +7,10 @@
|
||||
#include "remote_control.h"
|
||||
extern RC_ctrl_t rc_ctrl;
|
||||
Ball ball;
|
||||
|
||||
int abc=0;
|
||||
int c30=0;
|
||||
int speed1=500;
|
||||
extern int speedm;
|
||||
extern int speedm1;
|
||||
|
||||
void FunctionBall(void *argument)
|
||||
{
|
||||
@ -25,8 +25,9 @@ void FunctionBall(void *argument)
|
||||
task_struct.stack_water_mark.ball = osThreadGetStackSpace(osThreadGetId());
|
||||
#endif
|
||||
abc=HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);
|
||||
|
||||
ball.ballHadling(); // 处理摩擦轮转动
|
||||
ball.Spin(speedm);
|
||||
ball.Spin(speedm,speedm1);
|
||||
ball.Send_control();
|
||||
|
||||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "remote_control.h"
|
||||
extern RC_ctrl_t rc_ctrl;
|
||||
Shoot shoot;
|
||||
int k=0;
|
||||
|
||||
// sw[0]2 下306上1694 sw[5]3前306后1694 sw[4]4前1694后306 sw[1]xuan1 sw[3]xuan2
|
||||
|
||||
@ -26,7 +25,6 @@ while(1)
|
||||
task_struct.stack_water_mark.shoot = osThreadGetStackSpace(osThreadGetId());
|
||||
#endif
|
||||
|
||||
k++;
|
||||
shoot.shootThree();
|
||||
shoot.shootBack();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user