diff --git a/.github/workflows/build-check.yml b/.github/workflows/build-check.yml index 5ee76bbc..2390778a 100644 --- a/.github/workflows/build-check.yml +++ b/.github/workflows/build-check.yml @@ -3,18 +3,16 @@ on: [push] jobs: run-build: runs-on: ubuntu-latest - container: - image: ghcr.io/northeastern-electric-racing/embedded-base:main timeout-minutes: 10 steps: - name: Checkout code uses: actions/checkout@v4 with: submodules: recursive - + fetch-depth: 0 - name: Execute Make run: | - if ! make; then + if ! docker compose run --rm ner-gcc-arm make -j `nproc`; then echo "The application has failed to build." exit 1 # This will cause the workflow to fail - fi \ No newline at end of file + fi diff --git a/Core/Inc/dti.h b/Core/Inc/dti.h index 802448ca..091d26e7 100644 --- a/Core/Inc/dti.h +++ b/Core/Inc/dti.h @@ -27,7 +27,7 @@ 0x496 /* Throttle signal, Brake signal, IO, Drive enable */ #define TIRE_DIAMETER 16 /* inches */ -#define GEAR_RATIO 47 / 13.0 /* unitless */ +#define GEAR_RATIO 43 / 13.0 /* unitless */ #define POLE_PAIRS 10 /* unitless */ typedef struct { diff --git a/Core/Inc/emrax.h b/Core/Inc/emrax.h index 10df36c4..3957327c 100644 --- a/Core/Inc/emrax.h +++ b/Core/Inc/emrax.h @@ -18,7 +18,7 @@ #define EMRAX_NOMINAL_VOLTAGE 520 /* V */ #define EMRAX_PEAK_EFFICIENCY 90 /* % */ #define EMRAX_PEAK_POWER 124 /* kW, at 5500 RPM */ -#define EMRAX_PEAK_TORQUE 230 /* Nm */ +#define EMRAX_PEAK_TORQUE 220 /* Nm */ #define EMRAX_CONT_TORQUE 112 /* Nm */ #define EMRAX_LIMITING_SPEED 6500 /* RPM */ #define EMRAX_KV 15.53 diff --git a/Core/Src/main.c b/Core/Src/main.c index d7de1b4f..b61f6bba 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -39,6 +39,7 @@ #include "dti.h" #include "steeringio.h" #include "pedals.h" +#include "string.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -708,7 +709,35 @@ static void MX_GPIO_Init(void) } /* USER CODE BEGIN 4 */ - +struct __attribute__((__packed__)) git_version_data { + uint8_t git_major_version; + uint8_t git_minor_version; + uint8_t git_patch_version; + bool git_is_upstream_clean; + bool git_is_local_clean; + } git_version_data; + + struct __attribute__((__packed__)) git_hash_data { + uint32_t git_shorthash; + uint32_t git_authorhash; + } git_hash_data; + +/** + * @brief Sends git version infomation as a can message + */ +void send_git_version_message() { + const struct git_hash_data git_hash_data2 = {GIT_SHORTHASH , GIT_AUTHORHASH}; + const struct git_version_data git_version_data2 = {GIT_MAJOR_VERSION , GIT_MINOR_VERSION, GIT_PATCH_VERSION, GIT_IS_UPSTREAM_CLEAN, GIT_IS_LOCAL_CLEAN}; + can_msg_t msg1 = { .id = 0x698, .len = sizeof(git_version_data2)}; + can_msg_t msg2 = { .id = 0x699, .len = sizeof(git_hash_data2)}; + + memcpy(&msg1.data, &git_version_data2, sizeof(git_version_data2)); + memcpy(&msg2.data, &git_hash_data2, sizeof(git_hash_data2)); + + queue_can_msg(msg1); + //queue_can_msg(msg2); + +} /* USER CODE END 4 */ /* USER CODE BEGIN Header_StartDefaultTask */ @@ -739,6 +768,7 @@ void StartDefaultTask(void *argument) /* Send NERO state data continuously */ send_nero_msg(); + send_git_version_message(); osDelay(500); //osDelay(YELLOW_LED_BLINK_DELAY); } diff --git a/Core/Src/pedals.c b/Core/Src/pedals.c index 0dd1fd7a..5553143c 100644 --- a/Core/Src/pedals.c +++ b/Core/Src/pedals.c @@ -197,6 +197,7 @@ bool calc_bspd_prefault(float accel_val, float brake_val) return motor_disabled; } +#ifndef POWER_REGRESSION_PEDAL_TORQUE_TRANSFER static void linear_accel_to_torque(float accel) { /* Sometimes, the pedal travel jumps to 1% even if it is not pressed. */ @@ -209,6 +210,22 @@ static void linear_accel_to_torque(float accel) dti_set_torque(torque); } +#else +static void power_regression_accel_to_torque(float accel) +{ + /* Sometimes, the pedal travel jumps to 1% even if it is not pressed. */ + if (fabs(accel - 0.01) < 0.001) { + accel = 0; + } + /* map acceleration to torque */ + int16_t torque = + (int16_t)(0.137609 * powf(accel, 1.43068) * MAX_TORQUE); + /* These values came from creating a power regression function intersecting three points: (0,0) (20,10) & (100,100)*/ + + dti_set_torque(torque); +} +#endif + /** * @brief Derate torque target to keep car below the maximum pit/reverse mode speed. * @@ -440,7 +457,11 @@ void vProcessPedals(void *pv_params) handle_endurance(mc, mph, accelerator_value, brake_val); break; case F_PERFORMANCE: +#ifndef POWER_REGRESSION_PEDAL_TORQUE_TRANSFER linear_accel_to_torque(accelerator_value); +#else + power_regression_accel_to_torque(accelerator_value); +#endif break; case F_PIT: handle_pit(mph, accelerator_value); diff --git a/Makefile b/Makefile index e28cb1b8..f6dcdce7 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,34 @@ $(info \ \___\ ___/| | \/ \_\ \ ___/| | \/ | /\___ \ ) $(info .\______ /\___ >__| |___ /\___ >__| |____//____ >) $(info ........\/ \/ \/ \/ \/ ) + +###################################### +# git +###################################### +GIT_MAJOR_VERSION := $(shell git describe --tags --abbrev=0 | cut -c2- | cut -d'.' -f1) +GIT_MINOR_VERSION := $(shell git describe --tags --abbrev=0 | cut -c2- | cut -d'.' -f2) +GIT_PATCH_VERSION := $(shell git describe --tags --abbrev=0 | cut -c2- | cut -d'.' -f3) +GIT_IS_UPSTREAM_CLEAN := $(shell bash -c 'git merge-base --is-ancestor HEAD @{u} && echo 0 || echo 1') +GIT_IS_LOCAL_CLEAN := $(shell bash -c 'test -z "$$(git status --porcelain)" && echo 0 || echo 1') +GIT_SHORTHASH := $(shell git rev-parse --short=8 HEAD) +GIT_AUTHORHASH := $(shell bash -c 'git log -n 1 --format=%h --author=$(git config --get user.name)') + + +all: + @echo "VERSION: $(GIT_MAJOR_VERSION).$(GIT_MINOR_VERSION).$(GIT_PATCH_VERSION)" + @echo "UNPUSHED CHANGES: $(GIT_IS_UPSTREAM_CLEAN)" + @echo "UNCOMMITTED CHANGES: $(GIT_IS_LOCAL_CLEAN)" + @echo "COMMIT HASH: $(GIT_SHORTHASH)" + @echo "AUTHOR HASH: $(GIT_AUTHORHASH)" + +CFLAGS += -DGIT_MAJOR_VERSION=$(GIT_MAJOR_VERSION) \ + -DGIT_MINOR_VERSION=$(GIT_MINOR_VERSION) \ + -DGIT_PATCH_VERSION=$(GIT_PATCH_VERSION) \ + -DGIT_IS_UPSTREAM_CLEAN=$(GIT_IS_UPSTREAM_CLEAN) \ + -DGIT_IS_LOCAL_CLEAN=$(GIT_IS_LOCAL_CLEAN) \ + -DGIT_SHORTHASH=0x$(GIT_SHORTHASH) \ + -DGIT_AUTHORHASH=0x$(GIT_AUTHORHASH) + ###################################### # building variables ######################################