From 53e42e57f005294f8b9129cd4777454d075916d7 Mon Sep 17 00:00:00 2001 From: woozydragon Date: Tue, 24 Oct 2023 20:52:46 -0400 Subject: [PATCH] fixed semicolon --- .../firmware/teensy_main/teensy_main.ino | 110 +++++++++--------- 1 file changed, 54 insertions(+), 56 deletions(-) diff --git a/lunabot_embedded/firmware/teensy_main/teensy_main.ino b/lunabot_embedded/firmware/teensy_main/teensy_main.ino index 50ae3f1b..8f5a2428 100644 --- a/lunabot_embedded/firmware/teensy_main/teensy_main.ino +++ b/lunabot_embedded/firmware/teensy_main/teensy_main.ino @@ -7,8 +7,7 @@ #define TX_PERIOD 10 // ms #define ENC_TRANSFER_PERIOD 1000 // microsec -#define CURR_UPDATE_PERIOD 8 // ms - +#define CURR_UPDATE_PERIOD 8 // ms RobotState state = RobotState_init_zero; RobotEffort effort = RobotEffort_init_zero; @@ -23,73 +22,72 @@ bit0: cannot recv uint8_t flags = 0; void recv() { - /* Create a stream that reads from the buffer. */ - pb_istream_t stream = pb_istream_from_buffer(buffer, sizeof(buffer)); + /* Create a stream that reads from the buffer. */ + pb_istream_t stream = pb_istream_from_buffer(buffer, sizeof(buffer)); - /* Now we are ready to decode the message. */ - pb_decode(&stream, RobotEffort_fields, &effort); + /* Now we are ready to decode the message. */ + pb_decode(&stream, RobotEffort_fields, &effort); - actuation::cb(effort.lead_screw, effort.lin_act); - drivetrain::cb(effort.left_drive, effort.right_drive); - deposition::cb(effort.deposit); - excavation::cb(effort.excavate); + actuation::cb(effort.lead_screw, effort.lin_act); + drivetrain::cb(effort.left_drive, effort.right_drive); + deposition::cb(effort.deposit); + excavation::cb(effort.excavate); } void send() { - actuation::update(state.act_right_curr, state.lead_screw_curr, - state.act_ang, state.lead_screw_ang); - drivetrain::update(state.drive_left_curr, state.drive_right_curr, - state.drive_left_ang, state.drive_right_ang); - deposition::update(state.dep_curr, state.dep_ang); - - excavation::update(state.exc_curr); - - uwb::update(state.uwb_dist_0, state.uwb_dist_1, state.uwb_dist_2) - - pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); - pb_encode(&stream, RobotState_fields, &state); + actuation::update(state.act_right_curr, state.lead_screw_curr, state.act_ang, + state.lead_screw_ang); + drivetrain::update(state.drive_left_curr, state.drive_right_curr, + state.drive_left_ang, state.drive_right_ang); + deposition::update(state.dep_curr, state.dep_ang); + + excavation::update(state.exc_curr); + + uwb::update(state.uwb_dist_0, state.uwb_dist_1, state.uwb_dist_2); + + pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); + pb_encode(&stream, RobotState_fields, &state); } IntervalTimer enc_timer; void setup() { - STMotorInterface::init_serial(ST_SERIAL, ST_BAUD_RATE); - CurrentSensorBus::init_ads1115(); - EncoderBus::init(); - - enc_timer.begin(EncoderBus::transfer, ENC_TRANSFER_PERIOD); - - // disable timeout - MC1.setTimeout(0); - MC2.setTimeout(0); - MC3.setTimeout(0); - MC4.setTimeout(0); - - // set to fast ramp (1-10 - fast, 11-20 slow, 20-80 intermed) - MC1.setRamping(1); - MC2.setRamping(1); - MC3.setRamping(1); - MC4.setRamping(1); + STMotorInterface::init_serial(ST_SERIAL, ST_BAUD_RATE); + CurrentSensorBus::init_ads1115(); + EncoderBus::init(); + + enc_timer.begin(EncoderBus::transfer, ENC_TRANSFER_PERIOD); + + // disable timeout + MC1.setTimeout(0); + MC2.setTimeout(0); + MC3.setTimeout(0); + MC4.setTimeout(0); + + // set to fast ramp (1-10 - fast, 11-20 slow, 20-80 intermed) + MC1.setRamping(1); + MC2.setRamping(1); + MC3.setRamping(1); + MC4.setRamping(1); } elapsedMillis ms_until_send; elapsedMillis ms_curr_update; void loop() { - int n; - n = RawHID.recv(buffer, 0); // 0 timeout = do not wait - if (n > 0) { - recv(); - } - - if (ms_until_send > TX_PERIOD) { - ms_until_send -= TX_PERIOD; - send(); - n = RawHID.send(buffer, 0); - } - - if (ms_curr_update > CURR_UPDATE_PERIOD) { - ms_curr_update -= CURR_UPDATE_PERIOD; - CurrentSensorBus::transfer(); - } - + int n; + n = RawHID.recv(buffer, 0); // 0 timeout = do not wait + if (n > 0) { + recv(); + } + + if (ms_until_send > TX_PERIOD) { + ms_until_send -= TX_PERIOD; + send(); + n = RawHID.send(buffer, 0); + } + + if (ms_curr_update > CURR_UPDATE_PERIOD) { + ms_curr_update -= CURR_UPDATE_PERIOD; + CurrentSensorBus::transfer(); + } }