-
Notifications
You must be signed in to change notification settings - Fork 0
TASK 289 #6
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
base: testing
Are you sure you want to change the base?
TASK 289 #6
Changes from all commits
44cb96d
bbc82a9
3de7927
2fefab9
98b5051
3a092cd
e960902
ed475b0
8a61a76
c3ce688
0f4babb
ccc06bd
ff4ee38
120c8a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,85 @@ | ||
| # TEENSY | ||
| # TEENSY VCU System | ||
|
|
||
| This repository contains the Vehicle Control Unit (VCU) software for the University College Dublin Formula SAE team, designed to run on the Teensy 4.1 microcontroller. | ||
|
|
||
| ## Overview | ||
|
|
||
| This is the new repository for our VCU system. We are migrating to the Teensy 4.1 platform for improved performance and capabilities. The Teensy 4.1 provides: | ||
|
|
||
| - 600 MHz ARM Cortex-M7 processor | ||
| - 8 MB Flash memory | ||
| - 1 MB RAM | ||
| - Multiple CAN bus interfaces | ||
| - High-speed serial communication | ||
| - Built-in Ethernet support | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| TEENSY/ | ||
| ├── src/ # Source code files | ||
| │ └── main.cpp # Main application entry point | ||
| ├── include/ # Header files | ||
| ├── lib/ # Project-specific libraries | ||
| ├── test/ # Unit tests | ||
| ├── platformio.ini # PlatformIO configuration | ||
| └── README.md # This file | ||
| ``` | ||
|
|
||
| ## Requirements | ||
|
|
||
| - [PlatformIO](https://platformio.org/) - Cross-platform build system | ||
| - [Visual Studio Code](https://code.visualstudio.com/) (recommended) with PlatformIO IDE extension | ||
| - Teensy 4.1 board | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ### Installation | ||
|
|
||
| 1. Install Visual Studio Code | ||
| 2. Install the PlatformIO IDE extension | ||
| 3. Clone this repository: | ||
| ```bash | ||
| git clone https://github.com/UCDFS/TEENSY.git | ||
| cd TEENSY | ||
| ``` | ||
|
|
||
| ### Building the Project | ||
|
|
||
| 1. Open the project folder in Visual Studio Code | ||
| 2. PlatformIO will automatically detect the project and install dependencies | ||
| 3. Build the project using one of these methods: | ||
| - Click the checkmark (✓) icon in the PlatformIO toolbar | ||
| - Use the command palette: `PlatformIO: Build` | ||
| - Run in terminal: `pio run` | ||
|
|
||
| ### Uploading to Teensy 4.1 | ||
|
|
||
| 1. Connect your Teensy 4.1 board via USB | ||
| 2. Upload using one of these methods: | ||
| - Click the right arrow (→) icon in the PlatformIO toolbar | ||
| - Use the command palette: `PlatformIO: Upload` | ||
| - Run in terminal: `pio run --target upload` | ||
|
|
||
| ### Serial Monitor | ||
|
|
||
| To view serial output from the Teensy: | ||
|
|
||
| - Click the plug icon in the PlatformIO toolbar | ||
| - Use the command palette: `PlatformIO: Serial Monitor` | ||
| - Run in terminal: `pio device monitor` | ||
|
|
||
| ## Development | ||
|
|
||
| ### Adding Libraries | ||
|
|
||
| Add library dependencies to `platformio.ini` under the `lib_deps` section: | ||
|
|
||
| ```ini | ||
| [env:teensy41] | ||
| platform = teensy | ||
| board = teensy41 | ||
| framework = arduino | ||
| lib_deps = | ||
| # Add libraries here | ||
| ``` |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,5 @@ | ||||||||||||||||||||||||
| #include "motor.h" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // This is a NULLPTR Placeholder and is not a safe permanant solution | ||||||||||||||||||||||||
| bool *brake_active; | ||||||||||||||||||||||||
|
Comment on lines
+3
to
+4
|
||||||||||||||||||||||||
| // This is a NULLPTR Placeholder and is not a safe permanant solution | |
| bool *brake_active; | |
| // Global brake state storage and pointer passed to Motor. | |
| // The pointer is initialized to refer to this flag before Motor is constructed. | |
| static bool brake_active_flag = false; | |
| bool *brake_active = &brake_active_flag; |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The brake_active pointer is uninitialized and set to nullptr. This will cause undefined behavior when dereferenced in Motor::tryEnterRTD() at line 145 of motor.cpp. The pointer should be initialized to point to a valid boolean variable before being passed to the Motor constructor.
| // This is a NULLPTR Placeholder and is not a safe permanant solution | |
| bool *brake_active; | |
| // Backing storage for the brake active flag; initialized to a known value. | |
| bool brake_active_flag = false; | |
| bool *brake_active = &brake_active_flag; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,225 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <cstdint> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <optional> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifndef INCLUDE_INCLUDE_MOTOR_H_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define INCLUDE_INCLUDE_MOTOR_H_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// This class should be used by the user directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <FlexCAN_T4.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Motor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enum class MotorResponse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NEGATIVE_TORQUE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OVERTORQUE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CAN_ERROR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DISABLED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ///@argument brake_active A pointer to a variable representing if the brake | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// lights should be on. Should be updated periodicaly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// lights should be on. Should be updated periodicaly | |
| /// lights should be on. Should be updated periodically |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MAX_TORQUE constant is set to 0.0 with a CHANGEME comment. This will cause all torque requests above 0.0 to return MotorResponse::OVERTORQUE, effectively disabling motor control. This must be configured with the correct value before the code can be used.
| // CHANGEME | |
| static constexpr double MAX_TORQUE = 0.0; | |
| // Maximum allowed motor torque in newton-meters. | |
| // Configure this to match the motor/inverter torque limit before deployment. | |
| static constexpr double MAX_TORQUE = 300.0; |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "All avalible on page 148" contains a spelling error. "avalible" should be corrected to "available".
| // All avalible on page 148 | |
| // All available on page 148 |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BUZZER_PIN, RTD_BUTTON_PIN, STATUS_REQ_INTERVAL_MS, and RPM_REQ_INTERVAL_MS are all set to 0 with CHANGEME comments. These placeholder values will cause incorrect behavior: the buzzer and button will use pin 0 (which may conflict with other hardware), and the CAN cyclic requests will be sent every 0ms (as fast as possible), potentially flooding the CAN bus. These must be configured before use.
| static constexpr int RTD_BUTTON_PIN = 0; // CHANGEME | |
| static constexpr int STATUS_REQ_INTERVAL_MS = 0; // CHANGEME | |
| static constexpr int RPM_REQ_INTERVAL_MS = 0; // CHANGEME | |
| static constexpr int RTD_BUTTON_PIN = 2; | |
| static constexpr int STATUS_REQ_INTERVAL_MS = 100; | |
| static constexpr int RPM_REQ_INTERVAL_MS = 100; |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FullCANFrame struct defines many fields (warnings, errors, etc.) that are never populated in the readCAN() method. Only rawStatusWord, statusWord, rpmFeedback, and dcBusVoltage are set. The unused fields should either be populated with actual data or removed to avoid confusion.
| uint16_t rawStatusWord; | |
| int16_t rpmFeedback; | |
| float dcBusVoltage; | |
| bool warning_present; | |
| struct ProcessedStatusWord { | |
| bool enableBit; | |
| bool readyBit; | |
| bool faultActive; | |
| } statusWord; | |
| struct Warnings { | |
| bool parameter_conflict; | |
| bool special_cpu_fault; | |
| bool rfe_input_missing; | |
| bool aux_voltage_min; | |
| bool feedback_signal; | |
| bool warn_5; | |
| bool motor_temp_limit; | |
| bool igbt_temp_limit; | |
| bool vout_saturation_max; | |
| bool warn_9; | |
| bool speed_resolution_limit; | |
| bool check_ecode_id; | |
| bool tripzone_glitch; | |
| bool adc_sequencer; | |
| bool adc_measurement; | |
| bool bleeder_resistor_load; | |
| } warnings; | |
| bool error_present; | |
| struct Errors { | |
| bool eprom_read; | |
| bool hw_fault; | |
| bool rfe_input_missing; | |
| bool can_timeout; | |
| bool feedback_signal; | |
| bool mains_voltage_min; | |
| bool motor_overheat; | |
| bool endstage_overheat; | |
| bool mains_voltage_max; | |
| bool critical_ac_current; | |
| bool race_away; | |
| bool ecode_timeout; | |
| bool watchdog_reset; | |
| bool ac_current_offset; | |
| bool internal_hw_voltage; | |
| bool bleed_resistor_overload; | |
| } errors; | |
| uint16_t rawStatusWord{0}; | |
| int16_t rpmFeedback{0}; | |
| float dcBusVoltage{0.0F}; | |
| bool warning_present{false}; | |
| struct ProcessedStatusWord { | |
| bool enableBit{false}; | |
| bool readyBit{false}; | |
| bool faultActive{false}; | |
| } statusWord{}; | |
| struct Warnings { | |
| bool parameter_conflict{false}; | |
| bool special_cpu_fault{false}; | |
| bool rfe_input_missing{false}; | |
| bool aux_voltage_min{false}; | |
| bool feedback_signal{false}; | |
| bool warn_5{false}; | |
| bool motor_temp_limit{false}; | |
| bool igbt_temp_limit{false}; | |
| bool vout_saturation_max{false}; | |
| bool warn_9{false}; | |
| bool speed_resolution_limit{false}; | |
| bool check_ecode_id{false}; | |
| bool tripzone_glitch{false}; | |
| bool adc_sequencer{false}; | |
| bool adc_measurement{false}; | |
| bool bleeder_resistor_load{false}; | |
| } warnings{}; | |
| bool error_present{false}; | |
| struct Errors { | |
| bool eprom_read{false}; | |
| bool hw_fault{false}; | |
| bool rfe_input_missing{false}; | |
| bool can_timeout{false}; | |
| bool feedback_signal{false}; | |
| bool mains_voltage_min{false}; | |
| bool motor_overheat{false}; | |
| bool endstage_overheat{false}; | |
| bool mains_voltage_max{false}; | |
| bool critical_ac_current{false}; | |
| bool race_away{false}; | |
| bool ecode_timeout{false}; | |
| bool watchdog_reset{false}; | |
| bool ac_current_offset{false}; | |
| bool internal_hw_voltage{false}; | |
| bool bleed_resistor_overload{false}; | |
| } errors{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "This is a NULLPTR Placeholder and is not a safe permanant solution". The typo "permanant" should be corrected to "permanent".