Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
135 changes: 135 additions & 0 deletions arduino_driver/arduino_driver.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#include "Keyboard.h"
#include "Mouse.h"

const int switch0Pin = 4; //on off
const int switch1Pin = 11; //autopilot
const int buttonR1Pin = 8; //R1
const int buttonR2Pin = 7; //R2
const int buttonR3Pin = 9; //R3
const int buttonL1Pin = 6; //L1
const int buttonL2Pin = 5; //L2
const int buttonL3Pin = 10; //L3

int prevR1State = HIGH;
int prevR2State = HIGH;
int prevR3State = HIGH;
int prevL1State = HIGH;
int prevL2State = HIGH;
int prevL3State = HIGH;

char prevOut = 'w';
char buckler_out = 'w';

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial1.begin(115200);
Keyboard.begin();
Mouse.begin();
}

void loop() {
// put your main code here, to run repeatedly:
//input coming in from buckler
int switch0State = digitalRead(switch0Pin);
int switch1State = digitalRead(switch1Pin);
int buttonR1State = digitalRead(buttonR1Pin);
int buttonR2State = digitalRead(buttonR2Pin);
int buttonR3State = digitalRead(buttonR3Pin);
int buttonL1State = digitalRead(buttonL1Pin);
int buttonL2State = digitalRead(buttonL2Pin);
int buttonL3State = digitalRead(buttonL3Pin);
if (Serial1.available() > 0) {
buckler_out = Serial1.read();
}
if (switch0State == HIGH) {
if ((buttonR1State != prevR1State) && (buttonR1State == HIGH)) {
Mouse.click(MOUSE_RIGHT);
}
if ((buttonL1State != prevL1State) && (buttonL1State == HIGH)) {
Mouse.click(MOUSE_LEFT);
}
if ((switch1State == HIGH)) {
if ((buttonR2State != prevR2State) && (buttonR2State == HIGH)) {
Keyboard.press('3');
} else if (buttonR2State != HIGH) {
Keyboard.release('3');
}
if ((buttonR3State != prevR3State) && (buttonR3State == HIGH)) {
Keyboard.press('4');
} else if (buttonR3State != HIGH) {
Keyboard.release('4');
}
if ((buttonL2State != prevL2State) && (buttonL2State == HIGH)) {
Keyboard.press('1');
} else if (buttonL2State != HIGH) {
Keyboard.release('1');
}
if ((buttonL3State != prevL3State) && (buttonL3State == HIGH)) {
Keyboard.press('2');
} else if (buttonL3State != HIGH) {
Keyboard.release('2');
}
if (Serial1.available() > 0) {
if (buckler_out != prevOut) {
Keyboard.releaseAll();
prevOut = buckler_out;
}
if (buckler_out == '-') {
Mouse.move(0, 4, 0);
Keyboard.press(KEY_LEFT_SHIFT);
} else if (buckler_out == '+') {
Mouse.move(0, -4, 0);
Keyboard.press(' ');
} else {
//w, a, d
Serial.print(buckler_out);
Keyboard.press(buckler_out);
}
} else {
Keyboard.releaseAll();
}
} else {
if ((buttonR2State != prevR2State) && (buttonR2State == HIGH)) {
Keyboard.press(' ');
} else if (buttonR2State != HIGH) {
Keyboard.release(' ');
}
if ((buttonR3State != prevR3State) && (buttonR3State == HIGH)) {
Keyboard.press('s');
} else if (buttonR3State != HIGH) {
Keyboard.release('s');
}
if ((buttonL2State != prevL2State) && (buttonL2State == HIGH)) {
Keyboard.press(KEY_LEFT_SHIFT);
} else if (buttonL2State != HIGH) {
Keyboard.release(KEY_LEFT_SHIFT);
}
if ((buttonL3State != prevL3State) && (buttonL3State == HIGH)) {
Keyboard.press('w');
} else if (buttonL3State != HIGH) {
Keyboard.release('w');
}
if (Serial1.available() > 0) {
if (buckler_out == '+') {
Mouse.move(0, -4, 0);
} else if (buckler_out == '-') {
Mouse.move(0, 4, 0);
} else if (buckler_out == 'a') {
Mouse.move(-4, 0, 0);
} else if (buckler_out == 'd') {
Mouse.move(4, 0, 0);
}
}
}
prevR1State = buttonR1State;
prevR2State = buttonR2State;
prevR3State = buttonR3State;
prevL1State = buttonL1State;
prevL2State = buttonL2State;
prevL3State = buttonL3State;
} else {
Keyboard.releaseAll();
}
delay(10);
}
Binary file added eecs149report.pdf
Binary file not shown.
Binary file added software/.DS_Store
Binary file not shown.
Binary file added software/apps/.DS_Store
Binary file not shown.
Binary file added software/apps/steering-controller/.DS_Store
Binary file not shown.
209 changes: 130 additions & 79 deletions software/apps/steering-controller/main.c
Original file line number Diff line number Diff line change
@@ -1,79 +1,130 @@
// Analog accelerometer app
//
// Reads data from the ADXL327 analog accelerometer

#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include "app_error.h"
#include "app_timer.h"
#include "nrf.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_drv_spi.h"

#include "buckler.h"
#include "display.h"
#include "lsm9ds1.h"
#include "steeringwheel.h"

NRF_TWI_MNGR_DEF(twi_mngr_instance, 5, 0);

int main(void) {
ret_code_t error_code = NRF_SUCCESS;

// initialize RTT library
error_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(error_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
printf("Log initialized!\n");

// initialize LEDs
nrf_gpio_pin_dir_set(23, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_dir_set(24, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_dir_set(25, NRF_GPIO_PIN_DIR_OUTPUT);

// initialize display
nrf_drv_spi_t spi_instance = NRF_DRV_SPI_INSTANCE(1);
nrf_drv_spi_config_t spi_config = {
.sck_pin = BUCKLER_LCD_SCLK,
.mosi_pin = BUCKLER_LCD_MOSI,
.miso_pin = BUCKLER_LCD_MISO,
.ss_pin = BUCKLER_LCD_CS,
.irq_priority = NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY,
.orc = 0,
.frequency = NRF_DRV_SPI_FREQ_4M,
.mode = NRF_DRV_SPI_MODE_2,
.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST
};
error_code = nrf_drv_spi_init(&spi_instance, &spi_config, NULL, NULL);
APP_ERROR_CHECK(error_code);
display_init(&spi_instance);
display_write("Turn me UWU", DISPLAY_LINE_0);
printf("Display initialized!\n");

nrf_drv_twi_config_t i2c_config = NRF_DRV_TWI_DEFAULT_CONFIG;
i2c_config.scl = BUCKLER_SENSORS_SCL;
i2c_config.sda = BUCKLER_SENSORS_SDA;
i2c_config.frequency = NRF_TWIM_FREQ_100K;
error_code = nrf_twi_mngr_init(&twi_mngr_instance, &i2c_config);
APP_ERROR_CHECK(error_code);
lsm9ds1_init(&twi_mngr_instance);
printf("IMU initialized!\n");

steering_wheel_state_t state = OFF;
// loop forever, running state machine
while (1) {
nrf_delay_ms(1);
state = controller(state);

}
}


// Analog accelerometer app
//
// Reads data from the ADXL327 analog accelerometer

#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include "app_error.h"
#include "app_timer.h"
#include "nrf.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_drv_spi.h"
#include "nrf_serial.h"

#include "buckler.h"
#include "display.h"
#include "lsm9ds1.h"
#include "steeringwheel.h"
//#include "nrf52dk.h"

//from https://github.com/lab11/nrf52x-base/blob/6ca5df7892d2a26c864b52f1b5bf383e16885d25/apps/demo_nrf52dk/main.c
// Serial configuration
// configuration for uart, RX & TX pin, empty RTS and CTS pins,
// flow control disabled, no parity bit, 115200 baud, default priority
NRF_SERIAL_DRV_UART_CONFIG_DEF(serial_uart_config, BUCKLER_UART_RX, BUCKLER_UART_TX, 0, 0,
NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED, NRF_UART_BAUDRATE_115200, UART_DEFAULT_CONFIG_IRQ_PRIORITY);
// create serial queues for commands, tx length 32, rx length 32
NRF_SERIAL_QUEUES_DEF(serial_queues1, 1, 1);
// create serial buffers for data, tx size 100 bytes, rx size 100 bytes
NRF_SERIAL_BUFFERS_DEF(serial_buffers1, 1, 1);
// create a configuration using DMA with queues for commands and buffers for data storage
// both handlers are set to NULL as we do not need to support them
NRF_SERIAL_CONFIG_DEF(serial_config1, NRF_SERIAL_MODE_DMA, &serial_queues1, &serial_buffers1, NULL, NULL);

NRF_SERIAL_UART_DEF(serial_uart_instance, 0);

NRF_TWI_MNGR_DEF(twi_mngr_instance, 5, 0);

//error handler
//uart code from https://github.com/lab11/nrf52x-base/blob/6ca5df7892d2a26c864b52f1b5bf383e16885d25/apps/uart/main.c
//UART initialization
int main(void) {
ret_code_t error_code = NRF_SUCCESS;

// init UART
nrf_serial_init(&serial_uart_instance, &serial_uart_config, &serial_config1);
static char tx_message[] = "u";
error_code = nrf_serial_write(&serial_uart_instance, tx_message, strlen(tx_message), NULL, 0);
APP_ERROR_CHECK(error_code);

// initialize RTT library
error_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(error_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
printf("Log initialized!\n");
// initialize LEDs
nrf_gpio_pin_dir_set(23, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_dir_set(24, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_dir_set(25, NRF_GPIO_PIN_DIR_OUTPUT);

// initialize display
nrf_drv_spi_t spi_instance = NRF_DRV_SPI_INSTANCE(1);
nrf_drv_spi_config_t spi_config = {
.sck_pin = BUCKLER_LCD_SCLK,
.mosi_pin = BUCKLER_LCD_MOSI,
.miso_pin = BUCKLER_LCD_MISO,
.ss_pin = BUCKLER_LCD_CS,
.irq_priority = NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY,
.orc = 0,
.frequency = NRF_DRV_SPI_FREQ_4M,
.mode = NRF_DRV_SPI_MODE_2,
.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST
};
error_code = nrf_drv_spi_init(&spi_instance, &spi_config, NULL, NULL);
APP_ERROR_CHECK(error_code);
display_init(&spi_instance);
display_write("Turn me UWU1", DISPLAY_LINE_0);
printf("Display initialized!\n");

nrf_drv_twi_config_t i2c_config = NRF_DRV_TWI_DEFAULT_CONFIG;
i2c_config.scl = BUCKLER_SENSORS_SCL;
i2c_config.sda = BUCKLER_SENSORS_SDA;
i2c_config.frequency = NRF_TWIM_FREQ_100K;
error_code = nrf_twi_mngr_init(&twi_mngr_instance, &i2c_config);
APP_ERROR_CHECK(error_code);
lsm9ds1_init(&twi_mngr_instance);
printf("IMU initialized!\n");

steering_wheel_state_t state = OFF;
// loop forever, running state machine

while (1) {
nrf_delay_ms(1);
state = controller(state);
if (state == STRAIGHT) {
static char tx_message[] = "w";
error_code = nrf_serial_write(&serial_uart_instance, tx_message, strlen(tx_message), NULL, 0);
APP_ERROR_CHECK(error_code);
printf("STRAIGHT");
} else if (state == LEFT) {
static char tx_message[] = "a";
error_code = nrf_serial_write(&serial_uart_instance, tx_message, strlen(tx_message), NULL, 0);
APP_ERROR_CHECK(error_code);
printf("LEFT");
} else if (state == RIGHT) {
static char tx_message[] = "d";
error_code = nrf_serial_write(&serial_uart_instance, tx_message, strlen(tx_message), NULL, 0);
APP_ERROR_CHECK(error_code);
printf("RIGHT");
} else if (state == PITCHUP) {
static char tx_message[] = "+";
error_code = nrf_serial_write(&serial_uart_instance, tx_message, strlen(tx_message), NULL, 0);
APP_ERROR_CHECK(error_code);
printf("RIGHT");
} else if (state == PITCHDN) {
static char tx_message[] = "-";
error_code = nrf_serial_write(&serial_uart_instance, tx_message, strlen(tx_message), NULL, 0);
APP_ERROR_CHECK(error_code);
printf("RIGHT");
}
}
nrf_serial_uninit(&serial_uart_instance);
}
Loading