led and rc

This commit is contained in:
2024-09-30 00:26:00 +03:00
parent 7095a09a1d
commit 6c3af6fbb5
15 changed files with 634 additions and 221 deletions

View File

@ -60,6 +60,7 @@ void robotStateStop() {
long map(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
float calculatePeriod(int pwm_value) { // Функция для расчета периода вылета мяча на основе ШИМ
// Коэффициенты из аппроксимации
float a = 100382.255;
@ -72,6 +73,8 @@ float calculatePeriod(int pwm_value) { // Функция для расчета
}
void Robot_INIT() {
led_init();
// led_PingPong_start(7, 12);
memset(&currentInfo, 0x00, sizeof(currentInfo));
// NULL
currentInfo.shot.indexGlobal = 0xFF;
@ -79,8 +82,8 @@ void Robot_INIT() {
currentInfo.macro.indexGlobal = 0xFF;
initPCA9685();
EEPROM_INIT();
setPosDefault();
UART3_START();
led_init();
for (int i = 0; i < 10; ++i) {
// if ((i&1U)!=1 || i > 4) for test
@ -90,10 +93,15 @@ void Robot_INIT() {
}
}
led_clear();
HAL_Delay(100);
for (int i = 7; i < 13; ++i) {
led_blink_num(i, 100, 15);
}
// for (int i = 9; i <= 9; ++i) {
// led_blink_num(i, 100, 15);
// }
// for (int i = 0; i <= 100; ++i) {
// led_progressbar(0, 19, i);
// HAL_Delay(10);
// }
}
@ -109,6 +117,11 @@ void RobotTick() {
// No Ball Handler
if (currentInfo.state == RUN && millis() - noBallTimer > noBallTimeout) {
robotStateStop();
led_clear();
for (int i = 7; i <= 12; ++i) {
led_blink_num(i, 250, 0xFFFF-1);
}
isDelayTimerRun = 0;
setScrewkSpeed(0);
setRollersSpeed(100, 100);
setPos(infoBlock.hwInfo.servos[SERVO_AXIAL].def,
@ -131,8 +144,16 @@ void RobotTick() {
uint32_t intervalStep = currentInfo.startDelay / NUMLEDS;
if (elapsedTime - lastIndicationTime >= intervalStep) {
lastIndicationTime = elapsedTime;
uint8_t progress = (elapsedTime * 100) / currentInfo.startDelay;
// indicate(progress);
uint8_t progress = 100 - (elapsedTime * 100) / currentInfo.startDelay;
uint8_t ledProgress = map(progress, 0, 70, 0, 100);
if (ledProgress > 30) {
led_progressbar(9, 0, progress);
led_progressbar(10, 19, progress);
} else {
led_progressbar(9, 0, 100);
led_progressbar(10, 19, 100);
}
print("delay: ");
printNumber(progress);
print("\n");
@ -142,6 +163,7 @@ void RobotTick() {
}
uint8_t prepareShot(uint8_t number) {
stopShooting();
Shot shot;
memset(&shot, 0x00, sizeof(shot));
getShot(number, &shot);
@ -157,6 +179,7 @@ uint8_t prepareShot(uint8_t number) {
}
}
uint8_t prepareProgramm(uint8_t number) {
stopShooting();
Program program;
memset(&program, 0x00, sizeof(program));
getProg(number, &program);
@ -173,6 +196,7 @@ uint8_t prepareProgramm(uint8_t number) {
}
uint8_t prepareMacro(uint8_t number) {
stopShooting();
Macro macro;
memset(&macro, 0x00, sizeof(macro));
getMacro(number, &macro);
@ -478,6 +502,9 @@ void startShooting(uint32_t delayTime) {
}
void stopShooting() {
led_clear();
isDelayTimerRun = 0;
robotStateStop();
setScrewkSpeed(0);
setRollersSpeed(100, 100);
@ -494,6 +521,12 @@ void shotApply(CurrentShot *currentShot) {
calculatePeriod( shot->speedScrew) * NOBALL_TIMEOUT_MULTIPLIER,
30000);
noBallTimer = millis();
////////////////////////// LED ////////////////////////////////////////
led_clear();
led_showSpeed(shot->speedRollerTop, shot->speedRollerBottom);
/////////////////////////////////////////////////////////////////////////////
print("Global indx ");
printNumber(currentShot->indexGlobal);
print("\nisExist ");