Skip to content

Commit 52441ae

Browse files
committed
move pins to Hardware
remove led_strip Subscribe to watchdog for loop task Add register to custom command Register AX12 custom command handler Add read num PAMI during BOOT phase Various ident Move to another lib for screen to take less update time
1 parent 7e129bb commit 52441ae

6 files changed

Lines changed: 77 additions & 78 deletions

File tree

include/Hardware_Config.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef HARDWARE_CONFIG_H
22
#define HARDWARE_CONFIG_H
33
#include <cstddef>
4+
#include <HardwareSerial.h>
5+
#include <pins_arduino.h>
46
// Copy this file to your include project folder and change it's name to Hardware_Config.h
57
// Then you can modify the one in your project at your convenience
68

@@ -33,6 +35,12 @@ namespace Hardware_Config
3335
BroadCast = 0xFE // Broadcast ID pour communiquer avec tous les servos
3436
};
3537

38+
//******************** Pins SERVO
39+
#define SERIAL_SERVO Serial1
40+
constexpr size_t RX_SERVO = 18;
41+
constexpr size_t TX_SERVO = 17;
42+
constexpr size_t PIN_SERVO_DIR = 10;
43+
3644
//******************** Pins IHM
3745
constexpr size_t PIN_SWITCH = 14;
3846
constexpr size_t PIN_TEAM = 13;
@@ -45,5 +53,10 @@ namespace Hardware_Config
4553

4654
//******************** Pins Enable Power
4755
constexpr size_t PIN_EN_MCU = 3;
56+
57+
//******************** Pins TwoWire I²C
58+
constexpr size_t PIN_SDA = SDA;
59+
constexpr size_t PIN_SCL = SCL;
60+
4861
}
4962
#endif

include/pins.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@
77
//******************** Pins Undefined
88
constexpr size_t PIN_11 = 11;
99

10-
//******************** Pins UART - Serial USB Debug
11-
// https://community.platformio.org/t/esp32-s3-native-usb-interface-and-serial-monitor-missing-first-messages/40377/10
12-
// Serial used for USB CDC
13-
#undef SERIAL_DEBUG
14-
#if (ARDUINO_USB_CDC_ON_BOOT && ARDUINO_USB_MODE) || WOKWI
15-
// HWCDC Serial;
16-
#define SERIAL_DEBUG Serial
17-
#else
18-
#error "USB Serial not working"
19-
#endif
20-
2110
//******************** Pins UART - Serial 0
2211
/* Do we need this ?
2312
#undef SOC_RX0
@@ -29,16 +18,6 @@ constexpr size_t PIN_11 = 11;
2918
//******************** Pins Enable Power
3019
constexpr size_t PIN_EN_MCU = 3;
3120

32-
//******************** Pins UART - Serial 1 Servo Dxl
33-
#undef RX1
34-
#undef TX1
35-
constexpr size_t RX_SERVO = 18;
36-
constexpr size_t TX_SERVO = 17;
37-
#define SERIAL_SERVO Serial1
38-
39-
//******************** Pins SERVO
40-
constexpr size_t PIN_SERVO_DIR = 10;
41-
4221
//******************** Pins Motors - Drivers
4322
//constexpr size_t PIN_STEP_M1 = 7;
4423
//constexpr size_t PIN_DIR_M1 = 6;
@@ -49,14 +28,6 @@ constexpr size_t PIN_DIR_M2 = 4;
4928
constexpr size_t PIN_STEP_M3 = 2;
5029
constexpr size_t PIN_DIR_M3 = 1;
5130

52-
//******************** Pins TwoWire I²C - Otos
53-
/*
54-
#undef SDA
55-
#define SDA 8
56-
#undef SCL
57-
#define SCL 9
58-
*/
59-
6031
//******************** Pins Selecteur PAMI
6132
constexpr size_t PIN_PAMI_NUM_1 = 7; // LSB
6233
constexpr size_t PIN_PAMI_NUM_2 = 6; // MSB

platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ lib_deps =
4949
;adafruit/Adafruit NeoPixel@^1.12.3
5050
fastled/FastLED@3.9.16
5151
robotis-git/Dynamixel2Arduino@^0.8.0
52-
adafruit/Adafruit SSD1306@^2.5.16
52+
;adafruit/Adafruit SSD1306@^2.5.16
53+
greiman/SSD1306Ascii@^1.3.5
5354
adafruit/Adafruit INA219@^1.2.3
5455
stm32duino/STM32duino VL53L8CX @ ^2.0.3
5556

src/main.cpp

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "main.h"
2+
#include <esp_task_wdt.h>
23

34
using namespace std;
45
using namespace Printer;
@@ -19,8 +20,7 @@ void setup()
1920
PowerMonitor::Initialisation();
2021

2122
Screen::Initialisation();
22-
Screen::Logo();
23-
23+
2424
IHM::Initialisation();
2525
Match::Initialisation();
2626

@@ -32,8 +32,9 @@ void setup()
3232
ServoAX12::SetServoPosition(ServoID::VL53, ServoPosition::VL53Pos);
3333
ServoAX12::AddServo(ServoID::Bras, "Bras", ServoPosition::BrasMin, ServoPosition::BrasMax);
3434
ServoAX12::SetServoPosition(ServoID::Bras, ServoPosition::BrasPos);
35-
36-
ToF_VL53L8CX::Initialisation();
35+
ESP32_Helper::RegisterCommandHandler("AX12", ServoAX12::HandleCommand, ServoAX12::PrintCommandHelp);
36+
37+
//ToF_VL53L8CX::Initialisation();
3738

3839
// delay(2000);
3940

@@ -55,7 +56,7 @@ void setup()
5556
// }
5657

5758
TaskThread(TaskMatch, "TaskMatch", 20000, 15, 0);
58-
TaskThread(TaskTeleplot, "TaskTeleplot", 5000, 1, 0);
59+
//TaskThread(TaskTeleplot, "TaskTeleplot", 5000, 1, 0);
5960
TaskThread(TaskHandleCommand, "TaskHandleCommand", 10000, 15, 0);
6061

6162
TaskThread(TaskLoop, "TaskLoop", 20000, 20, 1);
@@ -73,43 +74,60 @@ void TaskLoop(void *pvParameters)
7374
{
7475
Chrono chrono("Loop", 10000);
7576

77+
// Ajouter la tâche courante au WDT système
78+
esp_task_wdt_add(NULL);
79+
7680
while (true)
7781
{
7882
chrono.Start();
7983
try
80-
{
81-
if (Match::matchState != Match::State::MATCH_STOP && Match::matchState != Match::State::MATCH_END && (motor_D.isRunning() || motor_G.isRunning()))
82-
{
83-
enableMotors();
84-
updateMotors();
85-
}
86-
else
87-
{
88-
disableMotors();
89-
}
90-
}
91-
catch (const std::exception &e)
84+
{
85+
if (Match::matchState != Match::State::MATCH_STOP && Match::matchState != Match::State::MATCH_END && (motor_D.isRunning() || motor_G.isRunning()))
86+
{
87+
enableMotors();
88+
updateMotors();
89+
}
90+
else
91+
{
92+
disableMotors();
93+
}
94+
}
95+
catch (const std::exception &e)
9296
{
9397
printError(e.what());
9498
}
9599
if (chrono.Check())
96100
{
97101
printChrono(chrono);
98102
}
103+
104+
// Reset le watchdog pour empêcher le reset de l'esp32
105+
esp_task_wdt_reset();
99106
vTaskDelay(1);
100107
}
101-
// led_strip.update();
102108
}
103109

104110
void TaskMatch(void *pvParameters)
105111
{
106112
println("Start TaskMatch");
107-
Chrono chrono("MainMatch", 1000);
113+
Chrono chrono("MainMatch", 1000);
108114
while (1)
109115
{
110-
chrono.Start();
116+
chrono.Start();
111117
try
112118
{
119+
if(Match::matchState == Match::State::MATCH_BOOT)
120+
{
121+
// Lecture do codage du numéro de PAMI
122+
int numPamiTmp = ReadNumPami();
123+
if (numPamiTmp != numPami)
124+
{
125+
numPami = numPamiTmp;
126+
println("N° PAMI : %i", numPami);
127+
Wifi_Helper::SetLocalIP("192.168.137." + String(100 + numPami + 1));
128+
}
129+
}
130+
113131
// En attente de retrait de la tirette pour démarrer le match
114132
if (Match::matchState == Match::State::MATCH_WAIT)
115133
{
@@ -331,13 +349,13 @@ chrono.Start();
331349
// Wait for reset
332350
if (IHM::switchMode == 0 && IHM::tirettePresent == 0)
333351
Match::matchState = Match::State::MATCH_BOOT;
334-
}
352+
}
335353
}
336354
catch (std::exception const &e)
337355
{
338356
printError(e.what());
339357
}
340-
if (chrono.Check())
358+
if (chrono.Check())
341359
{
342360
printChrono(chrono);
343361
}
@@ -349,29 +367,29 @@ Pose MapBoundaries[] = {{0, 0, 0}, {0, 2000, 0}, {3000, 2000, 0}, {3000, 0, 0}};
349367

350368
void TaskTeleplot(void *pvParameters)
351369
{
352-
int lastMatchTime = 0;
370+
int lastMatchTime = 0;
353371
println("Start TaskTeleplot");
354-
Timeout teleplotTO;
355-
teleplotTO.Start(500);
372+
Timeout teleplotTO;
373+
teleplotTO.Start(50);
356374
Chrono chrono("Teleplot", 1000);
357375

358376
while (true)
359377
{
360-
chrono.Start();
378+
chrono.Start();
361379
try
362380
{
363381
if (teleplotTO.IsTimeOut() && Match::matchState != Match::State::MATCH_RUN)
364382
{
365-
// Printer::teleplot("pos", getCurrentPose());
366-
// Printer::teleplot("ang", (int)(getCurrentPose().h));
383+
//Printer::teleplot("pos", getCurrentPose());
384+
//Printer::teleplot("ang", (int)(getCurrentPose().h));
367385

368386
// Countdown
369387
if (lastMatchTime != (int)(Match::getMatchTimeSec()))
370388
{
371-
// println("Match Time : %i", (int)(Match::getMatchTimeSec()));
389+
println("Match Time : %i", (int)(Match::getMatchTimeSec()));
372390
lastMatchTime = (int)(Match::getMatchTimeSec());
373391
}
374-
}
392+
}
375393
}
376394
catch (const std::exception &e)
377395
{
@@ -381,7 +399,7 @@ chrono.Start();
381399
{
382400
printChrono(chrono);
383401
}
384-
vTaskDelay(10);
402+
vTaskDelay(50);
385403
}
386404
}
387405

@@ -400,14 +418,14 @@ void TaskHandleCommand(void *pvParameters)
400418
{
401419
Command cmd = ESP32_Helper::GetCommand();
402420

403-
if (cmd.cmd.startsWith("Pos"))
421+
if (cmd.cmdStartsWith("Pos"))
404422
{
405423
print("Pos : x=%f", getCurrentPose().x);
406424
print(" y=%f", getCurrentPose().y);
407425
print(" h=%f", getCurrentPose().h);
408426
println();
409427
}
410-
if (cmd.cmd.startsWith("Speed"))
428+
if (cmd.cmdStartsWith("Speed"))
411429
{
412430
// print("Speed : ", cmd);
413431
if (cmd.size > 0)
@@ -419,7 +437,7 @@ void TaskHandleCommand(void *pvParameters)
419437
println("Motor D speed: %f", motor_D.maxSpeed());
420438
println("Motor G speed: %f", motor_G.maxSpeed());
421439
}
422-
if (cmd.cmd.startsWith("Accel"))
440+
if (cmd.cmdStartsWith("Accel"))
423441
{
424442
// print("Accel : ", cmd);
425443
if (cmd.size > 0)
@@ -431,7 +449,7 @@ void TaskHandleCommand(void *pvParameters)
431449
println("Motor D accel: %f", motor_D.acceleration());
432450
println("Motor G accel: %f", motor_G.acceleration());
433451
}
434-
if (cmd.cmd.startsWith("Pulse"))
452+
if (cmd.cmdStartsWith("Pulse"))
435453
{
436454
// print("Pulse : ", cmd);
437455
if (cmd.size > 0)
@@ -441,7 +459,7 @@ void TaskHandleCommand(void *pvParameters)
441459
}
442460
println("setMinPulseWidth: %i", cmd.data[0]);
443461
}
444-
if (cmd.cmd.startsWith("Go"))
462+
if (cmd.cmdStartsWith("Go"))
445463
{
446464
// print("Go : ", cmd);
447465
if (cmd.size == 1)
@@ -451,13 +469,13 @@ void TaskHandleCommand(void *pvParameters)
451469
if (cmd.size == 3)
452470
goTo(cmd.data[0], cmd.data[1], cmd.data[2]);
453471
}
454-
if (cmd.cmd.startsWith("Turn"))
472+
if (cmd.cmdStartsWith("Turn"))
455473
{
456474
// print("Turn : ", cmd);
457475
if (cmd.size > 0)
458476
turn(cmd.data[0]);
459477
}
460-
if (cmd.cmd.startsWith("Motor"))
478+
if (cmd.cmdStartsWith("Motor"))
461479
{
462480
println("Motor D:");
463481
println("speed: %f", motor_D.speed());
@@ -476,7 +494,7 @@ void TaskHandleCommand(void *pvParameters)
476494
// println("computeNewSpeed:",(long)motor_G.computeNewSpeed());
477495
println("-----");
478496
}
479-
if (cmd.cmd.startsWith("Blink"))
497+
if (cmd.cmdStartsWith("Blink"))
480498
{
481499
//Blink:0
482500
//Blink:1
@@ -486,7 +504,7 @@ void TaskHandleCommand(void *pvParameters)
486504
println("Blink : %i", IHM::useBlink);
487505
}
488506
}
489-
if (cmd.cmd.startsWith("RGB"))
507+
if (cmd.cmdStartsWith("RGB"))
490508
{
491509
//RGB:0:255:0
492510
if (cmd.size == 3)
@@ -498,7 +516,7 @@ void TaskHandleCommand(void *pvParameters)
498516
// println(" ", led[0].blue);
499517
}
500518
}
501-
if (cmd.cmd.startsWith("HSV"))
519+
if (cmd.cmdStartsWith("HSV"))
502520
{
503521
//HSV:0:255:255
504522
// if (cmd.size == 1)
@@ -514,10 +532,6 @@ void TaskHandleCommand(void *pvParameters)
514532
// print(" ", led[0].green);
515533
// println(" ", led[0].blue);
516534
}
517-
if (cmd.cmd.startsWith("AX12"))
518-
{
519-
ServoAX12::HandleCommand(cmd);
520-
}
521535
}
522536
}
523537
catch (std::exception const &e)
@@ -529,6 +543,6 @@ if (cmd.cmd.startsWith("AX12"))
529543
{
530544
printChrono(chrono);
531545
}
532-
vTaskDelay(10);
546+
vTaskDelay(10);
533547
}
534548
}

0 commit comments

Comments
 (0)