Skip to content

Commit

Permalink
SendCarCAN Restructure (#337)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Dec 17, 2023
1 parent 5c13022 commit 66958b8
Show file tree
Hide file tree
Showing 25 changed files with 577 additions and 400 deletions.
25 changes: 0 additions & 25 deletions Apps/Inc/CAN_Queue.h

This file was deleted.

23 changes: 23 additions & 0 deletions Apps/Inc/SendCarCAN.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef __SENDCARCAN_H
#define __SENDCARCAN_H

#include "CANbus.h"

/**
* @brief Initialize SendCarCAN
*/
void SendCarCAN_Init();

/**
* @brief Wrapper to put new message in the CAN queue
*/
void SendCarCAN_Put(CANDATA_t message);

/**
* @brief return the space left in SendCarCAN_Q for debug purposes
*/
#ifdef DEBUG
uint8_t get_SendCarCAN_Q_Space(void);
#endif

#endif
25 changes: 21 additions & 4 deletions Apps/Inc/SendTritium.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

#include "common.h"

// #define SENDTRITIUM_PRINT_MES
#define SENDTRITIUM_PRINT_MES

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

#define FOREACH_Gear(GEAR) \
GEAR(FORWARD_GEAR) \
GEAR(NEUTRAL_GEAR) \
GEAR(REVERSE_GEAR) \
GEAR(FORWARD_GEAR), \
GEAR(NEUTRAL_GEAR), \
GEAR(REVERSE_GEAR), \

typedef enum GEAR_ENUM {
FOREACH_Gear(GENERATE_ENUM)
Expand All @@ -49,6 +49,23 @@ typedef struct TritiumState{
void (*stateDecider)(void);
} TritiumState_t;

#ifdef SENDTRITIUM_EXPOSE_VARS
// Inputs
extern bool cruiseEnable;
extern bool cruiseSet;
extern bool onePedalEnable;
extern bool regenEnable;

extern uint8_t brakePedalPercent;
extern uint8_t accelPedalPercent;

extern Gear_t gear;

extern TritiumState_t state;
extern float velocityObserved;
extern float cruiseVelSetpoint;
#endif

// Getter functions for local variables in SendTritium.c
EXPOSE_GETTER(bool, cruiseEnable)
EXPOSE_GETTER(bool, cruiseSet)
Expand Down
12 changes: 3 additions & 9 deletions Apps/Inc/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
#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 8
#define TASK_TELEMETRY_PRIO 9
#define TASK_DEBUG_DUMP_PRIO 10
#define TASK_COMMAND_LINE_PRIO 11
#define TASK_SEND_CAR_CAN_PRIO 7
#define TASK_DEBUG_DUMP_PRIO 8
#define TASK_COMMAND_LINE_PRIO 9

/**
* Stack Sizes
Expand All @@ -49,7 +48,6 @@
#define TASK_UPDATE_DISPLAY_STACK_SIZE DEFAULT_STACK_SIZE
#define TASK_READ_TRITIUM_STACK_SIZE DEFAULT_STACK_SIZE
#define TASK_SEND_CAR_CAN_STACK_SIZE DEFAULT_STACK_SIZE
#define TASK_TELEMETRY_STACK_SIZE DEFAULT_STACK_SIZE
#define TASK_DEBUG_DUMP_STACK_SIZE DEFAULT_STACK_SIZE
#define TASK_COMMAND_LINE_STACK_SIZE DEFAULT_STACK_SIZE

Expand All @@ -73,8 +71,6 @@ void Task_ReadTritium(void* p_arg);

void Task_SendCarCAN(void* p_arg);

void Task_Telemetry(void* p_arg);

void Task_DebugDump(void *p_arg);

void Task_CommandLine(void* p_arg);
Expand All @@ -90,7 +86,6 @@ extern OS_TCB ReadCarCAN_TCB;
extern OS_TCB UpdateDisplay_TCB;
extern OS_TCB ReadTritium_TCB;
extern OS_TCB SendCarCAN_TCB;
extern OS_TCB Telemetry_TCB;
extern OS_TCB DebugDump_TCB;
extern OS_TCB CommandLine_TCB;

Expand All @@ -104,7 +99,6 @@ extern CPU_STK ReadCarCAN_Stk[TASK_READ_CAR_CAN_STACK_SIZE];
extern CPU_STK UpdateDisplay_Stk[TASK_UPDATE_DISPLAY_STACK_SIZE];
extern CPU_STK ReadTritium_Stk[TASK_READ_TRITIUM_STACK_SIZE];
extern CPU_STK SendCarCAN_Stk[TASK_SEND_CAR_CAN_STACK_SIZE];
extern CPU_STK Telemetry_Stk[TASK_TELEMETRY_STACK_SIZE];
extern CPU_STK DebugDump_Stk[TASK_DEBUG_DUMP_STACK_SIZE];
extern CPU_STK CommandLine_Stk[TASK_COMMAND_LINE_STACK_SIZE];

Expand Down
4 changes: 2 additions & 2 deletions Apps/Inc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "config.h"

/* Used for generating ENUMS */
#define GENERATE_ENUM(ENUM) ENUM,
#define GENERATE_STRING(STRING) #STRING,
#define GENERATE_ENUM(ENUM) ENUM
#define GENERATE_STRING(STRING) #STRING

/**
* Used for creating getter functions (returns the value based on given inputs)
Expand Down
69 changes: 0 additions & 69 deletions Apps/Src/CAN_Queue.c

This file was deleted.

1 change: 0 additions & 1 deletion Apps/Src/DebugDump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "Tasks.h"
#include "bsp.h"
#include "CANbus.h"
#include "CAN_Queue.h"
#include "Pedals.h"
#include "Minions.h"
#include "Contactors.h"
Expand Down
6 changes: 4 additions & 2 deletions Apps/Src/ReadTritium.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

#include "ReadTritium.h"
#include "CAN_Queue.h"
#include "CANbus.h"
#include "UpdateDisplay.h"
#include "SendCarCAN.h"
#include "os_cfg_app.h"
#include <string.h>

Expand Down Expand Up @@ -43,7 +43,7 @@ Objective 1:
- if error
- assertOSError
- determine information important to telementry
- SendCarCAN
- Telemetry
- determine information important for storage
- acquire mutex on Storage Array
- Store information in Storage Array (based on index)
Expand Down Expand Up @@ -104,6 +104,8 @@ 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);
Expand Down
Loading

0 comments on commit 66958b8

Please sign in to comment.