-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0361693
commit d554de3
Showing
12 changed files
with
644 additions
and
60 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
VERSION "" | ||
|
||
|
||
NS_ : | ||
NS_DESC_ | ||
CM_ | ||
BA_DEF_ | ||
BA_ | ||
VAL_ | ||
CAT_DEF_ | ||
CAT_ | ||
FILTER | ||
BA_DEF_DEF_ | ||
EV_DATA_ | ||
ENVVAR_DATA_ | ||
SGTYPE_ | ||
SGTYPE_VAL_ | ||
BA_DEF_SGTYPE_ | ||
BA_SGTYPE_ | ||
SIG_TYPE_REF_ | ||
VAL_TABLE_ | ||
SIG_GROUP_ | ||
SIG_VALTYPE_ | ||
SIGTYPE_VALTYPE_ | ||
BO_TX_BU_ | ||
BA_DEF_REL_ | ||
BA_REL_ | ||
BA_DEF_DEF_REL_ | ||
BU_SG_REL_ | ||
BU_EV_REL_ | ||
BU_BO_REL_ | ||
SG_MUL_VAL_ | ||
|
||
BS_: | ||
|
||
BU_: SG FC | ||
|
||
|
||
BO_ 257 speedGoat_tx: 1 SG | ||
SG_ sg_driverSpeaker : 1|1@1- (1,0) [0|1] "" FC | ||
SG_ sg_brakeLightEn : 0|1@1- (1,0) [0|1] "" FC | ||
|
||
BO_ 256 fc_tx: 8 FC | ||
SG_ fc_hvilStatus : 41|1@1- (1,0) [0|1] "" SG | ||
SG_ fc_startButton : 40|1@1- (1,0) [0|1] "" SG | ||
SG_ fc_steeringAngle : 32|8@1+ (0.005,0) [0|1] "" SG | ||
SG_ fc_bpps2 : 24|8@1+ (0.005,0) [0|1] "" SG | ||
SG_ fc_bpps1 : 16|8@1+ (0.005,0) [0|1] "" SG | ||
SG_ fc_apps2 : 8|8@1+ (0.005,0) [0|1] "" SG | ||
SG_ fc_apps1 : 0|8@1+ (0.005,0) [0|1] "" SG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Samuel Parent | ||
# January 6, 2023 | ||
|
||
# The target executable 'main' is created in the master CMakeLists. Do not change its name. | ||
# We only need to add the source code files and include directories. | ||
|
||
find_package(Python3 COMPONENTS Interpreter) | ||
message(${Python3_EXECUTABLE}) | ||
|
||
if(NOT ${Python3_FOUND}) | ||
message(FATAL_ERROR "Python 3 executable not found") | ||
endif() | ||
|
||
FILE(GLOB_RECURSE CAN_DEPENDENCIES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/../scripts/cangen/*" "${CMAKE_SOURCE_DIR}/dbcs/*") | ||
|
||
list(APPEND CAN_DEPENDENCIES "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml") | ||
|
||
add_custom_target( | ||
generated_can | ||
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/../scripts/cangen/main.py" "--project=\"EvActive\"" | ||
DEPENDS ${CAN_DEPENDENCIES} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMENT Generating CAN code from DBCs | ||
) | ||
|
||
target_sources(main | ||
PRIVATE | ||
main.cc | ||
) | ||
add_dependencies(main generated_can) | ||
|
||
target_include_directories(main | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/inc | ||
) | ||
|
||
# Link ETL which is needed for generated/can/msg_registry.h | ||
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party) | ||
target_link_libraries(main PRIVATE etl) | ||
|
||
# Notice that we don't include any mcal/ subdirectory in this CMake file. | ||
# The master CMakeLists handles platform selection and library linking. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Front Controller | ||
|
||
Based on [FC Gen2](https://github.com/macformula/front_controller/tree/main/FC_GEN2). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
canGen: | ||
ourNode: FC | ||
busName: veh | ||
dbcFiles: | ||
- "veh_test.dbc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/// @author Samuel Parent | ||
/// @date 2024-05-05 | ||
|
||
#include <cstdint> | ||
|
||
#include "generated/can/can_messages.h" | ||
#include "generated/can/msg_registry.h" | ||
#include "shared/comms/can/can_bus.h" | ||
#include "shared/periph/adc.h" | ||
#include "shared/periph/gpio.h" | ||
#include "shared/util/mappers/linear_map.h" | ||
|
||
namespace bindings { | ||
extern shared::periph::CanBase& veh_can_base; | ||
|
||
extern shared::periph::ADCInput& accel_pedal_pos_1; | ||
extern shared::periph::ADCInput& accel_pedal_pos_2; | ||
extern shared::periph::ADCInput& brake_pedal_pos_1; | ||
extern shared::periph::ADCInput& brake_pedal_pos_2; | ||
extern shared::periph::ADCInput& suspension_travel_1; | ||
extern shared::periph::ADCInput& suspension_travel_2; | ||
extern shared::periph::ADCInput& hvil_feedback; | ||
extern shared::periph::ADCInput& steering_angle; | ||
|
||
extern shared::periph::DigitalInput& start_button_n; | ||
extern shared::periph::DigitalInput& wheel_speed_left_a; | ||
extern shared::periph::DigitalInput& wheel_speed_left_b; | ||
extern shared::periph::DigitalInput& wheel_speed_right_a; | ||
extern shared::periph::DigitalInput& wheel_speed_right_b; | ||
|
||
extern shared::periph::DigitalOutput& debug_led_en; | ||
extern shared::periph::DigitalOutput& dashboard_en; | ||
extern shared::periph::DigitalOutput& hvil_led_en; | ||
extern shared::periph::DigitalOutput& brake_light_en; | ||
extern shared::periph::DigitalOutput& status_led_en; | ||
extern shared::periph::DigitalOutput& rtds_en; | ||
|
||
extern void Initialize(); | ||
extern void TickBlocking(uint32_t); | ||
} // namespace bindings | ||
|
||
/*************************************************************** | ||
Objects | ||
***************************************************************/ | ||
|
||
generated::can::VehMsgRegistry veh_can_registry{}; | ||
|
||
shared::can::CanBus veh_can_bus{ | ||
bindings::veh_can_base, | ||
veh_can_registry, | ||
}; | ||
|
||
shared::util::LinearMap<float, uint32_t> adc_to_voltage{ | ||
static_cast<float>(3.3 / 4095.0), 0}; | ||
|
||
int main(void) { | ||
bindings::Initialize(); | ||
|
||
// Digital input values | ||
bool start_button_n_value; | ||
bool wheel_speed_left_a_value; | ||
bool wheel_speed_left_b_value; | ||
bool wheel_speed_right_a_value; | ||
bool wheel_speed_right_b_value; | ||
|
||
// Adc values | ||
uint32_t accel_pedal_pos_1_value; | ||
uint32_t accel_pedal_pos_2_value; | ||
uint32_t brake_pedal_pos_1_value; | ||
uint32_t brake_pedal_pos_2_value; | ||
uint32_t suspension_travel_1_value; | ||
uint32_t suspension_travel_2_value; | ||
uint32_t hvil_feedback_value; | ||
uint32_t steering_angle_value; | ||
|
||
// CAN Messages | ||
generated::can::speedGoat_tx from_speedgoat; | ||
generated::can::fc_tx to_speedgoat; | ||
|
||
while (1) { | ||
// Read all input | ||
accel_pedal_pos_1_value = bindings::accel_pedal_pos_1.Read(); | ||
accel_pedal_pos_2_value = bindings::accel_pedal_pos_2.Read(); | ||
brake_pedal_pos_1_value = bindings::brake_pedal_pos_1.Read(); | ||
brake_pedal_pos_2_value = bindings::brake_pedal_pos_2.Read(); | ||
steering_angle_value = bindings::steering_angle.Read(); | ||
hvil_feedback_value = bindings::hvil_feedback.Read(); | ||
start_button_n_value = bindings::start_button_n.Read(); | ||
|
||
// Pack CAN Message and send | ||
to_speedgoat.fc_start_button = !start_button_n_value; | ||
// TODO: this is random, it is a 12 bit adc so i chose down the middle | ||
// to be the cuttoff | ||
to_speedgoat.fc_hvil_status = hvil_feedback_value > 2048; | ||
to_speedgoat.fc_apps1 = | ||
adc_to_voltage.Evaluate(accel_pedal_pos_1_value); | ||
to_speedgoat.fc_apps2 = | ||
adc_to_voltage.Evaluate(accel_pedal_pos_2_value); | ||
to_speedgoat.fc_bpps1 = | ||
adc_to_voltage.Evaluate(brake_pedal_pos_1_value); | ||
to_speedgoat.fc_bpps2 = | ||
adc_to_voltage.Evaluate(brake_pedal_pos_2_value); | ||
to_speedgoat.fc_steering_angle = | ||
adc_to_voltage.Evaluate(steering_angle_value); | ||
veh_can_bus.Send(to_speedgoat); | ||
|
||
// Get values from Speedgoat CAN message | ||
veh_can_bus.ReadWithUpdate(from_speedgoat); | ||
|
||
bindings::brake_light_en.Set(from_speedgoat.sg_brake_light_en); | ||
bindings::rtds_en.Set(from_speedgoat.sg_driver_speaker); | ||
|
||
bindings::TickBlocking(10); | ||
} | ||
|
||
return 0; | ||
} |
7 changes: 7 additions & 0 deletions
7
firmware/projects/EvActive/platforms/stm32f767/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Blake Freer | ||
# January 8, 2024 | ||
|
||
add_subdirectory(cubemx) | ||
|
||
target_sources(bindings PUBLIC bindings.cc) | ||
target_link_libraries(bindings PUBLIC driver mcal-stm32f767) |
106 changes: 106 additions & 0 deletions
106
firmware/projects/EvActive/platforms/stm32f767/bindings.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/// @author Blake Freer | ||
/// @date 2024-02-27 | ||
|
||
// cubemx files | ||
#include "adc.h" | ||
#include "can.h" | ||
#include "cubemx/Inc/main.h" | ||
#include "gpio.h" | ||
|
||
// fw imports | ||
#include "mcal/stm32f767/periph/adc.h" | ||
#include "mcal/stm32f767/periph/can.h" | ||
#include "mcal/stm32f767/periph/gpio.h" | ||
#include "shared/periph/can.h" | ||
|
||
namespace mcal { | ||
using namespace stm32f767::periph; | ||
|
||
CanBase veh_can_base{&hcan3}; | ||
|
||
ADCInput accel_pedal_pos_1{&hadc1, ADC_CHANNEL_12}; | ||
ADCInput accel_pedal_pos_2{&hadc1, ADC_CHANNEL_13}; | ||
ADCInput brake_pedal_pos_1{&hadc1, ADC_CHANNEL_2}; | ||
ADCInput brake_pedal_pos_2{&hadc1, ADC_CHANNEL_1}; | ||
ADCInput suspension_travel_1{&hadc1, ADC_CHANNEL_8}; | ||
ADCInput suspension_travel_2{&hadc1, ADC_CHANNEL_9}; | ||
ADCInput hvil_feedback{&hadc1, ADC_CHANNEL_5}; | ||
ADCInput steering_angle{&hadc1, ADC_CHANNEL_4}; | ||
|
||
DigitalInput start_button_n{START_BUTTON_N_GPIO_Port, START_BUTTON_N_Pin}; | ||
DigitalInput wheel_speed_left_a{WHEEL_SPEED_LEFT_A_GPIO_Port, | ||
WHEEL_SPEED_LEFT_A_Pin}; | ||
DigitalInput wheel_speed_left_b{WHEEL_SPEED_LEFT_B_GPIO_Port, | ||
WHEEL_SPEED_LEFT_B_Pin}; | ||
DigitalInput wheel_speed_right_a{WHEEL_SPEED_RIGHT_A_GPIO_Port, | ||
WHEEL_SPEED_RIGHT_A_Pin}; | ||
DigitalInput wheel_speed_right_b{WHEEL_SPEED_RIGHT_A_GPIO_Port, | ||
WHEEL_SPEED_RIGHT_A_Pin}; | ||
|
||
DigitalOutput debug_led_en{DEBUG_LED_GPIO_Port, DEBUG_LED_Pin}; | ||
DigitalOutput dashboard_en{DASHBOARD_HSD_EN_GPIO_Port, DASHBOARD_HSD_EN_Pin}; | ||
DigitalOutput hvil_led_en{HVIL_LED_EN_GPIO_Port, HVIL_LED_EN_Pin}; | ||
DigitalOutput brake_light_en{BRAKE_LIGHT_EN_GPIO_Port, BRAKE_LIGHT_EN_Pin}; | ||
DigitalOutput status_led_en{STATUS_LED_EN_GPIO_Port, STATUS_LED_EN_Pin}; | ||
DigitalOutput rtds_en{RTDS_EN_GPIO_Port, RTDS_EN_Pin}; | ||
|
||
} // namespace mcal | ||
|
||
extern "C" { | ||
/** | ||
* This requires extern since it is not declared in a header, only defined | ||
* in cubemx/../main.c | ||
*/ | ||
void SystemClock_Config(); | ||
} | ||
|
||
namespace bindings { | ||
|
||
shared::periph::CanBase& veh_can_base = mcal::veh_can_base; | ||
|
||
shared::periph::ADCInput& accel_pedal_pos_1 = mcal::accel_pedal_pos_1; | ||
shared::periph::ADCInput& accel_pedal_pos_2 = mcal::accel_pedal_pos_2; | ||
shared::periph::ADCInput& brake_pedal_pos_1 = mcal::brake_pedal_pos_1; | ||
shared::periph::ADCInput& brake_pedal_pos_2 = mcal::brake_pedal_pos_2; | ||
shared::periph::ADCInput& suspension_travel_1 = mcal::suspension_travel_1; | ||
shared::periph::ADCInput& suspension_travel_2 = mcal::suspension_travel_2; | ||
shared::periph::ADCInput& hvil_feedback = mcal::hvil_feedback; | ||
shared::periph::ADCInput& steering_angle = mcal::steering_angle; | ||
|
||
shared::periph::DigitalInput& start_button_n = mcal::start_button_n; | ||
shared::periph::DigitalInput& wheel_speed_left_a = mcal::wheel_speed_left_a; | ||
shared::periph::DigitalInput& wheel_speed_left_b = mcal::wheel_speed_left_b; | ||
shared::periph::DigitalInput& wheel_speed_right_a = mcal::wheel_speed_right_a; | ||
shared::periph::DigitalInput& wheel_speed_right_b = mcal::wheel_speed_right_b; | ||
|
||
shared::periph::DigitalOutput& debug_led_en = mcal::debug_led_en; | ||
shared::periph::DigitalOutput& dashboard_en = mcal::dashboard_en; | ||
shared::periph::DigitalOutput& hvil_led_en = mcal::hvil_led_en; | ||
shared::periph::DigitalOutput& brake_light_en = mcal::brake_light_en; | ||
shared::periph::DigitalOutput& status_led_en = mcal::status_led_en; | ||
shared::periph::DigitalOutput& rtds_en = mcal::rtds_en; | ||
|
||
void Initialize() { | ||
SystemClock_Config(); | ||
HAL_Init(); | ||
|
||
MX_GPIO_Init(); | ||
MX_ADC1_Init(); | ||
MX_CAN1_Init(); | ||
MX_CAN3_Init(); | ||
mcal::veh_can_base.Setup(); | ||
} | ||
|
||
void TickBlocking(uint32_t ticks) { | ||
HAL_Delay(ticks); | ||
} | ||
|
||
extern "C" { | ||
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* hcan) { | ||
if (hcan == &hcan3) { | ||
mcal::veh_can_base.AddRxMessageToQueue(); | ||
} | ||
} | ||
} | ||
|
||
} // namespace bindings |
Oops, something went wrong.