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
88 changes: 79 additions & 9 deletions Autonomous_Parallel_Parking/Autonomous_Parallel_Parking.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,98 @@
/***************************************************************************************************************
Authors: Harikrishnan G Nair
Denny Mathews
John Vasques
John Vasquez
Steven Pill
Harish Puvvada

Description: This is the file that contains the applicaiton source code. More coming up!!

*****************************************************************************************************************

Copyright © 2017 Harikrishnan G Nair, Denny Mathews, John Vasques, Steven Pill, Harish Puvvada @ NYU

Copyright © 2017 Harikrishnan G Nair, Denny Mathews, John Vasquez, Steven Pill, Harish Puvvada @ NYU
****************************************************************************************************************/

// C standard include(s):
#include <math.h>

// Custom user APIs needed for hardware access specific to this board:
#include "cpu.h"
#include "board_led.h"
#include "interrupts.h"
#include "uart.h"
#include <stdio.h>
#include "motion.h"
#include "state_machine.h"
#include "sensor_timer.h"
#include "pwm_hal.h"

// Custom user APIs needed for generic algorithmic libraries that are hardware-independent:
#include "foo.h"



int main()
{
/*
Initialize the PLL, clock tree to all peripherals, flash and Systick 1 ms time reference:
*/
cpu_init();
board_led_init();

uart_debug_init();
//GPIOInterruptSetup();
init_sensor();
state_init();

//Set PE8, blue LED
Pin_Set(GPIOE, GPIO_PIN_8, GPIO_MODE_OUTPUT_PP, GPIO_PULLDOWN, GPIO_SPEED_FREQ_LOW);
Pin_Set(GPIOE, GPIO_PIN_9, GPIO_MODE_OUTPUT_PP, GPIO_PULLDOWN, GPIO_SPEED_FREQ_LOW);


/*
Initialize the PWM outputs by configuring the corresponding channels
*/
init_pwm();

/*
Test a series of movements:
*/


int i = 0;
uint8_t next_dir;
while(1)
{
/*
Carry out a simple unit test of foo() declared in foo.h:
*/
if(TEST_FOO(i, i+1) < 0)
{
/*
If the above fails there is either a hardware, code or other undefined error.
Now we're in an undefined state regarding processor core behavior...
*/
while(1); // We probably have had a radiation hit or a major malfunction on the ALU of the processor...
}
else
{
// move_robot(STOP);

next_dir = state_execute();
move_robot(next_dir);
//cpu_sw_delay(10U);

//trigger_sensor(sensor_front) ;

// cpu_sw_delay(10U);
// if (g_inches_f < 20)
// move_back();
// cpu_sw_delay(500U);
// turn_f_right();
// cpu_sw_delay(500U);
// turn_f_left();
// cpu_sw_delay(500U);
// brake();
// cpu_sw_delay(500U);

}
}

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

void cpu_init(void); // This function calls all CPU HAL (Hardware Abstraction Layer)-specific functions that initialize the CPU clock, flash and peripherals.
void cpu_sw_delay(uint32_t ms); // A simple busy-loop delay function that blocks until the specified ms number of milliseconds have elapsed.
void cpu_sw_udelay(uint32_t us); // A simple busy-loop delay function that blocks until the specified ms number of milliseconds have elapsed.

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef INTERRUPTS
#define INTERRUPTS 1

#include "pin_setup.h"
#include "hal_common_includes.h"

//Interrupt initialization functions
void GPIOInterruptSetup();


//Interrupt IRQ's
void EXTI0_IRQHandler(void);
void EXTI2_TSC_IRQHandler(void);
void EXTI4_IRQHandler(void);

#endif
16 changes: 16 additions & 0 deletions Autonomous_Parallel_Parking/user_include/hal_interface/motor_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef MOTOR_HAL_H_
#define MOTOR_HAL_H_ 1

#include "hal_common_includes.h"

#define TIMER_PERIOD_1KHZ 6545

typedef enum {
motor1,
motor2
} motor_id;

void motor_init(void);
void test_motor_gpio(char value);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef PIN_SETUP
#define PIN_SETUP 1

#include "stm32f3xx_hal_gpio.h"


void Pin_Set(GPIO_TypeDef* GPIOx, uint32_t pins, uint32_t mode, uint32_t pull, uint32_t speed);

#endif
18 changes: 18 additions & 0 deletions Autonomous_Parallel_Parking/user_include/hal_interface/pwm_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef PWM_HAL_H_
#define PWM_HAL_H_ 1

#include "hal_common_includes.h"

#define TIMER_PERIOD_1KHZ 6545



void init_pwm(void);
void configure_channel(uint32_t channel_no, uint32_t new_pulse);

void start_channel(uint32_t channel_no);

void stop_channel(uint32_t channel_no);


#endif
15 changes: 15 additions & 0 deletions Autonomous_Parallel_Parking/user_include/hal_interface/uart_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef UART_HAL_H_
#define UART_HAL_H_ 1

#include "hal_common_includes.h"

typedef enum {
UART_PORT1
} uart_port;

void uart_hal_init(uart_port port);

void uart_hal_send_byte_blocking(uart_port port, uint8_t data);
uint8_t uart_hal_get_byte_blocking(uart_port port);

#endif
14 changes: 14 additions & 0 deletions Autonomous_Parallel_Parking/user_include/motion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef MOTION_H_
#define MOTION_H_ 1

#include <stdint.h>
#include "hal_common_includes.h"

#define LEFT 0U
#define RIGHT 1U
#define FORWARD 3U
#define BACK 4U
#define STOP 5U
void move_robot(uint8_t next_dir);

#endif // MOTION_H_
31 changes: 31 additions & 0 deletions Autonomous_Parallel_Parking/user_include/sensor_timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef SENSOR_TIMER_H_
#define SENSOR_TIMER_H_ 1

#include <stdint.h>
#include "hal_common_includes.h"

void InitializeTimer();
typedef enum {
sensor_front,
sensor_left,
sensor_right
} sensor_id;


float usensor_check_distance(int sensor_id);

// //Initialize ultrasound sensor gpio as needed for the board we are using.
// void usensor_gpio_init(void);

// //Simple software delay microseconds.
// void delay_us(uint32_t n);

// //Measures a pulse in microseconds.
// long pulse_in(GPIO_TypeDef* echo_port, uint32_t hexval);


void trigger_sensor(int sensor_no);

void init_sensor();
// HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority);
#endif
22 changes: 22 additions & 0 deletions Autonomous_Parallel_Parking/user_include/state_machine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef STATE_MACHINE_H_
#define STATE_MACHINE_H_ 1

#include "hal_common_includes.h"

#define TIMER_PERIOD_1KHZ 6545
#// uncomment for parallel parking
#define CURR_MODE_PERPENDICULAR

typedef enum {
STATE_IDLE,
STATE_FOLLOW_WALL,
STATE_PARK,
STATE_STOP
} states;

void state_init(void);

uint8_t state_execute(void);


#endif // STATE_MACHINE_H_
31 changes: 31 additions & 0 deletions Autonomous_Parallel_Parking/user_include/u_sensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// #ifndef U_SENSOR_H
// #define U_SENSOR_H 1

// #include "stm32f3xx_hal.h"
// #include "hal_common_includes.h"




// typedef enum {
// sensor_front,
// sensor_left,
// sensor_right
// } motor_id;




// //Initialize ultrasound sensor gpio as needed for the board we are using.
// void usensor_gpio_init(void);

// //Simple software delay microseconds.
// void delay_us(uint32_t n);

// //Measures a pulse in microseconds.
// long pulse_in(GPIO_TypeDef* echo_port);

// //Returns the distance from object.
// int get_sensor_dist(GPIO_TypeDef* trig_port, GPIO_TypeDef* echo_port, uint16_t trigger);

// #endif
17 changes: 17 additions & 0 deletions Autonomous_Parallel_Parking/user_include/uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef UART_H_
#define UART_H_ 1

#include "uart_hal.h"

#define DEBUG_UART UART_PORT1

void uart_debug_init(void);
void uart_init(uart_port port);

uint8_t uart_get_byte_blocking(uart_port port);
void uart_send_byte_blocking(uart_port port, uint8_t data);

void uart_get_data_blocking(uart_port port, uint8_t* data, uint8_t len);
void uart_send_data_blocking(uart_port port, uint8_t* data, uint8_t len);

#endif
17 changes: 16 additions & 1 deletion Autonomous_Parallel_Parking/user_source/hal_interface/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@ void cpu_sw_delay(uint32_t ms)
asm("nop");
}
}
}
}


void cpu_sw_udelay(uint32_t us)
{
uint32_t i = 0U;
uint32_t j = 0U;

for(i = 0U; i < us; ++i)
{
for(j = 0U; j < (uint32_t)CPU_TICKS_PER_MS/1000; ++j)
{
asm("nop");
}
}
}
Loading