Skip to content

Commit

Permalink
merged develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Myers-Ty committed Jan 19, 2025
2 parents 68208e5 + 2ffb5f3 commit 89269e6
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
fi
2 changes: 1 addition & 1 deletion Core/Inc/dti.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/emrax.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "dti.h"
#include "steeringio.h"
#include "pedals.h"
#include "string.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
Expand Down
21 changes: 21 additions & 0 deletions Core/Src/pedals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
######################################
Expand Down

0 comments on commit 89269e6

Please sign in to comment.