Skip to content

Commit

Permalink
User/fangm/pedal reader (#178)
Browse files Browse the repository at this point in the history
* create folder structure

* Initial commit

* Read accel pedal positions

* CAN for pedal debugging

* Forgot return

* add cmake

* Adds readme & initialize functions

* Gets debug LED working for MotorDebug

---------

Co-authored-by: Max Fang <[email protected]>
Co-authored-by: Tyler St-Amour <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2024
1 parent 3e0d890 commit ff0b700
Show file tree
Hide file tree
Showing 15 changed files with 594 additions and 0 deletions.
14 changes: 14 additions & 0 deletions firmware/dbcs/pedal.dbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
VERSION ""

BS_:

BU_: FRONTCONTROLLER


BO_ 2364540158 APPS: 8 FRONTCONTROLLER
SG_ APPS1 : 0|16@1+ (1,0) [0|100] "percent" Vector__XXX
SG_ APPS2 : 16|16@1+ (1,0) [0|100] "percent" Vector__XXX


CM_ SG_ 2364540158 APPS1 "Accel Pedal 1";
CM_ SG_ 2364540158 APPS2 "Accel Pedal 2";
37 changes: 37 additions & 0 deletions firmware/projects/EV5/debug/MotorDebug/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Blake Freer
# Sept 6, 2024

# 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=\"EV5/debug/MotorDebug\""
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)

# 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.
7 changes: 7 additions & 0 deletions firmware/projects/EV5/debug/MotorDebug/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Motor Debug

_September 6, 2024 - Blake Freer, Max Fang, Tyler St-Amour_

Read both accelerator pedal values. Report the percentage over CAN.

Created to verify the orientation of the pedal position sensors.
20 changes: 20 additions & 0 deletions firmware/projects/EV5/debug/MotorDebug/bindings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <cstdint>

#include "shared/periph/adc.h"
#include "shared/periph/can.h"
#include "shared/periph/gpio.h"

namespace bindings {

extern shared::periph::ADCInput& accel_pedal_1;
extern shared::periph::ADCInput& accel_pedal_2;
extern shared::periph::CanBase& vehicle_can_base;
extern shared::periph::DigitalOutput& debug_led;

extern void Initialize();

extern void DelayMS(uint32_t ms);

} // namespace bindings
6 changes: 6 additions & 0 deletions firmware/projects/EV5/debug/MotorDebug/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
canGen:
ourNode: FRONTCONTROLLER
busses:
- busName: vehicle
dbcFiles:
- "pedal.dbc"
44 changes: 44 additions & 0 deletions firmware/projects/EV5/debug/MotorDebug/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdint.h>

#include "bindings.h"
#include "generated/can/vehicle_can_messages.h"
#include "generated/can/vehicle_msg_registry.h"
#include "projects/EV5/debug/MotorDebug/generated/can/vehicle_msg_registry.h"
#include "shared/comms/can/can_bus.h"
#include "shared/periph/can.h"

namespace bindings {

extern shared::periph::CanBase& vehicle_can_base;

} // namespace bindings

generated::can::VehicleMsgRegistry veh_can_registry{};
shared::can::CanBus vehicle_can_bus{
bindings::vehicle_can_base,
veh_can_registry,
};

generated::can::APPS pedal_message{};

bool debug_led_state = true;

int main() {
bindings::Initialize();

while (true) {
uint32_t accel_pedal_pos_1 = bindings::accel_pedal_1.Read();
uint32_t accel_pedal_pos_2 = bindings::accel_pedal_2.Read();

// // Send over CAN
pedal_message.apps1 = static_cast<uint16_t>(accel_pedal_pos_1);
pedal_message.apps2 = static_cast<uint16_t>(accel_pedal_pos_2);
vehicle_can_bus.Send(pedal_message);

bindings::DelayMS(100);
bindings::debug_led.Set(debug_led_state);
debug_led_state = !debug_led_state;
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target_sources(bindings PRIVATE bindings.cc)
target_include_directories(bindings PRIVATE ${DIR_PROJECT})

target_link_libraries(bindings PUBLIC mcal-cli)
40 changes: 40 additions & 0 deletions firmware/projects/EV5/debug/MotorDebug/platforms/cli/bindings.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <unistd.h>

#include "bindings.h"
#include "shared/periph/adc.h"
#include "shared/periph/can.h"
#include "shared/periph/gpio.h"

// fw imports
#include "mcal/cli/periph/adc.h"
#include "mcal/cli/periph/can.h"
#include "mcal/cli/periph/gpio.h"

namespace mcal {
using namespace cli::periph;

ADCInput accel_pedal_1{"apps1"};
ADCInput accel_pedal_2{"apps2"};

CanBase vehicle_can_base{"vehicle"};

DigitalOutput debug_led{"Debug LED"};
} // namespace mcal

namespace bindings {
shared::periph::ADCInput& accel_pedal_1 = mcal::accel_pedal_1;
shared::periph::ADCInput& accel_pedal_2 = mcal::accel_pedal_2;
shared::periph::CanBase& vehicle_can_base = mcal::vehicle_can_base;

shared::periph::DigitalOutput& debug_led = mcal::debug_led;

void Initialize() {
std::cout << "Initializing CLI..." << std::endl;
mcal::vehicle_can_base.Setup();
}

void DelayMS(uint32_t ms) {
usleep(ms * 1000);
}

} // namespace bindings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(MCAL cli)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target_sources(bindings PRIVATE bindings.cc)
target_include_directories(bindings PRIVATE ${DIR_PROJECT})

target_link_libraries(bindings PUBLIC mcal-stm32f767)

add_subdirectory(cubemx) # provides "driver"
target_link_libraries(bindings PUBLIC driver)
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <cstdint>

#include "adc.h"
#include "bindings.h"
#include "can.h"
#include "gpio.h"
#include "main.h"
#include "shared/periph/adc.h"
#include "shared/periph/can.h"
#include "shared/periph/gpio.h"
#include "stm32f7xx_hal.h"
#include "stm32f7xx_hal_adc.h"

// fw imports
#include "mcal/stm32f767/periph/adc.h"
#include "mcal/stm32f767/periph/can.h"
#include "mcal/stm32f767/periph/gpio.h"

extern "C" {
/**
* This requires extern since it is not declared in a header, only defined
* in cubemx/../main.c
*/
void SystemClock_Config();
}

namespace mcal {
using namespace stm32f767::periph;

ADCInput accel_pedal_1{
&hadc1,
ADC_CHANNEL_12,
};
ADCInput accel_pedal_2{
&hadc1,
ADC_CHANNEL_13,
};

CanBase vehicle_can_base{&hcan3};

DigitalOutput debug_led{
DEBUG_LED_GPIO_Port,
DEBUG_LED_Pin,
};
} // namespace mcal

namespace bindings {
shared::periph::ADCInput& accel_pedal_1 = mcal::accel_pedal_1;
shared::periph::ADCInput& accel_pedal_2 = mcal::accel_pedal_2;
shared::periph::CanBase& vehicle_can_base = mcal::vehicle_can_base;
shared::periph::DigitalOutput& debug_led = mcal::debug_led;

void Initialize() {
SystemClock_Config();
HAL_Init();

MX_ADC1_Init();
MX_GPIO_Init();
MX_CAN3_Init();

mcal::vehicle_can_base.Setup();
}

void DelayMS(uint32_t ms) {
HAL_Delay(ms);
}

} // namespace bindings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!*.ioc
!.gitignore
!CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include(${CMAKE_SOURCE_DIR}/cmake/build_cubemx.cmake)
Loading

0 comments on commit ff0b700

Please sign in to comment.