Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final Firmware used at Comp #16

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
861a5ef
Begin creating can send and receive functionality
Burke-Daniel May 23, 2022
25a2f2b
Add return statuses and fix mailbox stuff
Burke-Daniel May 24, 2022
44065b7
Begin writing method to handle received can messages
Burke-Daniel May 26, 2022
2fb0798
tidy up LED test code
Burke-Daniel May 26, 2022
0fe903e
Add header of CAN message IDs
Burke-Daniel May 26, 2022
b4176d1
Fixes to get CAN bus working
Burke-Daniel May 29, 2022
913bbf8
Temp commit
Burke-Daniel May 29, 2022
51bcb6a
Get Motor control working
Burke-Daniel May 30, 2022
7e46bd0
Controlling multiple motors simultaneously
Burke-Daniel May 30, 2022
debab97
Current control of motors
Burke-Daniel May 30, 2022
0636340
Allow for each uart to receive data
Burke-Daniel May 31, 2022
c5752aa
set up callbacks for each uart
Burke-Daniel May 31, 2022
a0f8a70
Implemented prelim State and LED Actuations
Ian-Carroll Jun 2, 2022
698025f
Fixed get_next_state() e-stop
Ian-Carroll Jun 2, 2022
c7054c7
Implemented Node state machine
Ian-Carroll Jun 4, 2022
2580d0f
Set up PB7 as external interrupt
Burke-Daniel Jun 4, 2022
2a2ece9
Add PA15 as another interrupt pin
Burke-Daniel Jun 4, 2022
8b0967b
Implemented physical and wireless e-stop
Ian-Carroll Jun 4, 2022
71419eb
Added prelim diagnose for BOOT state
Ian-Carroll Jun 5, 2022
48cdbdd
Break state out into own file
Burke-Daniel Jun 5, 2022
1d0c2e9
Implement heartbeat functionality
Burke-Daniel Jun 5, 2022
3bc2ff3
Refactor motor commands to have separate commands for autonomous and
Burke-Daniel Jun 5, 2022
e838bd2
Fix motor command message ids
Burke-Daniel Jun 5, 2022
7620083
Break motor control out into its own file
Burke-Daniel Jun 5, 2022
145ba02
Add duty cycle control to can handle
Burke-Daniel Jun 5, 2022
21dc7f3
Added comparators and handle more can messages
Ian-Carroll Jun 5, 2022
9b977e2
First try at Boot->Standby
Burke-Daniel Jun 5, 2022
352b123
Change criteria for valid vesc data
Burke-Daniel Jun 5, 2022
17265cd
Only try and get values on specified interval
Burke-Daniel Jun 5, 2022
f7da2d1
Main testing and motor mask fix
Ian-Carroll Jun 5, 2022
d71bee3
Main cleanup and fix boot case in state.c
Ian-Carroll Jun 5, 2022
0a4bf19
Merge branch 'feature/motor-control-1' of github.com:ParadigmBoring/i…
Burke-Daniel Jun 5, 2022
78a0a83
Merge branch 'feature/motor-control-1' of github.com:ParadigmBoring/i…
Burke-Daniel Jun 5, 2022
1c16534
Housekeeping and tidying
Burke-Daniel Jun 5, 2022
60a9e66
Comment out getting values from motor
Burke-Daniel Jun 5, 2022
8476b12
Send current state less frequency
Burke-Daniel Jun 5, 2022
854af90
Update current and rpm constants
Ian-Carroll Aug 29, 2022
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
9 changes: 9 additions & 0 deletions Node/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
Build/
Drivers
Makefile
.mxproject
Expand All @@ -8,5 +9,13 @@ Core/Inc
Core/Src
!Core/Src/main.c
!Core/Inc/main.h
!Core/Src/can_handler.c
!Core/Inc/can_handler.h
!Core/Inc/utilities.h
!Core/Inc/can_message_defs.h
!Core/Src/state.c
!Core/Inc/state.h
!Core/Src/motor_control.c
!Core/Inc/motor_control.h
compile_commands.json
.cache/
21 changes: 17 additions & 4 deletions Node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ set(STM32CUBEMX_GENERATED_FILES
Core/Src/main.c
Core/Src/gpio.c
Core/Src/can.c
Core/Src/i2c.c
Core/Src/spi.c
Core/Src/tim.c
Core/Src/usart.c
Core/Src/stm32f3xx_it.c
Expand Down Expand Up @@ -43,15 +41,30 @@ set(STM32CUBEMX_GENERATED_FILES
startup_stm32f334x8.s
)

set(STM32_USER_CREATED_FILES
Core/Src/can_handler.c
Core/Src/state.c
Core/Src/motor_control.c
)

set(EXTERNAL_FILES
External/Src/bldc_interface_uart.c
External/Src/bldc_interface.c
External/Src/buffer.c
External/Src/crc.c
External/Src/packet.c
)

set(EXECUTABLE ${PROJECT_NAME}.out)
add_executable(${EXECUTABLE} ${STM32CUBEMX_GENERATED_FILES})
add_executable(${EXECUTABLE} ${STM32CUBEMX_GENERATED_FILES} ${STM32_USER_CREATED_FILES} ${EXTERNAL_FILES})

target_compile_definitions(${EXECUTABLE} PRIVATE
-DUSE_HAL_DRIVER
-DSTM32F334x8
)

target_include_directories(${EXECUTABLE} PRIVATE
External/Inc
Core/Inc
Drivers/STM32F3xx_HAL_Driver/Inc
Drivers/CMSIS/Device/ST/STM32F3xx/Include
Expand All @@ -69,7 +82,7 @@ target_compile_options(${EXECUTABLE} PRIVATE

-Wall

$<$<CONFIG:Debug>:-Og>
-Og
)

target_link_options(${EXECUTABLE} PRIVATE
Expand Down
21 changes: 21 additions & 0 deletions Node/Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <can.h>

typedef struct CanMessage
{
uint16_t id;
uint8_t len;
uint8_t data[8];
} CanMessage;

typedef enum CanStatus
{
CAN_GOOD,
CAN_RX_FIFO_EMPTY,
CAN_TX_MAILBOXES_FULL,
CAN_DATA_TOO_LONG,
} CanStatus;

CanStatus receive_can_message(CanMessage* message);
CanStatus send_can_message(CanMessage* message);
CanStatus send_can_message_blocking(CanMessage* message);
void handle_can_messages(uint8_t num_msgs_to_handle);
70 changes: 70 additions & 0 deletions Node/Core/Inc/can_message_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#define HEARTBEAT_ID 0x0001

#define STATE_CHANGE_CAN_ID 0x0010
#define STANDBY_REQUEST_CAN_ID 0x0011
#define AUTONOMOUS_REQUEST_CAN_ID 0x0012
#define MANUAL_REQUEST_CAN_ID 0x0013
#define BOOT_RESPONSE_CAN_ID 0x0016
#define STANDBY_RESPONSE_CAN_ID 0x0017
#define AUTONOMOUS_RESPONSE_CAN_ID 0x0018
#define MANUAL_RESPONSE_CAN_ID 0x0019

#define NODE_GOOD_CAN_ID_MASK 0x0014
#define NODE_BAD_CAN_ID_MASK 0x0015

#define MOTOR_CONTROL_RPM_MASK_MANUAL 0x0020
#define MOTOR_1_RPM_MANUAL 0x0021
#define MOTOR_2_RPM_MANUAL 0x0022
#define MOTOR_3_RPM_MANUAL 0x0023

#define MOTOR_CONTROL_RPM_MASK_AUTONOMOUS 0x0040
#define MOTOR_1_RPM_AUTONOMOUS 0x0041
#define MOTOR_2_RPM_AUTONOMOUS 0x0042
#define MOTOR_3_RPM_AUTONOMOUS 0x0043

#define IS_MOTOR1_RPM_CONTROL(motor) ((motor == MOTOR_1_RPM_AUTONOMOUS) || (motor == MOTOR_1_RPM_MANUAL))
#define IS_MOTOR2_RPM_CONTROL(motor) ((motor == MOTOR_2_RPM_AUTONOMOUS) || (motor == MOTOR_2_RPM_MANUAL))
#define IS_MOTOR3_RPM_CONTROL(motor) ((motor == MOTOR_3_RPM_AUTONOMOUS) || (motor == MOTOR_3_RPM_MANUAL))

#define MOTOR_CONTROL_CURRENT_MASK_MANUAL 0x0080
#define MOTOR_1_CURRENT_MANUAL 0x0081
#define MOTOR_2_CURRENT_MANUAL 0x0082
#define MOTOR_3_CURRENT_MANUAL 0x0083

#define MOTOR_CONTROL_CURRENT_MASK_AUTONOMOUS 0x0100
#define MOTOR_1_CURRENT_AUTONOMOUS 0x0101
#define MOTOR_2_CURRENT_AUTONOMOUS 0x0102
#define MOTOR_3_CURRENT_AUTONOMOUS 0x0103

#define IS_MOTOR1_CURRENT_CONTROL(motor) ((motor == MOTOR_1_CURRENT_AUTONOMOUS) || (motor == MOTOR_1_CURRENT_MANUAL))
#define IS_MOTOR2_CURRENT_CONTROL(motor) ((motor == MOTOR_2_CURRENT_AUTONOMOUS) || (motor == MOTOR_2_CURRENT_MANUAL))
#define IS_MOTOR3_CURRENT_CONTROL(motor) ((motor == MOTOR_3_CURRENT_AUTONOMOUS) || (motor == MOTOR_3_CURRENT_MANUAL))

#define MOTOR_CONTROL_DUTY_CYCLE_MASK_MANUAL 0x0200
#define MOTOR_1_DUTY_CYCLE_MANUAL 0x0201
#define MOTOR_2_DUTY_CYCLE_MANUAL 0x0202
#define MOTOR_3_DUTY_CYCLE_MANUAL 0x0203

#define MOTOR_CONTROL_DUTY_CYCLE_MASK_AUTONOMOUS 0x0400
#define MOTOR_1_DUTY_CYCLE_AUTONOMOUS 0x0401
#define MOTOR_2_DUTY_CYCLE_AUTONOMOUS 0x0402
#define MOTOR_3_DUTY_CYCLE_AUTONOMOUS 0x0403

#define IS_MOTOR1_DUTY_CYCLE_CONTROL(motor) ((motor == MOTOR_1_DUTY_CYCLE_AUTONOMOUS) || (motor == MOTOR_1_DUTY_CYCLE_MANUAL))
#define IS_MOTOR2_DUTY_CYCLE_CONTROL(motor) ((motor == MOTOR_2_DUTY_CYCLE_AUTONOMOUS) || (motor == MOTOR_2_DUTY_CYCLE_MANUAL))
#define IS_MOTOR3_DUTY_CYCLE_CONTROL(motor) ((motor == MOTOR_3_DUTY_CYCLE_AUTONOMOUS) || (motor == MOTOR_3_DUTY_CYCLE_MANUAL))

#define WIRELESS_ESTOP 120

#define LED_1_TEST_ON 0x0002
#define LED_2_TEST_ON 0x0003
#define LAMP_1_TEST_ON 0x0004
#define LAMP_2_TEST_ON 0x0005
#define LAMP_3_TEST_ON 0x0006
#define LAMP_4_TEST_ON 0x0007
#define LED_1_TEST_OFF 0x0008
#define LED_2_TEST_OFF 0x0009
#define LAMP_1_TEST_OFF 0x000a
#define LAMP_2_TEST_OFF 0x000b
#define LAMP_3_TEST_OFF 0x000c
#define LAMP_4_TEST_OFF 0x000d
7 changes: 7 additions & 0 deletions Node/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extern "C" {

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
#include "bldc_interface.h"


/* USER CODE END ET */

Expand All @@ -53,6 +55,11 @@ extern "C" {
void Error_Handler(void);

/* USER CODE BEGIN EFP */
extern BldcInterface motor1;
extern BldcInterface motor2;
extern BldcInterface motor3;
extern uint8_t vesc_data_valid[3];
int heartbeat_expired(uint32_t last_heartbeat_received_ms);

/* USER CODE END EFP */

Expand Down
10 changes: 10 additions & 0 deletions Node/Core/Inc/motor_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef MOTOR_CONTROL_H
#define MOTOR_CONTROL_H

#include <stdint.h>

void motor_control_rpm(uint32_t id, uint8_t data[]);
void motor_control_current(uint32_t id, uint8_t data[]);
void motor_control_duty_cycle(uint32_t id, uint8_t data[]);

#endif
20 changes: 20 additions & 0 deletions Node/Core/Inc/state.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef STATE_H
#define STATE_H

#include <stdint.h>

typedef enum
{
STANDBY,
AUTONOMOUS,
MANUAL,
BOOT
} state;

void get_next_state(uint32_t id);

extern state curr_state;
extern state next_state;
extern uint32_t last_heartbeat_received;

#endif
1 change: 1 addition & 0 deletions Node/Core/Inc/utilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
Loading