Skip to content

Commit

Permalink
Transistor's radio on NAND; inverted steering
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaagrawal committed Apr 14, 2018
1 parent 90fdca7 commit 02bc349
Show file tree
Hide file tree
Showing 6 changed files with 3,958 additions and 17 deletions.
31 changes: 31 additions & 0 deletions Electrical/NANDistor/code/lib_avr/rbserialmessages/rbsm_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* rbsm_config.h: A compilation-time created file containing message
headers and error codes for rbsm. Generated by headercheck.py. */

#ifndef RBSMHEADERS_H
#define RBSMHEADERS_H

#define RBSM_MID_ENC_TICKS_RESET 1
#define RBSM_MID_ENC_RESET_REQUEST 5
#define RBSM_MID_ENC_RESET_CONFIRM 6
#define RBSM_MID_MEGA_TELEOP_BRAKE_COMMAND 17
#define RBSM_MID_MEGA_AUTON_BRAKE_COMMAND 18
#define RBSM_MID_MEGA_STEER_COMMAND 19
#define RBSM_MID_MEGA_STEER_ANGLE 20
#define RBSM_MID_MEGA_BRAKE_STATE 21
#define RBSM_MID_MEGA_AUTON_STATE 22
#define RBSM_MID_MEGA_BATTERY_LEVEL 23
#define RBSM_MID_MEGA_STEER_FEEDBACK 24
#define RBSM_MID_COMP_HASH 30
#define RBSM_MID_MEGA_TIMESTAMP 253
#define RBSM_MID_ERROR 254
#define DEVICE_ID 255
#define FOOTER 10
#define RBSM_EID_WDT 0
#define RBSM_EID_RBSM_LOST_STREAM 1
#define RBSM_EID_RBSM_INVALID_MID 2
#define RBSM_EID_RC_LOST_SIGNAL 3
#define RBSM_EID_AUTON_LOST_SIGNAL 4
#define RBSM_ERROR_INSUFFICIENT_DATA -1
#define RBSM_ERROR_INVALID_MESSAGE -2

#endif
15 changes: 15 additions & 0 deletions Electrical/NANDistor/code/radio_buggy_mega/fingerprint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* fingerprint.h: A compilation-time created file containing compilation time,
closest version of git, and other information. Generated by fingerprint.py. */

#ifndef FINGERPRINT_H
#define FINGERPRINT_H

#define FP_COMPDATE "13:04:2018" //day:month:year
#define FP_COMPTIME "20:46:50" //hour:minute:second
#define FP_HOSTNAME "Rolis-MacBook-Pro"
#define FP_BRANCHNAME "abha_nandistor"
#define FP_HEXCOMMITHASH 0x90fdca7
#define FP_STRCOMMITHASH "90fdca7"
#define FP_CLEANSTATUS false

#endif
2 changes: 1 addition & 1 deletion Electrical/NANDistor/code/radio_buggy_mega/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ int main(void) {
unsigned long time_next_loop = micros() + STEERING_LOOP_TIME_US;

// Check for RC commands
steer_angle = g_steering_rx.GetAngleHundredths();
steer_angle = -(g_steering_rx.GetAngleHundredths());
brake_cmd_teleop_engaged = g_brake_rx.GetPulseWidth() > PWM_STATE_THRESHOLD;

// Detect dropped radio conections
Expand Down
34 changes: 18 additions & 16 deletions Electrical/Transistor/code/radio_buggy_mega/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@


// Global state
static bool g_is_autonomous;
static bool g_is_autonomous = false;
static unsigned long g_current_voltage; // in mV
static int steer_angle;
static int auto_steering_angle;
Expand Down Expand Up @@ -410,8 +410,8 @@ int main(void) {
bool brake_cmd_teleop_engaged = false;
bool brake_cmd_auton_engaged = false;
unsigned long time_start = micros();
unsigned long auton_brake_last = time_start;
unsigned long auton_steer_last = time_start;
//unsigned long auton_brake_last = time_start;
//unsigned long auton_steer_last = time_start;

g_encoder_distance.Init();

Expand Down Expand Up @@ -449,7 +449,7 @@ int main(void) {
// set up rc receivers
g_steering_rx.Init(&RX_STEERING_PIN, RX_STEERING_PINN, RX_STEERING_INTN);
g_brake_rx.Init(&RX_BRAKE_PIN, RX_BRAKE_PINN, RX_BRAKE_INTN);
g_auton_rx.Init(&RX_AUTON_PIN, RX_AUTON_PINN, RX_AUTON_INTN);
//g_auton_rx.Init(&RX_AUTON_PIN, RX_AUTON_PINN, RX_AUTON_INTN);

//Output information about code on arduino once to debug uart on startup.
printf("Hello world! This is debug information\r\n");
Expand Down Expand Up @@ -487,12 +487,12 @@ int main(void) {
break;
case RBSM_MID_MEGA_STEER_COMMAND:
auto_steering_angle = (int)(long)new_command.data;
auton_steer_last = micros();
//auton_steer_last = micros();
dbg_printf("Got steering message for %d.\n", auto_steering_angle);
break;
case RBSM_MID_MEGA_AUTON_BRAKE_COMMAND:
brake_cmd_auton_engaged = (bool)(long)new_command.data;
auton_brake_last = micros();
//brake_cmd_auton_engaged = (bool)(long)new_command.data;
//auton_brake_last = micros();
dbg_printf("Got brake message for %d.\n", brake_cmd_auton_engaged);
break;
default:
Expand All @@ -517,13 +517,13 @@ int main(void) {
// Check for RC commands
steer_angle = g_steering_rx.GetAngleHundredths();
brake_cmd_teleop_engaged = g_brake_rx.GetPulseWidth() > PWM_STATE_THRESHOLD;
g_is_autonomous = g_auton_rx.GetPulseWidth() > PWM_STATE_THRESHOLD;
//g_is_autonomous = g_auton_rx.GetPulseWidth() > PWM_STATE_THRESHOLD;

// Detect dropped radio conections

unsigned long time1 = g_steering_rx.GetLastTimestamp();
unsigned long time2 = g_brake_rx.GetLastTimestamp();
unsigned long time3 = g_auton_rx.GetLastTimestamp();
//unsigned long time3 = g_auton_rx.GetLastTimestamp();
//We need to call micros last because if we called it first,
// time1, time2, or time3 could be greater than time_now if an interrupt
// fires and updates its timestamp and our delta values will underflow
Expand All @@ -533,19 +533,19 @@ int main(void) {
//RC time deltas
unsigned long delta1 = time_now - time1;
unsigned long delta2 = time_now - time2;
unsigned long delta3 = time_now - time3;
//unsigned long delta3 = time_now - time3;
//Auton time deltas
unsigned long delta5 = time_now - auton_steer_last;
unsigned long delta4 = time_now - auton_brake_last;
//unsigned long delta5 = time_now - auton_steer_last;
//unsigned long delta4 = time_now - auton_brake_last;

bool rc_timeout = delta1 > CONNECTION_TIMEOUT_US ||
delta2 > CONNECTION_TIMEOUT_US ||
delta3 > CONNECTION_TIMEOUT_US;
delta2 > CONNECTION_TIMEOUT_US;
/*
bool auton_timeout = (g_is_autonomous == true) &&
(delta4 > CONNECTION_TIMEOUT_US ||
delta5 > CONNECTION_TIMEOUT_US);

if(rc_timeout || auton_timeout) {
*/
if(rc_timeout) {
// check for RC timout first
if(rc_timeout) {
// we haven't heard from the RC receiver in too long
Expand All @@ -558,6 +558,7 @@ int main(void) {
}

// then check for timeout under autonomous
/*
if(auton_timeout) {
g_errors |= _BV(RBSM_EID_AUTON_LOST_SIGNAL);
brake_needs_reset = true;
Expand All @@ -566,6 +567,7 @@ int main(void) {
} else {
g_errors &= ~_BV(RBSM_EID_AUTON_LOST_SIGNAL);
}
*/
// or reset the system if connection is back and driver engages brakes
} else {
if(brake_cmd_teleop_engaged == true) {
Expand Down
Loading

0 comments on commit 02bc349

Please sign in to comment.