From ec8c927fa92f2bea4082951cba2afe0209cc449f Mon Sep 17 00:00:00 2001 From: Dtom Date: Fri, 2 Dec 2016 21:49:39 -0500 Subject: [PATCH 01/11] made the message headers self created and took out someshit.txt stuff --- offline/debugging/rbsm_console.py | 62 +++++++++++++++++++------------ real_time/rbsm_config.txt | 2 +- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/offline/debugging/rbsm_console.py b/offline/debugging/rbsm_console.py index 24588a70..e52ffa7f 100755 --- a/offline/debugging/rbsm_console.py +++ b/offline/debugging/rbsm_console.py @@ -32,25 +32,44 @@ screenCopy = None #Create a dictionary of message headers -#TODO create it from ../../real_time/rbsm_config.txt -mid_to_str = { - 0: "ENC_TICKS_LAST", - 1: "ENC_TICKS_RESET", - 5: "ENC_RESET_REQUEST", - 6: "ENC_RESET_CONFIRM", - 17: "MEGA_TELEOP_BRAKE_COMMAND", - 18: "MEGA_AUTON_BRAKE_COMMAND", - 19: "MEGA_STEER_COMMAND", - 20: "MEGA_STEER_ANGLE", - 21: "MEGA_BRAKE_STATE", - 22: "MEGA_AUTON_STATE" , - 23: "MEGA_BATTERY_LEVEL", - 24: "MEGA_STEER_FEEDBACK", - 30: "COMP_HASH", - 253: "MEGA_TIMESTAMP", - 254: "ERROR", - 255: "DEVICE_ID" -} +def createMidToStr(): + dict = {} + settingsFile = None + try: + settingsFile = open("../../real_time/rbsm_config.txt") + except: + print("Error! Unable to find rbsm_headers.txt\n") + sys.exit() + # when the correct headers found + headersFound = False + # when to stop looking for headers + endHeaders = False + # go through each line to find the message headers + for lineNum, line in enumerate(settingsFile): + # to give right name takes out RBSM_MID_ if that is at beginning cause "RBSM_MID_" unneeded + if(line[0:9] == "RBSM_MID_"): + line = line[9:] + # key is in the part after , and value is before + if(headersFound): + definition = line.split(", ") + # if there are not enough values or too many, then line is assumed to be + # end of the parts with message headers + if(len(definition)!=2): + endHeaders = True + break + # sets the key to equal the message header + dict[int(definition[1])] = definition[0] + elif(line[0:15]=="// RBSM Headers"): + # the string that is found is what symbolizes when message headers begin on + # next line + headersFound = True + # when the headers end do not care about anything else so breaks + if(endHeaders): + break + return dict + +mid_to_str = createMidToStr() + def redraw(state): screen = state["screen"] @@ -70,9 +89,6 @@ def redraw(state): message_cache[mid]["update_time"]) screen.addstr(row_id, 2, s) - # with open('someshit.txt', 'at') as f: - # f.write(s + "\n") - row_id = row_id + 1 @@ -152,8 +168,6 @@ def command_worker(state): # standard ascii characters elif(new_char < 128) and len(state["command_line"]) < INPUTUPPERBOUND: state["command_line"] += chr(new_char) - with open('someshit.txt', 'at') as f: - f.write(state["command_line"]) # redraw(state) diff --git a/real_time/rbsm_config.txt b/real_time/rbsm_config.txt index f996f898..56face1a 100644 --- a/real_time/rbsm_config.txt +++ b/real_time/rbsm_config.txt @@ -10,7 +10,7 @@ RBSM_MID_MEGA_STEER_COMMAND, 19 RBSM_MID_MEGA_STEER_ANGLE, 20 RBSM_MID_MEGA_BRAKE_STATE, 21 RBSM_MID_MEGA_AUTON_STATE, 22 -RBSM_MID_MEGA_BATTERY_LEVEL, 23 +MEGA_BATTERY_LEVEL, 23 RBSM_MID_MEGA_STEER_FEEDBACK, 24 RBSM_MID_COMP_HASH, 30 RBSM_MID_MEGA_TIMESTAMP, 253 From d2fc9ab3903775d0fcfdaafcba041ee885b92167 Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Sat, 3 Dec 2016 00:47:15 -0500 Subject: [PATCH 02/11] Spacing changes, added comments, and moving braces to the same line --- .../rbserialmessages/rbserialmessages.cpp | 45 ++---- .../rbserialmessages/rbserialmessages.h | 39 +++-- .../arduino_src/radio_buggy_mega/Makefile | 2 +- .../arduino_src/radio_buggy_mega/main.cpp | 139 ++++++++---------- .../arduino_src/radio_buggy_mega/servo.c | 46 +++--- 5 files changed, 115 insertions(+), 156 deletions(-) diff --git a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp index 0c6ae383..9431190b 100644 --- a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp +++ b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp @@ -18,13 +18,11 @@ // Public ////////////////////////////////////////////////////////////////////// -RBSerialMessages::RBSerialMessages() -{ +RBSerialMessages::RBSerialMessages() { } -int RBSerialMessages::Init(UARTFILE *in_file, FILE *out_file) -{ +int RBSerialMessages::Init(UARTFILE *in_file, FILE *out_file) { // setup the hardware serial in_file_ = in_file; out_file_ = out_file; @@ -36,14 +34,12 @@ int RBSerialMessages::Init(UARTFILE *in_file, FILE *out_file) return 1; } -int RBSerialMessages::Send(uint8_t id, uint32_t message) -{ +int RBSerialMessages::Send(uint8_t id, uint32_t message) { uint8_t buffer_pos; buffer_pos = InitMessageBuffer(); buffer_pos = AppendMessageToBuffer(id, message, buffer_pos); - for(int i = 0; i < buffer_pos; i++) - { + for(int i = 0; i < buffer_pos; i++) { fputc(buffer_out_[i], out_file_); } @@ -55,37 +51,30 @@ int RBSerialMessages::Send(uint8_t id, uint32_t message) // return 0 if a complete message was found // return -1 if not enough data was found // return -2 if an invalid message was found -int RBSerialMessages::Read(rb_message_t* read_message) -{ - while(in_file_->available() > 0) - { +int RBSerialMessages::Read(rb_message_t* read_message) { + while(in_file_->available() > 0) { // check if there is new data char new_serial_byte = fgetc(in_file_); // first, we need to try to lock on to the stream - if(buffer_in_stream_lock_ == false) - { + if(buffer_in_stream_lock_ == false) { printf("%s: searching for lock...\n", __PRETTY_FUNCTION__); - if((uint8_t)new_serial_byte == FOOTER) - { + if((uint8_t)new_serial_byte == FOOTER) { printf("%s: got lock!\n", __PRETTY_FUNCTION__); buffer_in_stream_lock_ = true; } } // after we lock we need to read in to the buffer until full - else - { + else { // this->Send(RBSM_MID_ERROR, buffer_in_pos_); buffer_in_[buffer_in_pos_] = (uint8_t)new_serial_byte; buffer_in_pos_++; // handle the end of a packet - if(buffer_in_pos_ == RBSM_PACKET_LENGTH) - { + if(buffer_in_pos_ == RBSM_PACKET_LENGTH) { // reset buffer for next packet buffer_in_pos_ = 0; // parse this complete packet - if(buffer_in_[5] == FOOTER) - { + if(buffer_in_[5] == FOOTER) { read_message->message_id = buffer_in_[0]; uint8_t *data_bytes = (uint8_t *) &(read_message->data); data_bytes[0] = buffer_in_[4]; @@ -95,8 +84,7 @@ int RBSerialMessages::Read(rb_message_t* read_message) return 0; } // skip packet as an error - else - { + else { buffer_in_stream_lock_ = false; return RBSM_ERROR_INVALID_MESSAGE; } @@ -112,8 +100,7 @@ int RBSerialMessages::Read(rb_message_t* read_message) // Private ///////////////////////////////////////////////////////////////////// uint8_t RBSerialMessages::AppendMessageToBuffer(uint8_t id, uint32_t message, - uint8_t out_start_pos) -{ + uint8_t out_start_pos) { uint8_t buffer_pos = out_start_pos; uint8_t message_ll = message & RBSM_ONE_BYTE_MASK; uint8_t message_lh = (message >> RBSM_ONE_BYTE_SIZE) & RBSM_ONE_BYTE_MASK; @@ -138,8 +125,7 @@ uint8_t RBSerialMessages::AppendMessageToBuffer(uint8_t id, } -uint8_t RBSerialMessages::InitMessageBuffer() -{ +uint8_t RBSerialMessages::InitMessageBuffer() { uint8_t buffer_pos = 0; // write null terminator just in case. note no increment @@ -149,8 +135,7 @@ uint8_t RBSerialMessages::InitMessageBuffer() } -int RBSerialMessages::InitReadBuffer() -{ +int RBSerialMessages::InitReadBuffer() { buffer_in_pos_ = 0; buffer_in_stream_lock_ = false; diff --git a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.h b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.h index 61815ec8..02cefb27 100644 --- a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.h +++ b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.h @@ -42,41 +42,38 @@ #define RBSM_DID_MEGA 0 -struct rb_message_t -{ +struct rb_message_t { char message_id; uint32_t data; }; -class RBSerialMessages -{ +class RBSerialMessages { + public: + RBSerialMessages(); + int Init(UARTFILE *in_file, FILE *out_file); + int Send(uint8_t id, uint32_t message); + int Read(rb_message_t* read_message); - RBSerialMessages(); - int Init(UARTFILE *in_file, FILE *out_file); - int Send(uint8_t id, uint32_t message); - int Read(rb_message_t* read_message); private: - - UARTFILE *in_file_; - FILE *out_file_; - char buffer_out_[RBSM_BUFFER_OUT_LENGTH]; - char buffer_in_[RBSM_BUFFER_IN_LENGTH]; - uint8_t buffer_in_pos_; - bool buffer_in_stream_lock_; - uint8_t AppendMessageToBuffer(uint8_t id, - uint32_t message, - uint8_t out_start_pos); - uint8_t InitMessageBuffer(); - int InitReadBuffer(); + UARTFILE *in_file_; + FILE *out_file_; + char buffer_out_[RBSM_BUFFER_OUT_LENGTH]; + char buffer_in_[RBSM_BUFFER_IN_LENGTH]; + uint8_t buffer_in_pos_; + bool buffer_in_stream_lock_; + uint8_t AppendMessageToBuffer(uint8_t id, + uint32_t message, + uint8_t out_start_pos); + uint8_t InitMessageBuffer(); + int InitReadBuffer(); }; // old api. may still want some of these functions // // int protocol_init( void ); // TODO: I'm not sure exactly what needs to be initialized yet -// int protocol_run( void ); // TODO: // unsigned long protocol_send( byte id, unsigned int message); // Currently working on // unsigned long protocol_getMessage(unsigned long packet); // unsigned long protocol_getID(unsigned long packet); diff --git a/real_time/arduino_src/radio_buggy_mega/Makefile b/real_time/arduino_src/radio_buggy_mega/Makefile index 40b0195c..64296623 100755 --- a/real_time/arduino_src/radio_buggy_mega/Makefile +++ b/real_time/arduino_src/radio_buggy_mega/Makefile @@ -533,7 +533,7 @@ clean_list : $(REMOVE) $(patsubst %.c,%.d,$(patsubst %.cpp,%.d,$(SRC))) $(REMOVE) .dep/* $(REMOVE) fingerprint.h - $(REMOVE) rbsm_config.h + $(REMOVE) ../lib_avr/rbserialmessages/rbsm_config.h diff --git a/real_time/arduino_src/radio_buggy_mega/main.cpp b/real_time/arduino_src/radio_buggy_mega/main.cpp index 1b904510..18a2228a 100644 --- a/real_time/arduino_src/radio_buggy_mega/main.cpp +++ b/real_time/arduino_src/radio_buggy_mega/main.cpp @@ -100,7 +100,8 @@ #define STEERING_KP_DEMONENATOR 1L #define STEERING_KD_NUMERATOR 0L #define STEERING_KD_DENOMENATOR 100L -#define STEERING_MAX_SPEED 32000L //limited by 16-bit signed? 400 degress per second - 50% cpu usage from encoder interrupts +//limited by 16-bit signed? 400 degress per second - 50% cpu usage from encoder interrupts +#define STEERING_MAX_SPEED 32000L #define STEERING_KV_NUMERATOR 3L #define STEERING_KV_DENOMENATOR 1000L #define STEERING_PWM_CENTER_US 1500L //The PWM value that gives no movement. @@ -153,21 +154,18 @@ inline long map_signal(long x, long in_offset, long in_scale, long out_offset, - long out_scale) -{ + long out_scale) { return ((x - in_offset) * out_scale / in_scale) + out_offset; } inline long clamp(long input, long upper, - long lower) -{ + long lower) { return (max(min(input, upper), lower)); } -void adc_init(void) // copy-pasted from wiring.c l.353 (Arduino library) -{ +void adc_init(void) {// copy-pasted from wiring.c l.353 (Arduino library) // set a2d prescaler so we are inside the desired 50-200 KHz range. sbi(ADCSRA, ADPS2); sbi(ADCSRA, ADPS1); @@ -176,8 +174,7 @@ void adc_init(void) // copy-pasted from wiring.c l.353 (Arduino library) sbi(ADCSRA, ADEN); } -int adc_read_blocking(uint8_t pin) // takes less than 160us, return 0 to 1023 -{ +int adc_read_blocking(uint8_t pin) { // takes less than 160us, return 0 to 1023 uint8_t low, high; // the MUX5 bit of ADCSRB selects whether we're reading from channels @@ -216,28 +213,29 @@ void steer_set_velocity(long target_velocity) { static long steer_set_prev_ticks = 0; static long steer_set_prev_velocity = 0; - target_velocity = clamp(target_velocity, STEERING_MAX_SPEED, -(STEERING_MAX_SPEED)); - - long current_ticks = g_encoder_steering.GetTicks(); - long change_in_ticks = current_ticks - steer_set_prev_ticks; - long change_in_angle = (change_in_ticks * DEGREE_HUNDREDTHS_PER_REV) / DEGREE_HUNDREDTHS_PER_REV; - //angle * us/s * us = angle per second - long actual_velocity = (change_in_angle * MICROSECONDS_PER_SECOND) / STEERING_LOOP_TIME_US; - - long error = target_velocity - actual_velocity; - - long output_us = 0; - long output_p = error * STEERING_KV_NUMERATOR / STEERING_KV_DENOMENATOR; + target_velocity = clamp(target_velocity, STEERING_MAX_SPEED, -(STEERING_MAX_SPEED)); + + long current_ticks = g_encoder_steering.GetTicks(); + long change_in_ticks = current_ticks - steer_set_prev_ticks; + long change_in_angle = (change_in_ticks * DEGREE_HUNDREDTHS_PER_REV) / DEGREE_HUNDREDTHS_PER_REV; + //angle * us/s * us = angle per second + long actual_velocity = (change_in_angle * MICROSECONDS_PER_SECOND) / STEERING_LOOP_TIME_US; + + long error = target_velocity - actual_velocity; + + long output_us = 0; + long output_p = error * STEERING_KV_NUMERATOR / STEERING_KV_DENOMENATOR; output_us = output_p; long output_int_us = steer_set_prev_velocity + output_us; output_int_us = clamp(output_int_us, STEERING_MAX_PWM, -STEERING_MAX_PWM); - - // dbg_printf("target: %ld, current: %ld, error: %ld, correction: %ld, output: %ld\n", target_velocity, actual_velocity, error, output_us, output_int_us); - - //Send command to the motor + + // dbg_printf("target: %ld, current: %ld, error: %ld, correction: %ld, output: %ld\n", + // target_velocity, actual_velocity, error, output_us, output_int_us); + + //Send command to the motor servo_set_us(output_int_us + STEERING_PWM_CENTER_US); - - steer_set_prev_ticks = current_ticks; + + steer_set_prev_ticks = current_ticks; steer_set_prev_velocity = output_int_us; } @@ -250,15 +248,15 @@ void steering_set(int angle) { static long steer_set_error_prev = 0; //This is used to find the d term for position. - angle = clamp(angle, STEERING_LIMIT_RIGHT, STEERING_LIMIT_LEFT); - + angle = clamp(angle, STEERING_LIMIT_RIGHT, STEERING_LIMIT_LEFT); + //For the DC motor long actual = map_signal(g_encoder_steering.GetTicks(), 0, MOTOR_ENCODER_TICKS_PER_REV, 0, DEGREE_HUNDREDTHS_PER_REV); - + long error = angle - actual; long output_vel = 0; if(labs(error) > STEERING_ERROR_THRESHOLD) { //0.1 degree deadband @@ -325,9 +323,10 @@ int8_t steering_center() { return 0; } - -void indicator_light_init() -{ +/** @brief Sets up the appropriate pins for the indicator lights + * + */ +void indicator_light_init() { // set all pins to zero output RX_STATUS_LIGHT_PORT &= ~_BV(3); RX_STATUS_LIGHT_DDR |= _BV(3); @@ -338,46 +337,39 @@ void indicator_light_init() } -void voltage_too_low_light() -{ +void voltage_too_low_light() { // blue for this light RX_STATUS_LIGHT_PORT |= _BV(RX_STATUS_LIGHT_PINN_BLUE); } -void auton_timeout_light() -{ +void auton_timeout_light() { // red for this light RX_STATUS_LIGHT_PORT_RED |= _BV(RX_STATUS_LIGHT_PINN_RED); } -void rc_timeout_failure_light() -{ +void rc_timeout_failure_light() { // green for this light RX_STATUS_LIGHT_PORT |= _BV(RX_STATUS_LIGHT_PINN_GREEN); } -void voltage_too_low_light_reset() -{ +void voltage_too_low_light_reset() { RX_STATUS_LIGHT_PORT &= ~_BV(RX_STATUS_LIGHT_PINN_BLUE); } -void auton_timeout_light_reset() -{ +void auton_timeout_light_reset() { RX_STATUS_LIGHT_PORT_RED &= ~_BV(RX_STATUS_LIGHT_PINN_RED); } -void rc_timeout_failure_light_reset() -{ +void rc_timeout_failure_light_reset() { RX_STATUS_LIGHT_PORT &= ~_BV(RX_STATUS_LIGHT_PINN_GREEN); } -void brake_init() -{ +void brake_init() { BRAKE_OUT_DDR |= _BV(BRAKE_OUT_PINN); } @@ -392,8 +384,7 @@ void brake_raise() // Drops the brake // Do not call before brake_init -void brake_drop() -{ +void brake_drop() { BRAKE_OUT_PORT &= ~_BV(BRAKE_OUT_PINN); } @@ -405,8 +396,7 @@ void brake_drop() * Sets the system to "bark" after 1 second without resets. Has an * independent clock and will check for timeout regardless of main code. */ -void watchdog_init() -{ +void watchdog_init() { //Disable interrupts because setup is time sensitive cli(); @@ -428,8 +418,7 @@ void watchdog_init() } -int main(void) -{ +int main(void) { // state variables bool brake_needs_reset = true; // 0 = nominal, !0 = needs reset bool brake_cmd_teleop_engaged = false; @@ -497,8 +486,7 @@ int main(void) watchdog_init(); // loop forever - while(1) - { + while(1) { // prepare to time the main loop unsigned long time_next_loop = micros() + STEERING_LOOP_TIME_US; @@ -507,16 +495,14 @@ int main(void) int read_status; while((read_status = g_rbsm.Read(&new_command)) - != RBSM_ERROR_INSUFFICIENT_DATA) - { - if(read_status == 0) - { + != RBSM_ERROR_INSUFFICIENT_DATA) { + + if(read_status == 0) { // clear RBSM errors g_errors &= ~_BV(RBSM_EID_RBSM_LOST_STREAM); g_errors &= ~_BV(RBSM_EID_RBSM_INVALID_MID); // dipatch complete message - switch(new_command.message_id) - { + switch(new_command.message_id) { case RBSM_MID_ENC_RESET_REQUEST: g_encoder_distance.Reset(); //Let high level know that the request went through @@ -543,8 +529,7 @@ int main(void) } //End switch(new_command.message_id) } // report stream losses for tracking - else if(read_status == RBSM_ERROR_INVALID_MESSAGE) - { + else if(read_status == RBSM_ERROR_INVALID_MESSAGE) { dbg_printf("RBSM could not parse message.\n"); g_errors |= _BV(RBSM_EID_RBSM_LOST_STREAM); } @@ -585,6 +570,7 @@ int main(void) bool auton_timeout = (g_is_autonomous == true) && (delta4 > CONNECTION_TIMEOUT_US || delta5 > CONNECTION_TIMEOUT_US); + if(rc_timeout || auton_timeout) { // check for RC timout first if(rc_timeout) { @@ -634,26 +620,22 @@ int main(void) } // Set outputs - if(g_is_autonomous) - { + if(g_is_autonomous) { steering_set(auto_steering_angle); g_rbsm.Send(RBSM_MID_MEGA_STEER_ANGLE, (long int)(auto_steering_angle)); } - else - { + else { steering_set(steer_angle); g_rbsm.Send(RBSM_MID_MEGA_STEER_ANGLE, (long int)steer_angle); } if(brake_cmd_teleop_engaged == true || (g_is_autonomous == true && brake_cmd_auton_engaged == true) || - brake_needs_reset == true) - { + brake_needs_reset == true) { brake_drop(); g_rbsm.Send(RBSM_MID_MEGA_BRAKE_STATE,(long unsigned)true); } - else - { + else { brake_raise(); g_rbsm.Send(RBSM_MID_MEGA_BRAKE_STATE,(long unsigned)false); } @@ -693,8 +675,7 @@ int main(void) } -ISR(WDT_INT) -{ +ISR(WDT_INT) { cli(); brake_drop(); while(1) @@ -702,25 +683,21 @@ ISR(WDT_INT) } } -ISR(RX_STEERING_INT) -{ +ISR(RX_STEERING_INT) { g_steering_rx.OnInterruptReceiver(); } -ISR(RX_BRAKE_INT) -{ +ISR(RX_BRAKE_INT) { g_brake_rx.OnInterruptReceiver(); } -ISR(RX_AUTON_INT) -{ +ISR(RX_AUTON_INT) { g_auton_rx.OnInterruptReceiver(); } -ISR(ENCODER_INT) -{ +ISR(ENCODER_INT) { g_encoder_distance.OnInterrupt(); } diff --git a/real_time/arduino_src/radio_buggy_mega/servo.c b/real_time/arduino_src/radio_buggy_mega/servo.c index fc1b42c8..995929c8 100644 --- a/real_time/arduino_src/radio_buggy_mega/servo.c +++ b/real_time/arduino_src/radio_buggy_mega/servo.c @@ -2,33 +2,33 @@ void servo_init(void) { - // set up timers for PWM on OC1A (PB1, arduino pin 9) - // prescaler of 8 - // PWM with top as ICR1 (to set cap) - // set ICR1 to the desired refresh time - TCCR1A |= (_BV(WGM11) | _BV(COM1A1)); - TCCR1A &= ~(_BV(WGM10) | _BV(COM1A0)); - TCCR1B |= (_BV(WGM13) | _BV(WGM12) | _BV(CS11)); - TCCR1B &= ~(_BV(CS10) | _BV(CS12)); - TCNT1 = 0; - servo_set_us(SERVO_MID_US); - ICR1 = microsecondsToClockCycles(SERVO_REFRESH_US) / SERVO_TIMER_PRESCALER; + // set up timers for PWM on OC1A (PB1, arduino pin 9) + // prescaler of 8 + // PWM with top as ICR1 (to set cap) + // set ICR1 to the desired refresh time + TCCR1A |= (_BV(WGM11) | _BV(COM1A1)); + TCCR1A &= ~(_BV(WGM10) | _BV(COM1A0)); + TCCR1B |= (_BV(WGM13) | _BV(WGM12) | _BV(CS11)); + TCCR1B &= ~(_BV(CS10) | _BV(CS12)); + TCNT1 = 0; + servo_set_us(SERVO_MID_US); + ICR1 = microsecondsToClockCycles(SERVO_REFRESH_US) / SERVO_TIMER_PRESCALER; - // enable servo output - SERVO_PORT &= ~_BV(SERVO_PINN); - SERVO_DDR |= _BV(SERVO_PINN); + // enable servo output + SERVO_PORT &= ~_BV(SERVO_PINN); + SERVO_DDR |= _BV(SERVO_PINN); } void servo_set_us(uint16_t value) { - // check limits - if(value < SERVO_MIN_US) { - value = SERVO_MIN_US; - } - if(value > SERVO_MAX_US) { - value = SERVO_MAX_US; - } + // check limits + if(value < SERVO_MIN_US) { + value = SERVO_MIN_US; + } + if(value > SERVO_MAX_US) { + value = SERVO_MAX_US; + } - // modify hardware output - OCR1A = microsecondsToClockCycles(value) / SERVO_TIMER_PRESCALER; + // modify hardware output + OCR1A = microsecondsToClockCycles(value) / SERVO_TIMER_PRESCALER; } From bba9b42a17e6ad4ebc75093565ed48c478398d5a Mon Sep 17 00:00:00 2001 From: Dtom Date: Sat, 3 Dec 2016 01:51:05 -0500 Subject: [PATCH 03/11] put comment for rbsm_config.txt so it is maintainable and added error messages for Error bits in rbsm_console but haven't tested --- offline/debugging/rbsm_console.py | 59 +++++++++++++++++++++---------- real_time/rbsm_config.txt | 6 ++-- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/offline/debugging/rbsm_console.py b/offline/debugging/rbsm_console.py index e52ffa7f..bc0411bb 100755 --- a/offline/debugging/rbsm_console.py +++ b/offline/debugging/rbsm_console.py @@ -29,47 +29,50 @@ import signal signal.signal(signal.SIGINT, signal.SIG_DFL) -screenCopy = None +screen_copy = None #Create a dictionary of message headers -def createMidToStr(): +# startOfValues is the comment before start of values for dict +# takeout is what needs to be taken out from the beginning of the values in dict +# if it is in the rbsm_config.txt file +def create_bit_to_str(start_of_values, takeout=""): dict = {} - settingsFile = None + settings_file = None try: - settingsFile = open("../../real_time/rbsm_config.txt") + settings_file = open("../../real_time/rbsm_config.txt") except: print("Error! Unable to find rbsm_headers.txt\n") - sys.exit() + sys.exit(1) # when the correct headers found - headersFound = False + headers_found = False # when to stop looking for headers - endHeaders = False + end_headers = False # go through each line to find the message headers - for lineNum, line in enumerate(settingsFile): + for line_num, line in enumerate(settings_file): # to give right name takes out RBSM_MID_ if that is at beginning cause "RBSM_MID_" unneeded - if(line[0:9] == "RBSM_MID_"): - line = line[9:] + if(line[0:len(takeout)] == takeout): + line = line[len(takeout):] # key is in the part after , and value is before - if(headersFound): + if(headers_found): definition = line.split(", ") # if there are not enough values or too many, then line is assumed to be # end of the parts with message headers if(len(definition)!=2): - endHeaders = True + end_headers = True break # sets the key to equal the message header dict[int(definition[1])] = definition[0] - elif(line[0:15]=="// RBSM Headers"): + elif(line[0:len(start_of_values)+3]=="// " + start_of_values): # the string that is found is what symbolizes when message headers begin on # next line - headersFound = True + headers_found = True # when the headers end do not care about anything else so breaks - if(endHeaders): + if(end_headers): break return dict -mid_to_str = createMidToStr() - +mid_to_str = create_bit_to_str("RBSM Headers", "RBSM_MID_") +eid_to_str = create_bit_to_str("Error Message Bits", "RBSM_EID_") def redraw(state): screen = state["screen"] @@ -90,7 +93,27 @@ def redraw(state): screen.addstr(row_id, 2, s) row_id = row_id + 1 - + + #adding space and then error + screen.addstr(row_id, 2, "") + screen.addstr(row_id+1, 2, "ERROR") + screen.addstr(row_id+2, 2, "------------------------") + row_id = row_id + 3 + # finds which value is error + error = 254 + for key in mid_to_str.key(): + if(mid_to_str[key]=="ERROR"): + error = key + for error_message in message_cache[error]["data"]: + # if this error not in eid_to_str then displays this string + s = error_message + for key in eid_to_str.keys(): + if(error_message == eid_to_str[key]): + s = error_message + " bit"+str(key) + screen.addstr(row_id, 2, s) + row_id = row_id + 1 + # adding -- so that if there is nothing between error and this then no error + screen.addstr(row_id, 2, "------------------------") # update status line screen.addstr(max_y-3, 2, "status: {:<15}".format(status_line)) diff --git a/real_time/rbsm_config.txt b/real_time/rbsm_config.txt index 56face1a..e42410ca 100644 --- a/real_time/rbsm_config.txt +++ b/real_time/rbsm_config.txt @@ -1,4 +1,6 @@ -// +// note for maintaining this file: +// before each set of values and keys, put "// name of category" +// example: "// RBSM Headers" // RBSM Headers RBSM_MID_ENC_TICKS_RESET, 1 @@ -10,7 +12,7 @@ RBSM_MID_MEGA_STEER_COMMAND, 19 RBSM_MID_MEGA_STEER_ANGLE, 20 RBSM_MID_MEGA_BRAKE_STATE, 21 RBSM_MID_MEGA_AUTON_STATE, 22 -MEGA_BATTERY_LEVEL, 23 +RBSM_MID_MEGA_BATTERY_LEVEL, 23 RBSM_MID_MEGA_STEER_FEEDBACK, 24 RBSM_MID_COMP_HASH, 30 RBSM_MID_MEGA_TIMESTAMP, 253 From ee34cd6ffc025e0608428b664e3fda53afb36db3 Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sat, 3 Dec 2016 03:25:18 -0500 Subject: [PATCH 04/11] Added comments and moved brackets to the same line as the function --- real_time/arduino_src/lib_avr/encoder/encoder.cpp | 3 +-- real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp | 3 +-- .../arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/real_time/arduino_src/lib_avr/encoder/encoder.cpp b/real_time/arduino_src/lib_avr/encoder/encoder.cpp index a412c7b7..d9b0355f 100644 --- a/real_time/arduino_src/lib_avr/encoder/encoder.cpp +++ b/real_time/arduino_src/lib_avr/encoder/encoder.cpp @@ -1,8 +1,7 @@ #include "encoder.h" -Encoder::Encoder() { -} +Encoder::Encoder() {} //constructor function uint8_t Encoder::Init(volatile uint8_t *pin_a_reg, diff --git a/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp b/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp index be98f52c..b99e8092 100644 --- a/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp +++ b/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp @@ -1,8 +1,7 @@ #include "RadioReceiver.h" -RadioReceiver::RadioReceiver() { -} +RadioReceiver::RadioReceiver() {} //constructor function void RadioReceiver::Init(volatile uint8_t *pin_reg, diff --git a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp index 9431190b..f3d82f16 100644 --- a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp +++ b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp @@ -18,8 +18,7 @@ // Public ////////////////////////////////////////////////////////////////////// -RBSerialMessages::RBSerialMessages() { -} +RBSerialMessages::RBSerialMessages() {} //constructor function int RBSerialMessages::Init(UARTFILE *in_file, FILE *out_file) { From bf63881bfd54feeb609a9f0d4f8044e3ffa36ce5 Mon Sep 17 00:00:00 2001 From: Dtom Date: Sat, 3 Dec 2016 03:56:41 -0500 Subject: [PATCH 05/11] edited console and tested it so that it makes error messages --- offline/debugging/rbsm_console.py | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/offline/debugging/rbsm_console.py b/offline/debugging/rbsm_console.py index bc0411bb..235bd919 100755 --- a/offline/debugging/rbsm_console.py +++ b/offline/debugging/rbsm_console.py @@ -96,24 +96,32 @@ def redraw(state): #adding space and then error screen.addstr(row_id, 2, "") - screen.addstr(row_id+1, 2, "ERROR") - screen.addstr(row_id+2, 2, "------------------------") - row_id = row_id + 3 + screen.addstr(row_id+1, 2, "--------ERRORS---------") + # since last steps went through 2 rows adding 2 to row_id + row_id = row_id + 2 # finds which value is error error = 254 - for key in mid_to_str.key(): + for key in mid_to_str.keys(): if(mid_to_str[key]=="ERROR"): error = key - for error_message in message_cache[error]["data"]: - # if this error not in eid_to_str then displays this string - s = error_message - for key in eid_to_str.keys(): - if(error_message == eid_to_str[key]): - s = error_message + " bit"+str(key) - screen.addstr(row_id, 2, s) - row_id = row_id + 1 + # check if key is even in message_cache + if(error in message_cache.keys()): + error_message = message_cache[error]["data"] + # max bit that has associated error + maxBit = max(eid_to_str.keys()) + for bit in xrange(maxBit+1): + if(error_message%2==1 and bit in eid_to_str.keys()): + #screen.addstr(row_id, 2, eid_to_str[bit]) + wipeScreenAndPost(screen, eid_to_str[bit], row_id) + row_id = row_id + 1 + # can eliminate previous bit by diving by 2 + error_message = error_message/2 # adding -- so that if there is nothing between error and this then no error - screen.addstr(row_id, 2, "------------------------") + wipeScreenAndPost(screen, "------------------------", row_id) + #screen.addstr(row_id, 2, "------------------------") + # to make sure row below BottomLine clean: + wipeScreenAndPost(screen, "", row_id+1) + # update status line screen.addstr(max_y-3, 2, "status: {:<15}".format(status_line)) @@ -125,6 +133,10 @@ def redraw(state): screen.refresh() +def wipeScreenAndPost(screen, str, pos): + # long empty space to wipe line clean + screen.addstr(pos, 2, " ") + screen.addstr(pos, 2, str) def rbsm_worker(state): message_cache = state["message_cache"] From b3192f77a8842f1603313e8fbd03413691f1c3a7 Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sat, 3 Dec 2016 04:05:34 -0500 Subject: [PATCH 06/11] added and deleted comments and moved brackets to fit style --- .../arduino_src/lib_avr/encoder/encoder.cpp | 3 ++- .../lib_avr/radioreceiver/RadioReceiver.cpp | 4 +++- .../rbserialmessages/rbserialmessages.cpp | 4 +++- .../arduino_src/radio_buggy_mega/main.cpp | 24 +++++++++++++++---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/real_time/arduino_src/lib_avr/encoder/encoder.cpp b/real_time/arduino_src/lib_avr/encoder/encoder.cpp index d9b0355f..a412c7b7 100644 --- a/real_time/arduino_src/lib_avr/encoder/encoder.cpp +++ b/real_time/arduino_src/lib_avr/encoder/encoder.cpp @@ -1,7 +1,8 @@ #include "encoder.h" -Encoder::Encoder() {} //constructor function +Encoder::Encoder() { +} uint8_t Encoder::Init(volatile uint8_t *pin_a_reg, diff --git a/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp b/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp index b99e8092..34138467 100644 --- a/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp +++ b/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp @@ -1,7 +1,9 @@ #include "RadioReceiver.h" -RadioReceiver::RadioReceiver() {} //constructor function +RadioReceiver::RadioReceiver() { + +} void RadioReceiver::Init(volatile uint8_t *pin_reg, diff --git a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp index f3d82f16..bd2db72c 100644 --- a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp +++ b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp @@ -18,7 +18,9 @@ // Public ////////////////////////////////////////////////////////////////////// -RBSerialMessages::RBSerialMessages() {} //constructor function +RBSerialMessages::RBSerialMessages() { + +} int RBSerialMessages::Init(UARTFILE *in_file, FILE *out_file) { diff --git a/real_time/arduino_src/radio_buggy_mega/main.cpp b/real_time/arduino_src/radio_buggy_mega/main.cpp index 18a2228a..02f6752a 100644 --- a/real_time/arduino_src/radio_buggy_mega/main.cpp +++ b/real_time/arduino_src/radio_buggy_mega/main.cpp @@ -336,39 +336,53 @@ void indicator_light_init() { RX_STATUS_LIGHT_DDR_RED |= _BV(6); } - +/** @brief turns on blue light to indicate low voltage +* +*/ void voltage_too_low_light() { - // blue for this light RX_STATUS_LIGHT_PORT |= _BV(RX_STATUS_LIGHT_PINN_BLUE); } - +/** @brief turns on red light to indicate autonomous timeout +* +*/ void auton_timeout_light() { // red for this light RX_STATUS_LIGHT_PORT_RED |= _BV(RX_STATUS_LIGHT_PINN_RED); } +/** @brief turns on green light to indicate rc timeout +* +*/ void rc_timeout_failure_light() { // green for this light RX_STATUS_LIGHT_PORT |= _BV(RX_STATUS_LIGHT_PINN_GREEN); } +/** @brief turns off blue light +* +*/ void voltage_too_low_light_reset() { RX_STATUS_LIGHT_PORT &= ~_BV(RX_STATUS_LIGHT_PINN_BLUE); } - +/** @brief turns off red light +* +*/ void auton_timeout_light_reset() { RX_STATUS_LIGHT_PORT_RED &= ~_BV(RX_STATUS_LIGHT_PINN_RED); } - +/** @brief turns off green light +* +*/ void rc_timeout_failure_light_reset() { RX_STATUS_LIGHT_PORT &= ~_BV(RX_STATUS_LIGHT_PINN_GREEN); } + void brake_init() { BRAKE_OUT_DDR |= _BV(BRAKE_OUT_PINN); } From 848e649c64f55d221a1c85d6fd46a1ff30b6f997 Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sat, 3 Dec 2016 04:07:34 -0500 Subject: [PATCH 07/11] deleted a line --- real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp | 1 - .../arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp b/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp index 34138467..be98f52c 100644 --- a/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp +++ b/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.cpp @@ -2,7 +2,6 @@ RadioReceiver::RadioReceiver() { - } diff --git a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp index bd2db72c..9431190b 100644 --- a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp +++ b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp @@ -19,7 +19,6 @@ // Public ////////////////////////////////////////////////////////////////////// RBSerialMessages::RBSerialMessages() { - } From d6af009cf9d656b12804e072cf11b3d5fd8f146e Mon Sep 17 00:00:00 2001 From: Dtom Date: Sat, 3 Dec 2016 04:13:33 -0500 Subject: [PATCH 08/11] took out dead code and added comments in rbsm_config.txt --- offline/debugging/rbsm_console.py | 4 +--- real_time/rbsm_config.txt | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/offline/debugging/rbsm_console.py b/offline/debugging/rbsm_console.py index 235bd919..f7101b26 100755 --- a/offline/debugging/rbsm_console.py +++ b/offline/debugging/rbsm_console.py @@ -41,7 +41,7 @@ def create_bit_to_str(start_of_values, takeout=""): try: settings_file = open("../../real_time/rbsm_config.txt") except: - print("Error! Unable to find rbsm_headers.txt\n") + print("Error! Unable to find real_time/rbsm_headers.txt\n") sys.exit(1) # when the correct headers found headers_found = False @@ -111,14 +111,12 @@ def redraw(state): maxBit = max(eid_to_str.keys()) for bit in xrange(maxBit+1): if(error_message%2==1 and bit in eid_to_str.keys()): - #screen.addstr(row_id, 2, eid_to_str[bit]) wipeScreenAndPost(screen, eid_to_str[bit], row_id) row_id = row_id + 1 # can eliminate previous bit by diving by 2 error_message = error_message/2 # adding -- so that if there is nothing between error and this then no error wipeScreenAndPost(screen, "------------------------", row_id) - #screen.addstr(row_id, 2, "------------------------") # to make sure row below BottomLine clean: wipeScreenAndPost(screen, "", row_id+1) diff --git a/real_time/rbsm_config.txt b/real_time/rbsm_config.txt index e42410ca..304410a9 100644 --- a/real_time/rbsm_config.txt +++ b/real_time/rbsm_config.txt @@ -1,6 +1,7 @@ // note for maintaining this file: // before each set of values and keys, put "// name of category" // example: "// RBSM Headers" +// this file is required by offline/debugging/rbsm_console.py (l.74) // RBSM Headers RBSM_MID_ENC_TICKS_RESET, 1 From 893e3642bb68c974a96bd189c93bc00a7e901e99 Mon Sep 17 00:00:00 2001 From: Dtom Date: Sat, 3 Dec 2016 04:25:40 -0500 Subject: [PATCH 09/11] editted rbsm_config.txt so use of it is clearer --- real_time/rbsm_config.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/real_time/rbsm_config.txt b/real_time/rbsm_config.txt index 304410a9..031eebca 100644 --- a/real_time/rbsm_config.txt +++ b/real_time/rbsm_config.txt @@ -1,7 +1,7 @@ // note for maintaining this file: // before each set of values and keys, put "// name of category" // example: "// RBSM Headers" -// this file is required by offline/debugging/rbsm_console.py (l.74) +// this format is required by offline/debugging/rbsm_console.py (l.74) // RBSM Headers RBSM_MID_ENC_TICKS_RESET, 1 From 8e31098dfa67ff6a9bcf7650823611f5161eda16 Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Sat, 3 Dec 2016 04:36:26 -0500 Subject: [PATCH 10/11] Addressing PR comments. Removing random whitespaces and changing placement of else statements to match new braces format --- .../lib_avr/radioreceiver/RadioReceiver.h | 1 - .../rbserialmessages/rbserialmessages.cpp | 3 +- .../rbserialmessages/rbserialmessages.h | 1 - .../arduino_src/radio_buggy_mega/main.cpp | 34 +++++++------------ 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.h b/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.h index 5c0f6e58..3fd3e0a4 100644 --- a/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.h +++ b/real_time/arduino_src/lib_avr/radioreceiver/RadioReceiver.h @@ -7,7 +7,6 @@ class RadioReceiver { - protected: volatile uint8_t *receiver_pin_reg_; uint8_t receiver_pin_num_; diff --git a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp index 9431190b..eea744f4 100644 --- a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp +++ b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp @@ -63,9 +63,8 @@ int RBSerialMessages::Read(rb_message_t* read_message) { printf("%s: got lock!\n", __PRETTY_FUNCTION__); buffer_in_stream_lock_ = true; } - } // after we lock we need to read in to the buffer until full - else { + } else { // this->Send(RBSM_MID_ERROR, buffer_in_pos_); buffer_in_[buffer_in_pos_] = (uint8_t)new_serial_byte; buffer_in_pos_++; diff --git a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.h b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.h index 02cefb27..e9a8ed20 100644 --- a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.h +++ b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.h @@ -49,7 +49,6 @@ struct rb_message_t { class RBSerialMessages { - public: RBSerialMessages(); int Init(UARTFILE *in_file, FILE *out_file); diff --git a/real_time/arduino_src/radio_buggy_mega/main.cpp b/real_time/arduino_src/radio_buggy_mega/main.cpp index 02f6752a..9b3aba92 100644 --- a/real_time/arduino_src/radio_buggy_mega/main.cpp +++ b/real_time/arduino_src/radio_buggy_mega/main.cpp @@ -165,7 +165,7 @@ inline long clamp(long input, } -void adc_init(void) {// copy-pasted from wiring.c l.353 (Arduino library) +void adc_init(void) { // copy-pasted from wiring.c l.353 (Arduino library) // set a2d prescaler so we are inside the desired 50-200 KHz range. sbi(ADCSRA, ADPS2); sbi(ADCSRA, ADPS1); @@ -509,8 +509,7 @@ int main(void) { int read_status; while((read_status = g_rbsm.Read(&new_command)) - != RBSM_ERROR_INSUFFICIENT_DATA) { - + != RBSM_ERROR_INSUFFICIENT_DATA) { if(read_status == 0) { // clear RBSM errors g_errors &= ~_BV(RBSM_EID_RBSM_LOST_STREAM); @@ -541,14 +540,12 @@ int main(void) { g_errors |= _BV(RBSM_EID_RBSM_INVALID_MID); break; } //End switch(new_command.message_id) - } - // report stream losses for tracking - else if(read_status == RBSM_ERROR_INVALID_MESSAGE) { + } else if(read_status == RBSM_ERROR_INVALID_MESSAGE) { + // report stream losses for tracking dbg_printf("RBSM could not parse message.\n"); g_errors |= _BV(RBSM_EID_RBSM_LOST_STREAM); - } - // should not be other faults - else { + } else { + // should not be other faults dbg_printf("Unknown RBSM parse error.\n"); g_errors |= _BV(RBSM_EID_RBSM_LOST_STREAM); } @@ -593,8 +590,7 @@ int main(void) { brake_needs_reset = true; rc_timeout_failure_light(); dbg_printf("RC Timeout! %lu %lu %lu\n", delta1, delta2, delta3); - } - else { + } else { g_errors &= ~_BV(RBSM_EID_RC_LOST_SIGNAL); } @@ -604,12 +600,11 @@ int main(void) { brake_needs_reset = true; auton_timeout_light(); dbg_printf("Auton Timeout! %lu %lu\n", delta4, delta5); - } - else { + } else { g_errors &= ~_BV(RBSM_EID_AUTON_LOST_SIGNAL); } - } - else { // or reset the system if connection is back and driver engages brakes + // or reset the system if connection is back and driver engages brakes + } else { if(brake_cmd_teleop_engaged == true) { brake_needs_reset = false; } @@ -628,8 +623,7 @@ int main(void) { if (g_current_voltage < SYSTEM_VOLTAGE_THRESHOLD) { voltage_too_low_light(); - } - else { + } else { voltage_too_low_light_reset(); } @@ -637,8 +631,7 @@ int main(void) { if(g_is_autonomous) { steering_set(auto_steering_angle); g_rbsm.Send(RBSM_MID_MEGA_STEER_ANGLE, (long int)(auto_steering_angle)); - } - else { + } else { steering_set(steer_angle); g_rbsm.Send(RBSM_MID_MEGA_STEER_ANGLE, (long int)steer_angle); } @@ -648,8 +641,7 @@ int main(void) { brake_needs_reset == true) { brake_drop(); g_rbsm.Send(RBSM_MID_MEGA_BRAKE_STATE,(long unsigned)true); - } - else { + } else { brake_raise(); g_rbsm.Send(RBSM_MID_MEGA_BRAKE_STATE,(long unsigned)false); } From 1accb9d2417e7310e943d8b968aa924f011a9ae7 Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Sat, 3 Dec 2016 04:39:20 -0500 Subject: [PATCH 11/11] Forgot one else statement --- .../arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp index eea744f4..f27cb887 100644 --- a/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp +++ b/real_time/arduino_src/lib_avr/rbserialmessages/rbserialmessages.cpp @@ -81,9 +81,8 @@ int RBSerialMessages::Read(rb_message_t* read_message) { data_bytes[2] = buffer_in_[2]; data_bytes[3] = buffer_in_[1]; return 0; - } // skip packet as an error - else { + } else { buffer_in_stream_lock_ = false; return RBSM_ERROR_INVALID_MESSAGE; }