fix rc debug and ir logic

This commit is contained in:
2024-10-01 22:34:01 +03:00
parent 6c3af6fbb5
commit 839da85dfe
11 changed files with 154 additions and 91 deletions

View File

@ -23,7 +23,6 @@ unsigned char Shiftreg[3];
extern InfoBlock infoBlock;
uint8_t ballDetected = 0;
uint32_t ballReact_timer = 0;
uint8_t isDelayTimerRun = 0;
uint32_t startDelay_timer;
CurrentShot *postDelayShot = NULL;
uint32_t lastIndicationTime = 0;
@ -32,7 +31,7 @@ uint32_t noBallTimeout = 0xFFFFFFFF;
void BallEXT_Handler();
void robotStateStart(uint32_t delayTime);
void robotStatePause();
void pauseShooting();
void robotStateStop();
float calculatePeriod(int pwm_value);
uint8_t nextBallInShot(CurrentShot *shot);
@ -47,10 +46,13 @@ void robotStateStart(uint32_t delayTime) {
currentInfo.state = PRERUN_WAIT;
currentInfo.startDelay = delayTime;
startDelay_timer = millis();
isDelayTimerRun = 1;
}
void robotStatePause() {
void pauseShooting() {
currentInfo.state = PAUSE;
led_clear();
setScrewkSpeed(0);
setRollersSpeed(100, 100);
}
void robotStateStop() {
@ -116,12 +118,14 @@ void RobotTick() {
// No Ball Handler
if (currentInfo.state == RUN && millis() - noBallTimer > noBallTimeout) {
if(currentInfo.mode == DebugShot){
currentInfo.mode = ShotMode;
}
robotStateStop();
led_clear();
for (int i = 7; i <= 12; ++i) {
led_blink_num(i, 250, 0xFFFF-1);
led_blink_num(i, 250, 0xFFFF - 1);
}
isDelayTimerRun = 0;
setScrewkSpeed(0);
setRollersSpeed(100, 100);
setPos(infoBlock.hwInfo.servos[SERVO_AXIAL].def,
@ -131,20 +135,19 @@ void RobotTick() {
}
// PreRun delay
if (isDelayTimerRun) {
if (currentInfo.state == PRERUN_WAIT) {
uint32_t elapsedTime = millis() - startDelay_timer;
if (elapsedTime > currentInfo.startDelay) {
isDelayTimerRun = 0;
if (currentInfo.state == PRERUN_WAIT) {
currentInfo.state = RUN;
shotApply(postDelayShot);
}
} else {
uint32_t intervalStep = currentInfo.startDelay / NUMLEDS;
if (elapsedTime - lastIndicationTime >= intervalStep) {
lastIndicationTime = elapsedTime;
uint8_t progress = 100 - (elapsedTime * 100) / currentInfo.startDelay;
uint8_t progress = 100
- (elapsedTime * 100) / currentInfo.startDelay;
uint8_t ledProgress = map(progress, 0, 70, 0, 100);
if (ledProgress > 30) {
@ -258,6 +261,14 @@ void BallEXT_Handler() {
infoBlock.statInfo.shotInMacro++;
saveInfoBlock();
break;
case DebugShot:
currentInfo.mode = ShotMode;
led_clear();
robotStateStop();
setScrewkSpeed(0);
setRollersSpeed(100, 100);
break;
default:
break;
}
@ -502,10 +513,13 @@ void startShooting(uint32_t delayTime) {
}
void stopShooting() {
if(currentInfo.mode == DebugShot){
currentInfo.mode = ShotMode;
}
robotStateStop();
led_clear();
isDelayTimerRun = 0;
robotStateStop();
setScrewkSpeed(0);
setRollersSpeed(100, 100);
setPosDefault();