mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-06-27 20:59:36 +00:00
fix rc debug and ir logic
This commit is contained in:
@ -45,4 +45,6 @@ enum IR_CMD_LIST {
|
||||
IR_ENGINE_DOWM_DEC = 17
|
||||
};
|
||||
|
||||
void IR_CMD_Clear();
|
||||
|
||||
#endif /* INC_IR_CMD_HANDLER_H_ */
|
||||
|
@ -24,6 +24,7 @@ typedef enum ServoMap{
|
||||
|
||||
typedef enum Mode {
|
||||
NoneMode, ShotMode, ProgramMode, MacroMode,
|
||||
DebugShot,
|
||||
} Mode;
|
||||
|
||||
typedef enum State{
|
||||
@ -85,6 +86,7 @@ uint8_t prepareMacro(uint8_t number);
|
||||
|
||||
void startShooting(uint32_t delayTime);
|
||||
void stopShooting();
|
||||
void pauseShooting();
|
||||
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max);
|
||||
|
||||
|
@ -135,6 +135,7 @@ MemoryStatus saveInfoBlock() {
|
||||
}
|
||||
|
||||
MemoryStatus getInfoBlock() {
|
||||
memset(&infoBlock, 0x00, sizeof(InfoBlock));
|
||||
MemoryStatus status = FLASH_ReadBlock(START_ADR_STAT, 0,
|
||||
(uint8_t*) &infoBlock, sizeof(InfoBlock));
|
||||
|
||||
@ -155,6 +156,7 @@ MemoryStatus saveShot(unsigned char number, Shot *shot) {
|
||||
|
||||
MemoryStatus getShot(unsigned char number, Shot *shot) {
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
memset(shot, 0x00, sizeof(Shot));
|
||||
if (FLASH_ReadBlock(START_ADR_SHOT, number, (uint8_t*) shot, SHOT_BLOCKSIZE)
|
||||
!= EEPROM_OK) {
|
||||
return EEPROM_FAIL;
|
||||
@ -198,6 +200,7 @@ MemoryStatus saveProg(unsigned char number, Program *prog) {
|
||||
}
|
||||
|
||||
MemoryStatus getProg(unsigned char number, Program *prog) {
|
||||
memset(prog, 0x00, sizeof(Program));
|
||||
if (FLASH_ReadBlock(START_ADR_PROGRAM, number, (uint8_t*) prog,
|
||||
PROGRAM_BLOCKSIZE) != EEPROM_OK) {
|
||||
return EEPROM_FAIL;
|
||||
@ -245,6 +248,7 @@ MemoryStatus saveMacro(unsigned char number, Macro *macro) {
|
||||
}
|
||||
|
||||
MemoryStatus getMacro(unsigned char number, Macro *macro) {
|
||||
memset(macro, 0x00, sizeof(Macro));
|
||||
if (FLASH_ReadBlock(START_ADR_MACRO, number, (uint8_t*) macro,
|
||||
MACRO_BLOCKSIZE) != EEPROM_OK) {
|
||||
return EEPROM_FAIL;
|
||||
@ -364,7 +368,7 @@ MemoryStatus FLASH_ReadBlock(uint16_t startAddr, uint8_t number,
|
||||
return EEPROM_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
memset(readData, 0x00, dataSize);
|
||||
// memset(readData, 0x00, !!!!dataSize!!!!);
|
||||
|
||||
uint16_t blockAddr16 = (uint16_t) (startAddr
|
||||
+ (uint16_t) (number * dataSize));
|
||||
|
@ -74,6 +74,8 @@ uint8_t speedDown = 100;
|
||||
|
||||
void IR_Home_Process() {
|
||||
InputHandler = IR_Home_Process;
|
||||
uint8_t isshotRcOverride = currentInfo.mode == ShotMode
|
||||
&& currentInfo.state == RUN;
|
||||
switch (data.command) {
|
||||
case IR_SHOT:
|
||||
paramEnter(onSelectShot);
|
||||
@ -96,106 +98,104 @@ void IR_Home_Process() {
|
||||
|
||||
case IR_PAUSE:
|
||||
if (currentInfo.state == RUN) {
|
||||
currentInfo.state = PAUSE;
|
||||
pauseShooting();
|
||||
}
|
||||
break;
|
||||
|
||||
case IR_START:
|
||||
if (currentInfo.state == PAUSE) {
|
||||
currentInfo.state = RUN;
|
||||
switch (currentInfo.mode) {
|
||||
case DebugShot:
|
||||
case ShotMode:
|
||||
shotApply(¤tInfo.shot);
|
||||
break;
|
||||
case ProgramMode:
|
||||
shotApply(¤tInfo.program.currentShot);
|
||||
break;
|
||||
case MacroMode:
|
||||
shotApply(¤tInfo.macro.currentProgram.currentShot);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case IR_ESC: {
|
||||
// if (EEPROM_EARSE() != EEPROM_OK) {
|
||||
// char errorMsg[] = "Error EEPROM_EARSE\n\n";
|
||||
// CDC_Transmit_FS((uint8_t*) errorMsg, strlen(errorMsg));
|
||||
// } else {
|
||||
// char doneMsg[] = "EEPROM_EARSE Done\n\n";
|
||||
// CDC_Transmit_FS((uint8_t*) doneMsg, strlen(doneMsg));
|
||||
// }
|
||||
IR_CMD_Clear();
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_DEBUG: {
|
||||
if (!(currentInfo.state == STOP || currentInfo.state == PAUSE))
|
||||
break;
|
||||
|
||||
switch (currentInfo.mode) {
|
||||
case ShotMode:
|
||||
currentInfo.mode = DebugShot;
|
||||
currentInfo.state = RUN;
|
||||
shotApply(¤tInfo.shot);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_NUM_1:
|
||||
|
||||
break;
|
||||
case IR_NUM_2:
|
||||
break;
|
||||
case IR_NUM_3:
|
||||
|
||||
break;
|
||||
|
||||
case IR_NUM_7:
|
||||
break;
|
||||
case IR_NUM_8:
|
||||
break;
|
||||
case IR_NUM_9:
|
||||
break;
|
||||
|
||||
case IR_NUM_5:
|
||||
break;
|
||||
|
||||
case IR_STOP: {
|
||||
speedUP = 100;
|
||||
speedDown = 100;
|
||||
screwSpeed = 0;
|
||||
print("***********************");
|
||||
stopShooting();
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_TEMPO_INC:
|
||||
if (currentInfo.shot.shot.speedScrew < 100) {
|
||||
if (isshotRcOverride && currentInfo.shot.shot.speedScrew < 100) {
|
||||
currentInfo.shot.shot.speedScrew++;
|
||||
shotApply(¤tInfo.shot);
|
||||
// led_progressbar(10, 19, currentInfo.shot.shot.speedScrew); //todo: led_progressbarTMP
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_TEMPO_DEC:
|
||||
if (currentInfo.shot.shot.speedScrew > 0) {
|
||||
if (isshotRcOverride && currentInfo.shot.shot.speedScrew > 0) {
|
||||
currentInfo.shot.shot.speedScrew--;
|
||||
shotApply(¤tInfo.shot);
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_UP_INC:
|
||||
if (currentInfo.shot.shot.speedRollerTop < 200) {
|
||||
if (isshotRcOverride && currentInfo.shot.shot.speedRollerTop < 200) {
|
||||
currentInfo.shot.shot.speedRollerTop++;
|
||||
shotApply(¤tInfo.shot);
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_UP_DEC:
|
||||
if (currentInfo.shot.shot.speedRollerTop > 0) {
|
||||
if (isshotRcOverride && currentInfo.shot.shot.speedRollerTop > 0) {
|
||||
currentInfo.shot.shot.speedRollerTop--;
|
||||
shotApply(¤tInfo.shot);
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_DOWM_INC:
|
||||
if (currentInfo.shot.shot.speedRollerBottom < 200) {
|
||||
if (isshotRcOverride && currentInfo.shot.shot.speedRollerBottom < 200) {
|
||||
currentInfo.shot.shot.speedRollerBottom++;
|
||||
shotApply(¤tInfo.shot);
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_ENGINE_DOWM_DEC:
|
||||
if (currentInfo.shot.shot.speedRollerBottom > 0) {
|
||||
if (isshotRcOverride && currentInfo.shot.shot.speedRollerBottom > 0) {
|
||||
currentInfo.shot.shot.speedRollerBottom--;
|
||||
shotApply(¤tInfo.shot);
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
}
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
@ -293,13 +293,19 @@ void IR_Home_Process() {
|
||||
|
||||
void IR_ShootingStart() {
|
||||
InputHandler = IR_ShootingStart;
|
||||
|
||||
switch (data.command) {
|
||||
case IR_START:
|
||||
startShooting(infoBlock.hwInfo.timings.preRun);
|
||||
break;
|
||||
default:
|
||||
InputHandler();
|
||||
break;
|
||||
case IR_START: {
|
||||
InputHandler = IR_Home_Process;
|
||||
startShooting(infoBlock.hwInfo.timings.preRun);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
InputHandler = IR_Home_Process;
|
||||
IR_Home_Process();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,8 @@ void IR_CMD_Handler() {
|
||||
lastRepeatTime = millis(); // Обновляем время последнего вызова
|
||||
// uint8_t blinkPeriod = 10;
|
||||
led_writeMirror(9, 1);
|
||||
|
||||
HAL_Delay(1);
|
||||
led_writeMirror(9,0);
|
||||
|
||||
onHoldRepeat(); // Вызываем функцию при удержании
|
||||
|
||||
@ -129,16 +130,13 @@ void IR_CMD_Clear() {
|
||||
inputInProgerss = 0;
|
||||
digitInputInProgerss = 0;
|
||||
inputParam = NULL_NumberParam;
|
||||
// SetShiftReg_inline(0, 0xff, 0);
|
||||
}
|
||||
|
||||
void IR_ParamEnter() {
|
||||
// SetShiftReg_inline(0x03, 0, 0);
|
||||
if (0 <= data.command && data.command <= 9) {
|
||||
if (digitInputInProgerss) {
|
||||
inputParam = inputParam * 10; // dec shift << 1
|
||||
inputParam += (data.command + 1) % 10;
|
||||
// SetShiftReg_inline(0xF0, 0, 0);
|
||||
} else {
|
||||
inputParam = (data.command + 1) % 10;
|
||||
}
|
||||
@ -151,13 +149,16 @@ void IR_ParamEnter() {
|
||||
if(inputParam != NULL_NumberParam){
|
||||
print("Enter: ");
|
||||
printNumber(inputParam);
|
||||
// SetShiftReg_inline(0, 0, inputParam);
|
||||
onParamEnter();
|
||||
}
|
||||
inputParam = NULL_NumberParam;
|
||||
digitInputInProgerss = 0;
|
||||
break;
|
||||
|
||||
case IR_START:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
IR_Home_Process();
|
||||
break;
|
||||
|
@ -228,12 +228,10 @@ void led_progressbar_(uint8_t fromLed, uint8_t toLed, uint8_t progress, void (*l
|
||||
ledBlinkInfo[ledIndex].count = 0;
|
||||
|
||||
if (i < ledsToLight) {
|
||||
// Включаем светодиод, если он не включен
|
||||
if (!led_getState(ledMap.ALL[ledIndex])) {
|
||||
led_writeFunc(ledIndex, 1); // Используем переданную функцию для включения
|
||||
}
|
||||
} else {
|
||||
// Выключаем светодиод, если он включен
|
||||
if (led_getState(ledMap.ALL[ledIndex])) {
|
||||
led_writeFunc(ledIndex, 0); // Используем переданную функцию для выключения
|
||||
}
|
||||
@ -270,6 +268,7 @@ void led_PingPong_start(uint8_t fromLed, uint8_t toLed) {
|
||||
ledPingPongInfo.writeCallback = led_write;
|
||||
led_PingPong_start_(fromLed, toLed);
|
||||
}
|
||||
|
||||
void led_PingPong_start_(uint8_t fromLed, uint8_t toLed){
|
||||
if (fromLed < toLed) {
|
||||
ledPingPongInfo.start = fromLed;
|
||||
|
@ -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();
|
||||
|
@ -517,7 +517,7 @@ void UART3_ReadStatistics(uint8_t *dataPtr, uint8_t len) {
|
||||
} StatusStruct;
|
||||
|
||||
StatusStruct res;
|
||||
uint8_t isRun = currentInfo.state == RUN;
|
||||
uint8_t isRun = currentInfo.state == RUN || currentInfo.state == PRERUN_WAIT;
|
||||
res.status = isRun;
|
||||
|
||||
res.shot_number = 0xFF;
|
||||
|
@ -174,7 +174,36 @@ int main(void)
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
|
||||
const char* getStateString(State state) {
|
||||
switch (state) {
|
||||
case STOP:
|
||||
return "STOP";
|
||||
case RUN:
|
||||
return "RUN";
|
||||
case PAUSE:
|
||||
return "PAUSE";
|
||||
case PRERUN_WAIT:
|
||||
return "PRERUN_WAIT";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
const char* getModeString(Mode mode) {
|
||||
switch (mode) {
|
||||
case NoneMode:
|
||||
return "NoneMode";
|
||||
case ShotMode:
|
||||
return "ShotMode";
|
||||
case ProgramMode:
|
||||
return "ProgramMode";
|
||||
case MacroMode:
|
||||
return "MacroMode";
|
||||
case DebugShot:
|
||||
return "DebugShot";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
while (1) {
|
||||
|
||||
IR_CMD_Handler();
|
||||
@ -194,13 +223,18 @@ int main(void)
|
||||
// extern uint32_t vsk2;
|
||||
// extern uint16_t timing1;
|
||||
// extern uint16_t timing2;
|
||||
// // Форматируем строку для вывода timing1, timing2, vsk1, vsk2
|
||||
// sprintf(buffer,
|
||||
// "timing1: %u ms, timing2: %u ms, vsk1: %u RPM, vsk2: %u RPM\n",
|
||||
// timing1, timing2, vsk1, vsk2);
|
||||
//
|
||||
// // Отправляем строку через CDC (USB)
|
||||
// CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||
|
||||
char buffer[64];
|
||||
sprintf(buffer, "Current mode: %s, Current state: %s\n",
|
||||
getModeString(currentInfo.mode),
|
||||
getStateString(currentInfo.state));
|
||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
|
Reference in New Issue
Block a user