Skip to content

Commit

Permalink
Driver cntrl validation (#270)
Browse files Browse the repository at this point in the history
* steering validation changes

* steering values updated + tested on mockup

* steering + brakes work
  • Loading branch information
Akashem06 authored Mar 28, 2024
1 parent a02f592 commit 0346df0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion projects/pedal/inc/pedal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "status.h"

#define BRAKE_LIMIT_SWITCH \
{ .port = GPIO_PORT_A, .pin = 7 }
{ .port = GPIO_PORT_B, .pin = 1 }

#define ADC_HALL_SENSOR \
{ .port = GPIO_PORT_A, .pin = 1 }
Expand Down
12 changes: 6 additions & 6 deletions projects/steering/inc/steering_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include "status.h"
#include "steering_setters.h"

#define VOLTAGE_TOLERANCE_MV 20
#define VOLTAGE_TOLERANCE_MV 100
// turn signal voltages
#define TURN_LEFT_SIGNAL_VOLTAGE_MV 1200
#define TURN_RIGHT_SIGNAL_VOLTAGE_MV 2130
#define NEUTRAL_SIGNAL_VOLTAGE_MV 2610
#define TURN_LEFT_SIGNAL_VOLTAGE_MV 2100
#define TURN_RIGHT_SIGNAL_VOLTAGE_MV 1200
#define NEUTRAL_SIGNAL_VOLTAGE_MV 3300
// cruise control voltages
#define CRUISE_CONTROl_STALK_SPEED_INCREASE_VOLTAGE_MV 1650
#define CRUISE_CONTROl_STALK_SPEED_DECREASE_VOLTAGE_MV 790
#define CRUISE_CONTROl_STALK_SPEED_INCREASE_VOLTAGE_MV 1600
#define CRUISE_CONTROl_STALK_SPEED_DECREASE_VOLTAGE_MV 775
#define CRUISE_CONTROl_STALK_NEUTRAL_VOLTAGE_MV 3300

#define TURN_SIGNAL_GPIO \
Expand Down
17 changes: 10 additions & 7 deletions projects/steering/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "gpio.h"
#include "gpio_it.h"
#include "gpio_mcu.h"
#include "interrupt.h"
#include "log.h"
#include "master_task.h"
#include "steering_task.h"
Expand All @@ -15,13 +16,18 @@
static CanStorage s_can_storage = { 0 };
const CanSettings can_settings = {
.device_id = SYSTEM_CAN_DEVICE_STEERING,
.bitrate = CAN_HW_BITRATE_125KBPS,
.bitrate = CAN_HW_BITRATE_500KBPS,
.tx = { GPIO_PORT_A, 12 },
.rx = { GPIO_PORT_A, 11 },
.loopback = true,
.loopback = false,
};

void pre_loop_init() {}
void pre_loop_init() {
// Setup analog inputs and initialize adc
Task *steering_master_task = get_master_task();
steering_init(steering_master_task);
adc_init();
}

void run_fast_cycle() {}

Expand All @@ -41,13 +47,10 @@ void run_slow_cycle() {}
int main() {
tasks_init();
log_init();
interrupt_init();
gpio_init();
gpio_it_init();

// Setup analog inputs and initialize adc
steering_init();
adc_init();

can_init(&s_can_storage, &can_settings);
init_master_task();
tasks_start();
Expand Down
11 changes: 9 additions & 2 deletions projects/steering/src/steering.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ StatusCode steering_init(Task *task) {
// Initialize Pins
gpio_init_pin(&turn_signal_address, GPIO_ANALOG, GPIO_STATE_LOW);
gpio_init_pin(&cc_address, GPIO_ANALOG, GPIO_STATE_LOW);
gpio_init_pin(&cc_toggle_address, GPIO_ANALOG, GPIO_STATE_LOW);
gpio_init_pin(&cc_toggle_address, GPIO_INPUT_FLOATING, GPIO_STATE_LOW);
// Set up ADC
adc_add_channel(turn_signal_address);
adc_add_channel(cc_address);
Expand All @@ -26,17 +26,21 @@ StatusCode steering_init(Task *task) {
return STATUS_CODE_OK;
}

void steering_input(uint32_t notification) {
void steering_input() {
uint16_t control_stalk_data;
uint32_t notification;
set_steering_info_input_cc(0);
LOG_DEBUG("RUNNING CYCLE\n");
// Read ADC of pin set by turn signal lights
adc_read_converted(turn_signal_address, &control_stalk_data);
// Determine if it's a left, right or off signal
if (control_stalk_data > TURN_LEFT_SIGNAL_VOLTAGE_MV - VOLTAGE_TOLERANCE_MV &&
control_stalk_data < TURN_LEFT_SIGNAL_VOLTAGE_MV + VOLTAGE_TOLERANCE_MV) {
LOG_DEBUG("LEFT\n");
set_steering_info_input_lights(TURN_SIGNAL_LEFT);
} else if (control_stalk_data > TURN_RIGHT_SIGNAL_VOLTAGE_MV - VOLTAGE_TOLERANCE_MV &&
control_stalk_data < TURN_RIGHT_SIGNAL_VOLTAGE_MV + VOLTAGE_TOLERANCE_MV) {
LOG_DEBUG("RIGHT\n");
set_steering_info_input_lights(TURN_SIGNAL_RIGHT);
} else {
set_steering_info_input_lights(TURN_SIGNAL_OFF);
Expand All @@ -48,17 +52,20 @@ void steering_input(uint32_t notification) {
control_stalk_data < CRUISE_CONTROl_STALK_SPEED_INCREASE_VOLTAGE_MV + VOLTAGE_TOLERANCE_MV) {
// toggle second bit to 1
set_steering_info_input_cc(CC_INCREASE_MASK | CC_INPUT);
LOG_DEBUG("CC INCREASE\n");
} else if (control_stalk_data >
CRUISE_CONTROl_STALK_SPEED_DECREASE_VOLTAGE_MV - VOLTAGE_TOLERANCE_MV &&
control_stalk_data <
CRUISE_CONTROl_STALK_SPEED_DECREASE_VOLTAGE_MV + VOLTAGE_TOLERANCE_MV) {
// toggle first bit to 1
set_steering_info_input_cc(CC_DECREASE_MASK | CC_INPUT);
LOG_DEBUG("CC DECREASE\n");
}
if (notify_get(&notification) == STATUS_CODE_OK) {
while (event_from_notification(&notification, &STEERING_EVENT) == STATUS_CODE_INCOMPLETE) {
if (STEERING_EVENT == CC_TOGGLE_EVENT) {
set_steering_info_input_cc(CC_TOGGLE_MASK | CC_INPUT);
LOG_DEBUG("CC TOGGLED\n");
}
}
}
Expand Down

0 comments on commit 0346df0

Please sign in to comment.