Skip to content

Commit 58c2e88

Browse files
author
Geoffroy Arenou
committed
Rewrite AX12 lib for adding servo, config and position
1 parent 44a8c50 commit 58c2e88

3 files changed

Lines changed: 22 additions & 18 deletions

File tree

include/Hardware_Config.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ namespace Hardware_Config
1616
{
1717
enum class ServoPosition
1818
{
19-
VL53Min = 0,
20-
VL53Pos = 145,
21-
VL53Max = 290,
22-
23-
BrasMin = 0,
24-
BrasPos = 145,
25-
BrasMax = 290,
26-
2719
Min = 0,
28-
Max = 290
20+
Pos1,
21+
Pos2,
22+
Pos3,
23+
Max,
24+
Count
2925
};
30-
26+
constexpr size_t ServoPositionCount = static_cast<size_t>(ServoPosition::Count);
27+
3128
enum class ServoID
3229
{
3330
VL53 = 1, // Servo pour bouger le VL53
@@ -40,7 +37,7 @@ namespace Hardware_Config
4037
constexpr size_t RX_SERVO = 18;
4138
constexpr size_t TX_SERVO = 17;
4239
constexpr size_t PIN_SERVO_DIR = 10;
43-
40+
4441
//******************** Pins IHM
4542
constexpr size_t PIN_SWITCH = 14;
4643
constexpr size_t PIN_TEAM = 13;
@@ -53,10 +50,9 @@ namespace Hardware_Config
5350

5451
//******************** Pins Enable Power
5552
constexpr size_t PIN_EN_MCU = 3;
56-
53+
5754
//******************** Pins TwoWire I²C
5855
constexpr size_t PIN_SDA = SDA;
5956
constexpr size_t PIN_SCL = SCL;
60-
6157
}
6258
#endif

src/main.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using namespace std;
55
using namespace Printer;
66
using namespace Hardware_Config;
7+
using namespace ServoAX12;
78

89
Adafruit_INA219 ina219;
910

@@ -13,13 +14,20 @@ void setup()
1314
println("PAMI Firmware");
1415

1516
Hardware::Initialisation();
17+
Power::EnablePower();
1618

1719
Motion::Initialisation();
1820

19-
ServoAX12::AddServo(ServoID::VL53, "VL53", ServoPosition::VL53Min, ServoPosition::VL53Max);
20-
ServoAX12::SetServoPosition(ServoID::VL53, ServoPosition::VL53Pos);
21-
ServoAX12::AddServo(ServoID::Bras, "Bras", ServoPosition::BrasMin, ServoPosition::BrasMax);
22-
ServoAX12::SetServoPosition(ServoID::Bras, ServoPosition::BrasPos);
21+
// Valeurs par défaut : { ax12Id, {positions[0]=min ... positions[n-1]=max}, count }
22+
// Modifiables via commande : AX12Config:<nom>:<field>:<valeur> (field: id|cnt|p0..p9)
23+
// Stockées en NVS, persistantes au redémarrage
24+
AddServo(ServoID::VL53, "VL53", ServoConfig(1, std::array<int32_t, MAX_SERVO_POSITIONS>{0, 100, 200, 290}, 4));
25+
ServoConfig servoConfig;
26+
servoConfig.ax12Id = 2;
27+
servoConfig.AddPosition(0, ServoPosition::Min); // min
28+
servoConfig.AddPosition(90, ServoPosition::Pos1); // pos1
29+
// We do not have to set all positions, only the ones we want to use. The count will be automatically updated to reflect the number of valid positions.
30+
AddServo(ServoID::Bras, "Bras", servoConfig);
2331

2432
TaskThread(TaskMatch, "TaskMatch", 20000, 15, 0);
2533
TaskThread(TaskTeleplot, "TaskTeleplot", 5000, 1, 0);

0 commit comments

Comments
 (0)