This commit is contained in:
2024-10-08 16:51:36 +03:00
parent 53bf72d071
commit 08b99d8ec2
9 changed files with 287 additions and 102 deletions

View File

@ -30,6 +30,10 @@ uint32_t lastIndicationTime = 0;
uint32_t noBallTimer = 0;
uint32_t noBallTimeout = 0xFFFFFFFF;
uint32_t stop_timer = 0;
uint32_t stop_timer_TIMEOUT = 0;
uint8_t onStopExecuted = 1;
void BallEXT_Handler();
void robotStateStart(uint32_t delayTime);
void pauseShooting();
@ -43,6 +47,12 @@ uint8_t loadShotFromProgram(CurrentProgram *currentProg);
uint8_t loadNextProgramInMacro(CurrentMacro *currentMacro);
uint8_t loadProgramFromMacro(CurrentMacro *currentMacro);
void setPosOffDelay(uint16_t ms){
stop_timer = millis();
stop_timer_TIMEOUT = ms;
onStopExecuted = 0;
}
void robotStateStart(uint32_t delayTime) {
currentInfo.state = PRERUN_WAIT;
currentInfo.startDelay = delayTime;
@ -58,6 +68,8 @@ void pauseShooting() {
void robotStateStop() {
currentInfo.state = STOP;
stop_timer = millis();
onStopExecuted = 0;
}
long map(long x, long in_min, long in_max, long out_min, long out_max) {
@ -98,6 +110,12 @@ void Robot_INIT() {
}
led_clear();
melody(melody_start);
setPosOffDelay(1000);
// SetServoOFF(0);
// SetServoOFF(1);
// SetServoOFF(2);
}
void BallEXT() {
@ -105,11 +123,24 @@ void BallEXT() {
ballReact_timer = millis();
}
void setPosOff(){
SetServoOFF(0);
SetServoOFF(1);
SetServoOFF(2);
}
void RobotTick() {
BallEXT_Handler();
led_tick();
sound_tick();
if(onStopExecuted == 0 && millis() - stop_timer > stop_timer_TIMEOUT){
onStopExecuted = 1;
setPosOff();
}
// No Ball Handler
if (currentInfo.state == RUN && millis() - noBallTimer > noBallTimeout) {
if(currentInfo.mode == DebugShot){
@ -128,6 +159,13 @@ void RobotTick() {
infoBlock.hwInfo.servos[SERVO_HORIZONTAL].def,
infoBlock.hwInfo.servos[SERVO_VERTICAL].min);
print("NO BALL!!!");
setPosOffDelay(1000);
// SetServoOFF(0);
// SetServoOFF(1);
// SetServoOFF(2);
}
// PreRun delay
@ -174,6 +212,12 @@ uint8_t prepareShot(uint8_t number) {
currentInfo.mode = ShotMode;
currentInfo.shot.shot = shot;
currentInfo.shot.indexGlobal = number;
currentInfo.shot.currentBallCount = 0;
// setPosDefault();
Shot* firstShot = &currentInfo.shot.shot;
setPos(firstShot->rotationAxial, firstShot->rotationHorizontal, firstShot->rotationVertical);
melody(melody_OK);
return 1;
} else {
@ -192,6 +236,18 @@ uint8_t prepareProgramm(uint8_t number) {
currentInfo.mode = ProgramMode;
currentInfo.program.program = program;
currentInfo.program.indexGlobal = number;
currentInfo.program.currentShotIndexLocal = 0;
currentInfo.program.currentBallCount = 0;
if (!loadShotFromProgram(&currentInfo.program)) {
print("loadShotFromProgram ERR\n");
melody(melody_Error);
return 0;
}
Shot* firstShot = &currentInfo.program.currentShot.shot;
setPos(firstShot->rotationAxial, firstShot->rotationHorizontal, firstShot->rotationVertical);
melody(melody_OK);
return 1;
} else {
@ -211,6 +267,24 @@ uint8_t prepareMacro(uint8_t number) {
currentInfo.mode = MacroMode;
currentInfo.macro.macro = macro;
currentInfo.macro.indexGlobal = number;
currentInfo.macro.currentProgramIndexLocal = 0;
currentInfo.macro.currentBallCount = 0;
if (!loadProgramFromMacro(&currentInfo.macro)) {
print("loadProgramFromMacro ERR\n");
melody(melody_Error);
return 0;
}
if (!loadShotFromProgram(&currentInfo.macro.currentProgram)) {
print("loadShotFromProgram in macro ERR\n");
melody(melody_Error);
return 0;
}
Shot* firstShot = &currentInfo.macro.currentProgram.currentShot.shot;
setPos(firstShot->rotationAxial, firstShot->rotationHorizontal, firstShot->rotationVertical);
melody(melody_OK);
return 1;
} else {
@ -534,7 +608,12 @@ void stopShooting() {
setScrewkSpeed(0);
setRollersSpeed(100, 100);
setPosDefault();
// setPosDefault();
setPosOffDelay(1000);
// SetServoOFF(0);
// SetServoOFF(1);
// SetServoOFF(2);
}
void shotApply(CurrentShot *currentShot) {
@ -543,9 +622,10 @@ void shotApply(CurrentShot *currentShot) {
shot->rotationVertical);
setRollersSpeed(shot->speedRollerTop, shot->speedRollerBottom);
setScrewkSpeed(shot->speedScrew);
noBallTimeout = MIN(
calculatePeriod( shot->speedScrew) * NOBALL_TIMEOUT_MULTIPLIER,
30000);
// noBallTimeout = MIN(
// calculatePeriod( shot->speedScrew) * NOBALL_TIMEOUT_MULTIPLIER,
// 30000);
noBallTimeout = NOBALL_TIMEOUT_HARD;
noBallTimer = millis();
////////////////////////// LED ////////////////////////////////////////