Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Add paramters to allow reversal of motor direction. (#13)
Browse files Browse the repository at this point in the history
This can come in handy since it not always clear from the start if the left motor is attached to motor 0 or if the right motor is attached to motor 0.
  • Loading branch information
aentinger authored Nov 14, 2023
1 parent bb56238 commit c3e6da0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions CyphalRobotController07-CAN-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ static uint16_t update_period_ms_motor0_bemf = 1000;
static uint16_t update_period_ms_motor1_bemf = 1000;
static uint16_t timeout_ms_motor0 = 1000;
static uint16_t timeout_ms_motor1 = 1000;
static bool reverse_motor_0 = false;
static bool reverse_motor_1 = false;
static unsigned long prev_motor0_update = 0;
static unsigned long prev_motor1_update = 0;

Expand Down Expand Up @@ -263,6 +265,8 @@ const auto reg_rw_crc07_update_period_ms_motor0_bemf = node_registry->ex
const auto reg_rw_crc07_update_period_ms_motor1_bemf = node_registry->expose("crc07.update_period_ms.motor1bemf", {true}, update_period_ms_motor1_bemf);
const auto reg_rw_crc07_timeout_ms_motor0 = node_registry->expose("crc07.timeout_ms.motor0", {true}, timeout_ms_motor0);
const auto reg_rw_crc07_timeout_ms_motor1 = node_registry->expose("crc07.timeout_ms.motor1", {true}, timeout_ms_motor1);
const auto reg_rw_crc07_reverse_motor0 = node_registry->expose("crc07.motor_0.reverse", {true}, reverse_motor_0);
const auto reg_rw_crc07_reverse_motor1 = node_registry->expose("crc07.motor_1.reverse", {true}, reverse_motor_1);

#endif /* __GNUC__ >= 11 */

Expand Down Expand Up @@ -355,7 +359,11 @@ void setup()
port_id_motor0,
[](uavcan::primitive::scalar::Integer16_1_0 const & msg)
{
mot0.pwm(msg.value);
if (reverse_motor_0)
mot0.pwm(-1 * msg.value);
else
mot0.pwm(msg.value);

prev_motor0_update = millis();
});

Expand All @@ -364,7 +372,11 @@ void setup()
port_id_motor1,
[](uavcan::primitive::scalar::Integer16_1_0 const & msg)
{
mot1.pwm(msg.value);
if (reverse_motor_1)
mot1.pwm(-1 * msg.value);
else
mot1.pwm(msg.value);

prev_motor1_update=millis();
});

Expand Down

0 comments on commit c3e6da0

Please sign in to comment.