Skip to content

Commit

Permalink
Update main.c (#361)
Browse files Browse the repository at this point in the history
* Remove contactor handling and extraneous delays from main

* Create CommandLine task in main.c

* changed ordering of task prios

* Actually switch to hard floats, remove duplicated flags

* disabled regen

* Squashed commit of the following:

commit f72917b
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 15:55:26 2023 +0000

    Fixed accidental deletion in docs.

commit 2755a69
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 15:50:32 2023 +0000

    Memset the gTxMessage.Data to zero since one-byte messages weren't clearing out old data in the rest of the bytes, updated comments in the test file.

commit 5d3ddfb
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 14:50:01 2023 +0000

    Added commas to enum to match new enum generation format.

commit 347ef98
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 14:27:58 2023 +0000

    Updated NUM_CAN_IDS to MAX_CAN_ID in the CANId enum.

commit 03f262c
Merge: 362628e e6c9fb6
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 10:31:31 2023 +0000

    Merge branch 'master' into sendcarcan-telemetry-merge

commit 362628e
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 10:24:37 2023 +0000

    Revisions to SendCarCAN and test file to allow messages to be inspected in GDB using variables instead of prints which were overwhelming UART.

commit 8bdf6bb
Author: Madeleine Lee <[email protected]>
Date:   Mon Nov 13 23:04:14 2023 +0000

    Addressing review comments: updated SendTritium macros, removed motorMsgCount queue, downsized SendCarCAN FIFO.

commit 0079ce4
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 17:57:19 2023 +0000

    Test file changes for last minute panic debugging. Added an array to see what IDS are being received.

commit de12ac1
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 17:32:41 2023 +0000

    Added while loop to putIOState

commit ff4bf0a
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 08:16:23 2023 +0000

    Updates from hardware testing: added counter array to reduce frequency at which we forwared motor messages onto CarCAN, moved init functions in test file, added Renode independent watchdog fix.

commit 77dbc2a
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 03:22:40 2023 +0000

    Changed PutIOState to send directly instead of putting messages in the queue to be sent by SendCarCAN later.

commit ce1d74a
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 03:20:33 2023 +0000

    Moved mutex, semaphore creation and fifo renewal to a new SendCarCAN_Init function so that other tasks can put things into the queue before SendCarCAN is ready. Additionally, created a new static task in SendCarCAN.c called PutIOState which periodically sends messages over CarCAN.

commit 9043b7b
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 10 23:57:18 2023 +0000

    Deleted extra lines added when merging.

commit a5e63df
Merge: d303e9b 5ae3439
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 10 23:41:44 2023 +0000

    Merge branch 'master' into sendcarcan-telemetry-merge

commit d303e9b
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 10 23:07:18 2023 +0000

    Test file updates from testing on hardware.

commit 9c755ba
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 4 21:08:49 2023 +0000

    Added ability to print FIFO queue indexes, added ReadTritium task in SendCarCAN test, fixed CAN initialization to read CarCAN but also initialize MOTORCAN.

commit 489a494
Author: Madeleine Lee <[email protected]>
Date:   Fri Oct 27 14:44:45 2023 +0000

    Cleaned up and worked on test file, removed attempt to put fifo in header file and added a wrapper instead. Test compiles but hasn't been verified to work successfully yet.

commit c38a3d7
Author: Madeleine Lee <[email protected]>
Date:   Sat Oct 21 04:57:18 2023 +0000

    SendCarCAN test file compiles! But at what cost...

commit ad84abf
Author: Madeleine Lee <[email protected]>
Date:   Sat Oct 21 04:47:33 2023 +0000

    Made aa first draft of the SendCarCAN test file and attempted to get at the SendCarCAN file by exposing it with a macro mess. controls-leader code compiles, but the test file does not compile yet.

commit 3d1d906
Author: Madeleine Lee <[email protected]>
Date:   Fri Oct 20 21:06:52 2023 +0000

    Altered test macros so that we can define __TEST_SENDTRITIUM and print info while running tests on hardware or also define __TEST_SENDTRITIUM_SOFTWAREONLY to bypass hardware inputs/outputs.

commit 73dddf7
Author: Madeleine Lee <[email protected]>
Date:   Fri Oct 20 03:02:13 2023 +0000

    Added line to put messages from the motor into the CarCAN queue to be sent.

commit 90cb9c6
Author: Madeleine Lee <[email protected]>
Date:   Fri Oct 20 02:50:50 2023 +0000

    Deleted most putIOStateTimer thigns, added a macro and counter in the sendCarCAN loop to send the IO message at approximately the same frequency as before (250 ms), but this time using loops, delays, and counters. It won't be as accurate, but it should still be at a relatively similar frequency.

commit 5185426
Author: Madeleine Lee <[email protected]>
Date:   Sat Oct 14 20:29:23 2023 +0000

    Changed main loop to check the queue periodically instead of pending on a semaphore. The loop will check two semaphores- one to see if it's time to put an IO State message in the queue (based on if the putIOState timer has expired or not) and one to see if there's a message in the queuethat we should send.

commit 2d7dbbf
Author: Madeleine Lee <[email protected]>
Date:   Sat Oct 7 23:21:43 2023 +0000

    Started a test file for SendCarCAN.

commit 2f45100
Merge: 6f69ba9 fd33899
Author: ishdeshpa <[email protected]>
Date:   Tue Sep 26 00:09:02 2023 +0000

    merged in master, now builds. test still needs to be written and bugfixes made. also ignition switch message needs to be added.

commit 6f69ba9
Author: ishdeshpa <[email protected]>
Date:   Mon Sep 25 23:50:29 2023 +0000

    merge conflict resolved

commit de426c5
Author: ishdeshpa <[email protected]>
Date:   Mon Jul 10 19:36:13 2023 +0000

    adapted CAN_Queue into a library file and integrated with SendCarCAN

commit cfd0b7c
Author: ishdeshpa <[email protected]>
Date:   Sun Jul 9 22:16:56 2023 +0000

    renamed telemetry to send car can

commit 771a916
Author: Nathaniel Delgado <[email protected]>
Date:   Sat Jul 8 03:13:27 2023 +0000

    Merged functionality of SendCarCAN into Telemetry and removed SendCarCAN remnants

* test commit

* Changes from integration with BPS: uncommented initialization of Task_ReadCarCAN, changed BPS_CONTACTOR CAN message ID to 0x102 instead of x101 (which is for BPS All Clear)

* test commit

* Squashed commit of the following:

commit 6cf7996
Author: Madeleine Lee <[email protected]>
Date:   Sun Dec 3 05:59:52 2023 +0000

    Changes from integration with BPS: flipped reading of ignition pins in PutIOState to account for the inverted logic, added a new bit of information to PutIOState in byte 3, bit 2 which tells BPS if the array contactor should be turned on or not (true if IGN_1 or IGN_2 are on). This is necessary because  when the ignition is switched to motor state, the array pin is turned off (only one or the other is on at a time). Note: in the future we'd like to use the GPIO read settings to account for the inverted ignition logic so we don't have to negate every Minions_Read.

commit f72917b
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 15:55:26 2023 +0000

    Fixed accidental deletion in docs.

commit 2755a69
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 15:50:32 2023 +0000

    Memset the gTxMessage.Data to zero since one-byte messages weren't clearing out old data in the rest of the bytes, updated comments in the test file.

commit 5d3ddfb
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 14:50:01 2023 +0000

    Added commas to enum to match new enum generation format.

commit 347ef98
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 14:27:58 2023 +0000

    Updated NUM_CAN_IDS to MAX_CAN_ID in the CANId enum.

commit 03f262c
Merge: 362628e e6c9fb6
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 10:31:31 2023 +0000

    Merge branch 'master' into sendcarcan-telemetry-merge

commit 362628e
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 17 10:24:37 2023 +0000

    Revisions to SendCarCAN and test file to allow messages to be inspected in GDB using variables instead of prints which were overwhelming UART.

commit 8bdf6bb
Author: Madeleine Lee <[email protected]>
Date:   Mon Nov 13 23:04:14 2023 +0000

    Addressing review comments: updated SendTritium macros, removed motorMsgCount queue, downsized SendCarCAN FIFO.

commit 0079ce4
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 17:57:19 2023 +0000

    Test file changes for last minute panic debugging. Added an array to see what IDS are being received.

commit de12ac1
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 17:32:41 2023 +0000

    Added while loop to putIOState

commit ff4bf0a
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 08:16:23 2023 +0000

    Updates from hardware testing: added counter array to reduce frequency at which we forwared motor messages onto CarCAN, moved init functions in test file, added Renode independent watchdog fix.

commit 77dbc2a
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 03:22:40 2023 +0000

    Changed PutIOState to send directly instead of putting messages in the queue to be sent by SendCarCAN later.

commit ce1d74a
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 11 03:20:33 2023 +0000

    Moved mutex, semaphore creation and fifo renewal to a new SendCarCAN_Init function so that other tasks can put things into the queue before SendCarCAN is ready. Additionally, created a new static task in SendCarCAN.c called PutIOState which periodically sends messages over CarCAN.

commit 9043b7b
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 10 23:57:18 2023 +0000

    Deleted extra lines added when merging.

commit a5e63df
Merge: d303e9b 5ae3439
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 10 23:41:44 2023 +0000

    Merge branch 'master' into sendcarcan-telemetry-merge

commit d303e9b
Author: Madeleine Lee <[email protected]>
Date:   Fri Nov 10 23:07:18 2023 +0000

    Test file updates from testing on hardware.

commit 9c755ba
Author: Madeleine Lee <[email protected]>
Date:   Sat Nov 4 21:08:49 2023 +0000

    Added ability to print FIFO queue indexes, added ReadTritium task in SendCarCAN test, fixed CAN initialization to read CarCAN but also initialize MOTORCAN.

commit 489a494
Author: Madeleine Lee <[email protected]>
Date:   Fri Oct 27 14:44:45 2023 +0000

    Cleaned up and worked on test file, removed attempt to put fifo in header file and added a wrapper instead. Test compiles but hasn't been verified to work successfully yet.

commit c38a3d7
Author: Madeleine Lee <[email protected]>
Date:   Sat Oct 21 04:57:18 2023 +0000

    SendCarCAN test file compiles! But at what cost...

commit ad84abf
Author: Madeleine Lee <[email protected]>
Date:   Sat Oct 21 04:47:33 2023 +0000

    Made aa first draft of the SendCarCAN test file and attempted to get at the SendCarCAN file by exposing it with a macro mess. controls-leader code compiles, but the test file does not compile yet.

commit 3d1d906
Author: Madeleine Lee <[email protected]>
Date:   Fri Oct 20 21:06:52 2023 +0000

    Altered test macros so that we can define __TEST_SENDTRITIUM and print info while running tests on hardware or also define __TEST_SENDTRITIUM_SOFTWAREONLY to bypass hardware inputs/outputs.

commit 73dddf7
Author: Madeleine Lee <[email protected]>
Date:   Fri Oct 20 03:02:13 2023 +0000

    Added line to put messages from the motor into the CarCAN queue to be sent.

commit 90cb9c6
Author: Madeleine Lee <[email protected]>
Date:   Fri Oct 20 02:50:50 2023 +0000

    Deleted most putIOStateTimer thigns, added a macro and counter in the sendCarCAN loop to send the IO message at approximately the same frequency as before (250 ms), but this time using loops, delays, and counters. It won't be as accurate, but it should still be at a relatively similar frequency.

commit 5185426
Author: Madeleine Lee <[email protected]>
Date:   Sat Oct 14 20:29:23 2023 +0000

    Changed main loop to check the queue periodically instead of pending on a semaphore. The loop will check two semaphores- one to see if it's time to put an IO State message in the queue (based on if the putIOState timer has expired or not) and one to see if there's a message in the queuethat we should send.

commit 2d7dbbf
Author: Madeleine Lee <[email protected]>
Date:   Sat Oct 7 23:21:43 2023 +0000

    Started a test file for SendCarCAN.

commit 2f45100
Merge: 6f69ba9 fd33899
Author: ishdeshpa <[email protected]>
Date:   Tue Sep 26 00:09:02 2023 +0000

    merged in master, now builds. test still needs to be written and bugfixes made. also ignition switch message needs to be added.

commit 6f69ba9
Author: ishdeshpa <[email protected]>
Date:   Mon Sep 25 23:50:29 2023 +0000

    merge conflict resolved

commit de426c5
Author: ishdeshpa <[email protected]>
Date:   Mon Jul 10 19:36:13 2023 +0000

    adapted CAN_Queue into a library file and integrated with SendCarCAN

commit cfd0b7c
Author: ishdeshpa <[email protected]>
Date:   Sun Jul 9 22:16:56 2023 +0000

    renamed telemetry to send car can

commit 771a916
Author: Nathaniel Delgado <[email protected]>
Date:   Sat Jul 8 03:13:27 2023 +0000

    Merged functionality of SendCarCAN into Telemetry and removed SendCarCAN remnants

* mostly working

* ReadTritium fixes

* Squashed commit of the following:

commit 66958b8
Author: Nathaniel Delgado <[email protected]>
Date:   Sat Dec 16 18:29:35 2023 -0600

    SendCarCAN Restructure (#337)

    * Merged functionality of SendCarCAN into Telemetry and removed SendCarCAN remnants

    * renamed telemetry to send car can

    * adapted CAN_Queue into a library file and integrated with SendCarCAN

    * merge conflict resolved

    * Started a test file for SendCarCAN.

    * Changed main loop to check the queue periodically instead of pending on a semaphore. The loop will check two semaphores- one to see if it's time to put an IO State message in the queue (based on if the putIOState timer has expired or not) and one to see if there's a message in the queuethat we should send.

    * Deleted most putIOStateTimer thigns, added a macro and counter in the sendCarCAN loop to send the IO message at approximately the same frequency as before (250 ms), but this time using loops, delays, and counters. It won't be as accurate, but it should still be at a relatively similar frequency.

    * Added line to put messages from the motor into the CarCAN queue to be sent.

    * Altered test macros so that we can define __TEST_SENDTRITIUM and print info while running tests on hardware or also define __TEST_SENDTRITIUM_SOFTWAREONLY to bypass hardware inputs/outputs.

    * Made aa first draft of the SendCarCAN test file and attempted to get at the SendCarCAN file by exposing it with a macro mess. controls-leader code compiles, but the test file does not compile yet.

    * SendCarCAN test file compiles! But at what cost...

    * Cleaned up and worked on test file, removed attempt to put fifo in header file and added a wrapper instead. Test compiles but hasn't been verified to work successfully yet.

    * Added ability to print FIFO queue indexes, added ReadTritium task in SendCarCAN test, fixed CAN initialization to read CarCAN but also initialize MOTORCAN.

    * Test file updates from testing on hardware.

    * Deleted extra lines added when merging.

    * Moved mutex, semaphore creation and fifo renewal to a new SendCarCAN_Init function so that other tasks can put things into the queue before SendCarCAN is ready. Additionally, created a new static task in SendCarCAN.c called PutIOState which periodically sends messages over CarCAN.

    * Changed PutIOState to send directly instead of putting messages in the queue to be sent by SendCarCAN later.

    * Updates from hardware testing: added counter array to reduce frequency at which we forwared motor messages onto CarCAN, moved init functions in test file, added Renode independent watchdog fix.

    * Added while loop to putIOState

    * Test file changes for last minute panic debugging. Added an array to see what IDS are being received.

    * Addressing review comments: updated SendTritium macros, removed motorMsgCount queue, downsized SendCarCAN FIFO.

    * Revisions to SendCarCAN and test file to allow messages to be inspected in GDB using variables instead of prints which were overwhelming UART.

    * Updated NUM_CAN_IDS to MAX_CAN_ID in the CANId enum.

    * Added commas to enum to match new enum generation format.

    * Memset the gTxMessage.Data to zero since one-byte messages weren't clearing out old data in the rest of the bytes, updated comments in the test file.

    * Fixed accidental deletion in docs.

    * Changes from integration with BPS: flipped reading of ignition pins in PutIOState to account for the inverted logic, added a new bit of information to PutIOState in byte 3, bit 2 which tells BPS if the array contactor should be turned on or not (true if IGN_1 or IGN_2 are on). This is necessary because  when the ignition is switched to motor state, the array pin is turned off (only one or the other is on at a time). Note: in the future we'd like to use the GPIO read settings to account for the inverted ignition logic so we don't have to negate every Minions_Read.

    * Addressed review comments: Shifted task priorities to be next to each other, added to the comment for SendCarCAN_Put.

    * addressed review comments

    ---------

    Co-authored-by: ishdeshpa <[email protected]>
    Co-authored-by: Madeleine Lee <[email protected]>

commit 5c13022
Author: Nathaniel Delgado <[email protected]>
Date:   Wed Dec 13 14:59:37 2023 -0600

    Added bps can sim for integration simulation

* removed duplicates

* fixed merge issue in SendTritium.c (closes #381)

* moved macros from ReadCarCAN.c to ReadCarCAN.h so they are visible in docs

* fixed header comment so doxygen recognizes it

* changed lang to en

* created helper script for printing all sphinx references

* updated readtritium docs

* updated Minions.rst

* Revert mistakenly pushed docs commits.

Revert "updated Minions.rst"

This reverts commit 96aab88.

Revert "updated readtritium docs"

This reverts commit 6c10365.

Revert "created helper script for printing all sphinx references"

This reverts commit a9a9b4e.

Revert "changed lang to en"

This reverts commit 929f242.

Revert "fixed header comment so doxygen recognizes it"

This reverts commit dd36bc4.

Revert "moved macros from ReadCarCAN.c to ReadCarCAN.h so they are visible in docs"

This reverts commit 47d011f.

* Removed redundant code

* Apply suggestions from code review

Co-authored-by: Diya Rajon <[email protected]>
Co-authored-by: Madeleine Lee <[email protected]>

* Feature/GitHub workflow fix (#396)

* Changed github actions workflow to use install script from Embedded-Sharepoint

* initialize submodules before install tools

* fixed directory

* changed flags

* changed the target that is the phony so that later we could add additional targets and change what 'leader' points to

* addressed more review comments

* Apply suggestions from code review

Co-authored-by: Madeleine Lee <[email protected]>

* Apply suggestions from code review

Co-authored-by: Diya Rajon <[email protected]>

---------

Co-authored-by: ishdeshpa <[email protected]>
Co-authored-by: Madeleine Lee <[email protected]>
Co-authored-by: Nathaniel Delgado <[email protected]>
Co-authored-by: Diya Rajon <[email protected]>
Co-authored-by: Madeleine Lee <[email protected]>
  • Loading branch information
6 people authored Jan 2, 2024
1 parent fbbd8b6 commit 70b3526
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 121 deletions.
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

#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
#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){
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);
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
42 changes: 26 additions & 16 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
#define FIFO_NAME SendCarCAN_Q
#include "fifo.h"

Expand All @@ -48,22 +50,32 @@ 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;
CPU_TS ticks;

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

bool success = SendCarCAN_Q_put(&CANFifo, message);
static uint8_t carcan_ctr = 0;

if(carcan_ctr > SENDCARCAN_MSG_SKIP_CTR){
OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err);
assertOSError(err);

OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err);
assertOSError(err);
success = SendCarCAN_Q_put(&CANFifo, message);

if(success) OSSemPost(&CarCAN_Sem4, OS_OPT_POST_1, &err);
assertOSError(err);
OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err);
assertOSError(err);

carcan_ctr = 0;
}
carcan_ctr++;


if(success) {
OSSemPost(&CarCAN_Sem4, OS_OPT_POST_1, &err);
assertOSError(err);
}
}

/**
Expand Down Expand Up @@ -97,7 +109,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,
(CPU_STK*)putIOState_Stk,
(CPU_STK_SIZE)WATERMARK_STACK_LIMIT,
(CPU_STK_SIZE)TASK_SEND_CAR_CAN_STACK_SIZE,
Expand All @@ -119,13 +131,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 +151,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;
message.data[2] |= pinState << pin;
}

Expand All @@ -150,6 +159,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 +174,6 @@ static void Task_PutIOState(void *p_arg) {
while (1) {
putIOState();
OSTimeDlyHMSM(0, 0, 0, IO_STATE_DLY_MS, OS_OPT_TIME_HMSM_STRICT, &err);
}

assertOSError(err);
}
}
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
#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

#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;

// 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);

// 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

0 comments on commit 70b3526

Please sign in to comment.