implement remaining commands

This commit is contained in:
Leonetienne
2025-12-14 19:27:21 +01:00
parent 95bd2a37ae
commit fd218f0358
2 changed files with 23 additions and 4 deletions
+22 -3
View File
@@ -80,9 +80,28 @@ void MainLoop::update() noexcept
uart.getNextPacket(packet);
CommandParser::Command command = CommandParser::getInstance().parsePacket(packet);
if (command.instruction == CommandParser::Command::TYPE::MOVE_ABSOLUTE) {
const float moveTarget = (float)command.args[1] / 10.0f;
motors[command.args[0]].moveTo(moveTarget);
switch (command.instruction) {
// Scoping to keep variables local
case CommandParser::Command::TYPE::MOVE_ABSOLUTE: {
AdafruitServoMotor& motor = motors[command.args[0]];
const float moveTarget = (float)command.args[1] / 10.0f;
motor.moveTo(moveTarget);
}
break;
case CommandParser::Command::TYPE::MOVE_RELATIVE: {
AdafruitServoMotor& motor = motors[command.args[0]];
const float moveDelta = (float)command.args[1] / 10.0f;
motor.moveTo(motor.getPosition() + moveDelta);
}
break;
case CommandParser::Command::TYPE::RESET_POSITIONS: {
for (uint8_t i = 0; i < 3; i++) {
motors[i].moveTo(0);
motors[i].commitMoveImmediately();
}
}
break;
}
}
}