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

Update main.c #361

Merged
merged 35 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2e8460c
Remove contactor handling and extraneous delays from main
Cam0Cow Sep 30, 2023
b6fd25e
Create CommandLine task in main.c
Cam0Cow Sep 30, 2023
183ab34
Merge branch 'master' into check_main
Cam0Cow Oct 27, 2023
ca360f5
Merge branch 'master' into check_main
Cam0Cow Nov 4, 2023
92ac207
changed ordering of task prios
IshDeshpa Nov 10, 2023
097caf3
Merge branch 'master' into check_main
IshDeshpa Nov 10, 2023
31e2d81
Merge branch 'master' into check_main
IshDeshpa Nov 25, 2023
e8c22a1
Actually switch to hard floats, remove duplicated flags
Cam0Cow Nov 25, 2023
fa89f23
disabled regen
IshDeshpa Nov 25, 2023
8b5a3db
Squashed commit of the following:
IshDeshpa Nov 25, 2023
7b16d4d
test commit
IshDeshpa Dec 2, 2023
5cb19e2
Changes from integration with BPS: uncommented initialization of Task…
KnockbackNemo Dec 3, 2023
8615137
test commit
IshDeshpa Dec 9, 2023
d3a4e90
Squashed commit of the following:
IshDeshpa Dec 13, 2023
8c3c16a
mostly working
IshDeshpa Dec 13, 2023
84a04c0
ReadTritium fixes
IshDeshpa Dec 13, 2023
e0c40ec
Squashed commit of the following:
IshDeshpa Dec 17, 2023
8d7e935
removed duplicates
IshDeshpa Dec 17, 2023
b5adbeb
Merge remote-tracking branch 'origin/master' into check_main
IshDeshpa Dec 17, 2023
c7808fa
fixed merge issue in SendTritium.c (closes #381)
IshDeshpa Dec 17, 2023
47d011f
moved macros from ReadCarCAN.c to ReadCarCAN.h so they are visible in…
IshDeshpa Dec 19, 2023
dd36bc4
fixed header comment so doxygen recognizes it
IshDeshpa Dec 19, 2023
929f242
changed lang to en
IshDeshpa Dec 19, 2023
a9a9b4e
created helper script for printing all sphinx references
IshDeshpa Dec 19, 2023
6c10365
updated readtritium docs
IshDeshpa Dec 19, 2023
96aab88
updated Minions.rst
IshDeshpa Dec 19, 2023
bf453fa
Revert mistakenly pushed docs commits.
IshDeshpa Dec 19, 2023
9c2e234
Removed redundant code
NathanielDelgado Dec 27, 2023
ea33372
Merge branch 'master' into check_main
IshDeshpa Dec 29, 2023
2bf5ea5
Apply suggestions from code review
IshDeshpa Jan 1, 2024
8a65d35
Merge branch 'master' into check_main
IshDeshpa Jan 1, 2024
c6c4cf1
Feature/GitHub workflow fix (#396)
IshDeshpa Jan 1, 2024
3f20813
addressed more review comments
IshDeshpa Jan 1, 2024
5b7314b
Apply suggestions from code review
IshDeshpa Jan 2, 2024
0b55f39
Apply suggestions from code review
IshDeshpa Jan 2, 2024
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
10 changes: 5 additions & 5 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Initialize Submodules
run: git submodule update --init --recursive
- name: Install tools
run: |
./Embedded-Sharepoint/Scripts/install.sh -i
sudo apt -y update
sudo apt -y install gcc-arm-none-eabi
- name: Initialize Submodules
run: git submodule update --init --recursive
- name: clean
run: make clean
- name: make stm32f413
run: make stm32f413
- name: make leader
run: make leader
6 changes: 3 additions & 3 deletions Apps/Inc/SendTritium.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

#include "common.h"

#define SENDTRITIUM_PRINT_MES
//#define SENDTRITIUM_PRINT_MES
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved

#define MOTOR_MSG_PERIOD 100
#define FSM_PERIOD 100
#define MOTOR_MSG_PERIOD 100 // in ms
#define FSM_PERIOD 100 // in ms
#define DEBOUNCE_PERIOD 2 // in units of FSM_PERIOD
#define MOTOR_MSG_COUNTER_THRESHOLD (MOTOR_MSG_PERIOD)/(FSM_PERIOD)

Expand Down
9 changes: 5 additions & 4 deletions Apps/Inc/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
#define TASK_READ_TRITIUM_PRIO 3
#define TASK_SEND_TRITIUM_PRIO 4
#define TASK_READ_CAR_CAN_PRIO 5
#define TASK_UPDATE_DISPLAY_PRIO 6
#define TASK_SEND_CAR_CAN_PRIO 7
#define TASK_DEBUG_DUMP_PRIO 8
#define TASK_COMMAND_LINE_PRIO 9
#define TASK_SEND_CAR_CAN_PRIO 6
#define TASK_PUT_IOSTATE_PRIO 7
#define TASK_UPDATE_DISPLAY_PRIO 8
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved
#define TASK_DEBUG_DUMP_PRIO 9
#define TASK_COMMAND_LINE_PRIO 10

/**
* Stack Sizes
Expand Down
6 changes: 3 additions & 3 deletions Apps/Src/ReadCarCAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ static void updateHVPlusMinusSaturation(int8_t messageState){
*/
void attemptTurnMotorControllerPBCOn(void){
if(mcPBCComplete){
Contactors_Set(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR, ON, true);
UpdateDisplay_SetMotor(true);
}
Contactors_Set(MOTOR_CONTROLLER_PRECHARGE_BYPASS_CONTACTOR, ON, true);
UpdateDisplay_SetMotor(true);
}
}

/**
Expand Down
40 changes: 11 additions & 29 deletions Apps/Src/ReadTritium.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,26 @@ static void motorWatchdog(void *tmr, void *p_arg) {
}


/* OBJECTIVES:
Objective 1:
- Receive motor status message from MotorController (18.4.2)
- interpret error status
- if error
- assertOSError
- determine information important to telementry
- Telemetry
- determine information important for storage
- acquire mutex on Storage Array
- Store information in Storage Array (based on index)
- release mutex on Storage Array

Objective 2:
- create function able to read data from Storage Array
- pend on Storage Array mutex
- acquire Storage Array mutex
- read information of array index
- release Storage Array mutex
*/

void Task_ReadTritium(void *p_arg){
OS_ERR err;
CANDATA_t dataBuf = {0};

// Timer doesn't seem to trigger without initial delay? Might be an RTOS bug
OSTmrCreate(&MotorWatchdog, "Motor watchdog", MOTOR_TIMEOUT_TICKS, MOTOR_TIMEOUT_TICKS, OS_OPT_TMR_PERIODIC, motorWatchdog, NULL, &err);
assertOSError(err);
OSTmrStart(&MotorWatchdog, &err);
assertOSError(err);
static bool watchdogCreated = false;

while (1){
ErrorStatus status = CANbus_Read(&dataBuf, true, MOTORCAN);

if (status == SUCCESS){
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved
if(!watchdogCreated){ // Timer doesn't seem to trigger without initial delay? Might be an RTOS bug
OSTmrCreate(&MotorWatchdog, "Motor watchdog", MOTOR_TIMEOUT_TICKS, MOTOR_TIMEOUT_TICKS, OS_OPT_TMR_PERIODIC, motorWatchdog, NULL, &err);
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved
assertOSError(err);

OSTmrStart(&MotorWatchdog, &err);
assertOSError(err);

watchdogCreated = true;
}

switch(dataBuf.ID){
case MOTOR_STATUS:{
// motor status error flags is in bytes 4-5
Expand Down Expand Up @@ -107,9 +92,6 @@ void Task_ReadTritium(void *p_arg){

SendCarCAN_Put(dataBuf); // Forward message on CarCAN for telemetry
}

OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_HMSM_NON_STRICT, &err);
assertOSError(err);
}
}

Expand Down
37 changes: 22 additions & 15 deletions Apps/Src/SendCarCAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

#define IO_STATE_DLY_MS 250u

#define SENDCARCAN_MSG_SKIP_CTR 3

// Task_PutIOState
OS_TCB putIOState_TCB;
CPU_STK putIOState_Stk[TASK_SEND_CAR_CAN_STACK_SIZE];

//fifo
#define FIFO_TYPE CANDATA_t
#define FIFO_SIZE 16
#define FIFO_SIZE 50
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved
#define FIFO_NAME SendCarCAN_Q
#include "fifo.h"

Expand All @@ -48,19 +50,27 @@ uint8_t get_SendCarCAN_Q_Space(void) {

/**
* @brief Wrapper to put new message in the CAN queue
* @param message the CAN message to put in SendCarCAN Queue
*/
void SendCarCAN_Put(CANDATA_t message){
OS_ERR err;
OS_ERR err = OS_ERR_NONE;
IshDeshpa marked this conversation as resolved.
Show resolved Hide resolved
CPU_TS ticks;

OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err);
assertOSError(err);
bool success = false;

static uint8_t carcan_ctr = 0;

bool success = SendCarCAN_Q_put(&CANFifo, message);
if(carcan_ctr > SENDCARCAN_MSG_SKIP_CTR){
OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err);
assertOSError(err);

success = SendCarCAN_Q_put(&CANFifo, message);

OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err);
assertOSError(err);

carcan_ctr = 0;
}
carcan_ctr++;

OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err);
assertOSError(err);

if(success) OSSemPost(&CarCAN_Sem4, OS_OPT_POST_1, &err);
assertOSError(err);
IshDeshpa marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -97,7 +107,7 @@ void Task_SendCarCAN(void *p_arg){
(CPU_CHAR*)"PutIOState",
(OS_TASK_PTR)Task_PutIOState,
(void*)NULL,
(OS_PRIO)TASK_SEND_CAR_CAN_PRIO, // Round-robin with SendCarCAN task
(OS_PRIO)TASK_PUT_IOSTATE_PRIO,
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved
(CPU_STK*)putIOState_Stk,
(CPU_STK_SIZE)WATERMARK_STACK_LIMIT,
(CPU_STK_SIZE)TASK_SEND_CAR_CAN_STACK_SIZE,
Expand All @@ -119,13 +129,11 @@ void Task_SendCarCAN(void *p_arg){
assertOSError(err);

bool res = SendCarCAN_Q_get(&CANFifo, &message);
assertOSError(err);

OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err);
assertOSError(err);

if(res) CANbus_Send(message, true, CARCAN);

}
}

Expand All @@ -141,7 +149,6 @@ static void putIOState(void){
// Get minion information
for(pin_t pin = 0; pin < NUM_PINS; pin++){
bool pinState = Minions_Read(pin);
if(pin == IGN_1 || pin == IGN_2) pinState = !pinState;
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved
message.data[2] |= pinState << pin;
}

Expand All @@ -150,6 +157,7 @@ static void putIOState(void){
bool contactorState = (Contactors_Get(contactor) == ON) ? true : false;
message.data[3] |= contactorState << contactor;
}

// Tell BPS if the array contactor should be on
message.data[3] |= (!Minions_Read(IGN_1) || !Minions_Read(IGN_2)) << 2;

Expand All @@ -164,6 +172,5 @@ static void Task_PutIOState(void *p_arg) {
while (1) {
putIOState();
OSTimeDlyHMSM(0, 0, 0, IO_STATE_DLY_MS, OS_OPT_TIME_HMSM_STRICT, &err);
IshDeshpa marked this conversation as resolved.
Show resolved Hide resolved
}

}
}
9 changes: 5 additions & 4 deletions Apps/Src/SendTritium.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#define MIN_CRUISE_VELOCITY mpsToRpm(20.0f) // rpm
#define MAX_GEARSWITCH_VELOCITY mpsToRpm(8.0f) // rpm

#define BRAKE_PEDAL_THRESHOLD 15 // percent
#define BRAKE_PEDAL_THRESHOLD 50 // percent
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved
#define ACCEL_PEDAL_THRESHOLD 10 // percent

#define ONEPEDAL_BRAKE_THRESHOLD 25 // percent
Expand Down Expand Up @@ -62,13 +62,10 @@ float velocitySetpoint = 0;
float cruiseVelSetpoint = 0;

// Current observed velocity

KnockbackNemo marked this conversation as resolved.
Show resolved Hide resolved
#ifndef SENDTRITIUM_EXPOSE_VARS
static float velocityObserved = 0;

// Counter for sending setpoints to motor
static uint8_t motorMsgCounter = 0;
#endif

// Debouncing counters
static uint8_t onePedalCounter = 0;
Expand Down Expand Up @@ -668,6 +665,10 @@ void Task_SendTritium(void *p_arg){
#endif
state.stateDecider(); // decide what the next state is

// Disable velocity controlled mode by always overwriting velocity to the maximum
// in the appropriate direction.
velocitySetpoint = (velocitySetpoint>0)?MAX_VELOCITY:-MAX_VELOCITY;
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved
IshDeshpa marked this conversation as resolved.
Show resolved Hide resolved

// Drive
#ifdef SENDTRITIUM_PRINT_MES
dumpInfo();
Expand Down
18 changes: 9 additions & 9 deletions Apps/Src/Tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ void throwTaskError(error_code_t errorCode, callback_t errorCallback, error_sche

#if DEBUG == 1
// Print the error that caused this fault
printf("\n\rCurrent Error Code: 0x%04x\n\r", errorCode);
// printf("\n\rCurrent Error Code: 0x%04x\n\r", errorCode);
NathanielDelgado marked this conversation as resolved.
Show resolved Hide resolved

// Print the errors for each applications with error data
printf("\n\rAll application errors:\n\r");
printf("Error_ReadCarCAN: 0x%04x\n\r", Error_ReadCarCAN);
printf("Error_ReadTritium: 0x%04x\n\r", Error_ReadTritium);
printf("Error_UpdateDisplay: 0x%04x\n\r", Error_UpdateDisplay);
// // Print the errors for each applications with error data
// printf("\n\rAll application errors:\n\r");
// printf("Error_ReadCarCAN: 0x%04x\n\r", Error_ReadCarCAN);
// printf("Error_ReadTritium: 0x%04x\n\r", Error_ReadTritium);
// printf("Error_UpdateDisplay: 0x%04x\n\r", Error_UpdateDisplay);

// Delay so that we're not constantly printing
for (int i = 0; i < 9999999; i++) {
}
// // Delay so that we're not constantly printing
// for (int i = 0; i < 9999999; i++) {
// }
#endif

}
Expand Down
Loading
Loading