Skip to content

Commit

Permalink
On car testing minimal (#45)
Browse files Browse the repository at this point in the history
* yo

* Fixed all pindefs outside of setup

* memes

* yo

* Added dash LED to safety system

* walker eepy

* working without adcs

* some comments to debug

* pushing current issues

* working kinda minimal progress

* working without steering sensor

* pushing up constants and stuff

* Reworked dashboard to use tick function and added LED states

* pushing up debugging tcmux

* torque requests

* the negative sign was correct

* fixing tcs and offsets

* almost working kinda, error after a second sending no torque

* working code

* known good debug

* yo

* working on car

* what is on car currently

* working except for hardware issue

* removed more print lines, simplified resetting of drivetrain, limited AMK max RPM for lot testing, re-enabled correct speed setpoint for torque control, and added in resetting of drivetrain via dash button

* minor change in main_minimal for serial definition and bringing actual main up to where minimal main is now

* Fixed pin defs for dashboard lights

* Fixed IMD and AMS lights going red if BOTS tripped

* Updated buzzer time and brake/accel thresholds

* Fix for buzzer timing, force buzzer to end before entering ready to drive

* Added new can message for inverter RPMs

* Drivetrain RPMs are sent to TCU

* Added DRIVETRAIN_ERR_STATUS_TELEM_hytech to telemetry

* Added drivetrain_status_telem_CAN_msg() (untested)

* Added some pedal data to drivetrain status message

* Added accumulator current/reference can messages

* Update to ADC interface to support setting 1M baud for MCP 04's. Changing pindefs for reading status of IMD and BMS OK

* discovered potential issue with drivetrain system

* fixed regen pedal scaling

* Steering Sensor should now be working

* add SAB reading to ECU

* Added Motor Controller torque message and rolling average print for seal testing

* Updated HT_CAN with new suspension messages. Removed old ones

* removed fixed point precision on steering sensor. no clue why it was there

* add load cell vectoring. add safe mode transition when controllers fault

* working on car

* attempting to remove deadzone in pedals for ensuring that we can always reach 100 percent and start at 0 percent accel and brake

* put stuff for loadcell mode 1 calibrate

* hopefully calibrated?

* tick load cell controller

* adding more to readme about auto-completition and setup of vscode

* Added torque mode LED display

* Changed torqueMode button

* Updated Mock dashboard interface

* adding in more docs to tc mux and tcs as well as adding in scaling for simple tc for regen

* moving main minimal into main

* only deploying docs on master

---------

Co-authored-by: walkermburns <[email protected]>
Co-authored-by: Dopp-IO <[email protected]>
Co-authored-by: Justin Hwang <[email protected]>
Co-authored-by: Dopp-IO <[email protected]>
Co-authored-by: shaynoorani <[email protected]>
  • Loading branch information
6 people authored Mar 21, 2024
1 parent e2487bd commit 083b47c
Show file tree
Hide file tree
Showing 47 changed files with 1,329 additions and 2,166 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: generate doxygen docs and deploy to github pages

on: [push, pull_request]

on:
push:
branches:
- master
jobs:

gen_docs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.vscode/launch.json
.vscode/ipch
.vscode/
compile_commands.json
docs/html/
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To test using platformio core CLI simply run `pio test -e test_env`.

To upload to the teensy simply use the platformio upload arrow shown [here at number 3](https://docs.platformio.org/en/latest/integration/ide/vscode.html#platformio-toolbar).

#### On Implementing and Importance of tests
##### On Implementing and Importance of tests
Unit tests are a great way to ensure that new features and new code in general can integrate and work well with other code. It provides a framework to verify that your stuff works the way it should and lets you know when and how it doesnt.

This project uses unit tests in the `test` folder to for both local testing and testing in the CI on github.
Expand All @@ -39,6 +39,44 @@ You can see results of previous test runs on commits here: https://github.com/hy

These MUST be maintained for functionality of the car.

### setup vscode
##### with auto-completition and advanced navigation using compile commands


the `compile_commands.json` file is a file that gets generated in the build folder upon excution of the [compiledb platformio task](https://docs.platformio.org/en/latest/integration/compile_commands.html) that sets up the include paths for vscode. [more about compile_commands.json here](https://clangd.llvm.org/design/compile-commands).

If you enter the platformio terminal, you can generate compile commands with
1. ![alt text](image-1.png)

then
2. ```pio run -t compiledb -e teensy41```


this will generate the compile commands for the `teensy41` environment which is the environment we use to build and flash to the car. in a similar fashion, other environments (eg: `test_env`) can have their compile commands generated.

3. then you need to setup vscode to recognize where this file is, which gets put into the `.pio` folder in your workspace. To do this, simply create a `.vscode` folder in the workspace and add a file called `c_cpp_properties.json` and it should look like this:

```json
{
"configurations": [
{
"name": "teensy41",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"compileCommands": "${workspaceFolder}/.pio/build/teensy41/compile_commands.json"
}
],
"version": 4
}
```
then you can select this configuration to be used with [this c/c++ extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) in vscode for auto-completition and code navigation.

to select the configuration, use the hotkey `ctrl+shift+p` to open the command prompt in vscode, and then type \`C/C++: Select a Configuration\` and then select your configuration for which you named above.


## Design Lore of the Code
Expand Down
1 change: 0 additions & 1 deletion compile_commands.json

This file was deleted.

Binary file added image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
124 changes: 0 additions & 124 deletions include/MCU_rev12_dfs.h

This file was deleted.

38 changes: 25 additions & 13 deletions include/MCU_rev15_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
const int ADC1_CS = 34;
const int ADC2_CS = 33;
const int ADC3_CS = 29;
const int SOFTWARE_OK = 28;
const int SOFTWARE_OK = 8;
const int WATCHDOG_INPUT = 32;

// serial def
HardwareSerial* STEERING_SERIAL = &Serial5;

// ADC1 channel defs
const int MCU15_ACCEL1_CHANNEL = 2;
Expand All @@ -36,17 +34,31 @@ const unsigned long INV_CAN_BAUDRATE = 500000;
const unsigned long TELEM_CAN_BAUDRATE = 500000;

// APPS/Brake pedal parameters
const int ACCEL1_MIN_THRESH = 100;
const int ACCEL2_MIN_THRESH = 100;
const int ACCEL1_MAX_THRESH = 3000;
const int ACCEL2_MAX_THRESH = 3000;
const int ACCEL1_MIN_THRESH = 2087;
const int ACCEL2_MIN_THRESH = 1472;
const int ACCEL1_MAX_THRESH = 3283;
const int ACCEL2_MAX_THRESH = 323;
const float APPS_ACTIVATION_PERCENTAGE = 0.1;

const int BRAKE1_MIN_THRESH = 100;
const int BRAKE2_MIN_THRESH = 100;
const int BRAKE1_MAX_THRESH = 3000;
const int BRAKE2_MAX_THRESH = 3000;
const float BRAKE_ACTIVATION_PERCENTAGE = 0.05;
const float BRAKE_MECH_THRESH = 0.05; // TODO: Determine actual mech threshold
const int BRAKE1_MIN_THRESH = 2757;
const int BRAKE2_MIN_THRESH = 867;
const int BRAKE1_MAX_THRESH = 1421;
const int BRAKE2_MAX_THRESH = 2198;
const float BRKAE_ACTIVATION_PERCENTAGE = 0.05;
const float BRAKE_MECH_THRESH = 0.55;

// Load Cell Defs to convert raw to lbs
// lbs = (scale)*raw + offset

const float LOADCELL_FL_SCALE = 0.0553;
const float LOADCELL_FL_OFFSET = 15.892;

const float LOADCELL_FR_SCALE = 0.0512;
const float LOADCELL_FR_OFFSET = 17.196;

const float LOADCELL_RL_SCALE = 0.1147;
const float LOADCELL_RL_OFFSET = 21.842;

const float LOADCELL_RR_SCALE = 0.0588;
const float LOADCELL_RR_OFFSET = 19.576;
#endif /* __MCU15_H__ */
14 changes: 5 additions & 9 deletions lib/interfaces/include/AMSInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#include "FlexCAN_T4.h"
#include "HyTech_CAN.h"


/// @brief Heartbeat Interval is the allowable amount of time between BMS status messages before car delatches */
const unsigned long HEARTBEAT_INTERVAL = 20; // milliseconds
/// @brief The total pcc threshold is the lowest allowable voltage of the entire pack (in Volts)*/
/* Heartbeat Interval is the allowable amount of time between BMS status messages before car delatches */
const unsigned long HEARTBEAT_INTERVAL = 2000; // milliseconds
/* The total pcc threshold is the lowest allowable voltage of the entire pack (in Volts)*/
const unsigned long PACK_CHARGE_CRIT_TOTAL_THRESHOLD = 420;
/* The lowest pcc threshold is the lowest allowable single cell voltage (in 100 microvolts)*/
const unsigned long PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD = 35000; //equivalent to 3.5V
Expand All @@ -32,11 +31,8 @@ class AMSInterface
filtered_max_cell_temp(init_temp),
filtered_min_cell_voltage(init_volt),
cell_temp_alpha(temp_alpha),
cell_voltage_alpha(volt_alpha)
{
// Set pin mode
pinMode(pin_software_ok_, OUTPUT);
}
cell_voltage_alpha(volt_alpha) {};

/* Overloaded constructor that only takes in software OK pin and uses default voltages and temp*/
AMSInterface(int sw_ok_pin):
AMSInterface(sw_ok_pin, DEFAULT_INIT_TEMP, DEFAULT_INIT_VOLTAGE, DEFAULT_TEMP_ALPHA, DEFAULT_VOLTAGE_ALPHA) {};
Expand Down
27 changes: 24 additions & 3 deletions lib/interfaces/include/DashboardInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
#include "MessageQueueDefine.h"
#include "FlexCAN_T4.h"
#include "hytech.h"
#include "MCUInterface.h"
#include "MCU_status.h"

/*
Enum for the car's torque limits
MOVE ME! - ideally into a TorqueControllerDefs.h file
to prevent circular dependencies
*/
enum class TorqueLimit_e
{
TCMUX_LOW_TORQUE = 0,
TCMUX_MID_TORQUE = 1,
TCMUX_FULL_TORQUE = 2,
TCMUX_NUM_TORQUE_LIMITS = 3,
};

/* Enum for the modes on the dial, corresponds directly to dial index pos. */
enum class DialMode_e
Expand Down Expand Up @@ -40,8 +55,8 @@ enum class DashLED_e
INERTIA_LED,
GLV_LED,
CRIT_CHARGE_LED,
START_LED,
MC_ERROR_LED,
START_LED, /// from state machine. When READY_TO_DRIVE, set START_LED to true. See what else uses READY_TO_DRIVE so that you can update START_LED.
MC_ERROR_LED, /// from DrivetrainSystem.cpp, get drivetrain_error_occurred()
IMD_LED,
AMS_LED,
};
Expand Down Expand Up @@ -112,9 +127,15 @@ class DashboardInterface
@param can_msg is the reference to a new CAN message CAN_message_t
*/
void read(const CAN_message_t &can_msg);

/* write function will Pack a message based on the current data in the interface and push it to the tx buffer */
CAN_message_t write();

/*
Tick DashboardInterface at 10hz to gather data and send CAN message
*/
void tick10(MCUInterface* mcu, int car_state, bool buzzer, bool drivetrain_error, TorqueLimit_e torque);

/*!
getter for the dashboard's current dial position (drive profile)
@return returns a DialMode_e enum with the current dial position
Expand All @@ -129,7 +150,7 @@ class DashboardInterface
/* getter for the mark button */
bool specialButtonPressed();
/* getter for the torque button (does not currently exist on dash ) */
bool torqueButtonPressed();
bool torqueModeButtonPressed();
/* getter for the inverter reset button (clears error codes ) */
bool inverterResetButtonPressed();
/* getter for the launch control button */
Expand Down
11 changes: 11 additions & 0 deletions lib/interfaces/include/HytechCANInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "InverterInterface.h"
#include "DashboardInterface.h"
#include "AMSInterface.h"
#include "SABInterface.h"

/*
struct holding interfaces processed by process_ring_buffer()
Expand All @@ -27,6 +28,7 @@ struct CANInterfaces
InverterInterface<circular_buffer> *rear_right_inv;
DashboardInterface *dash_interface;
AMSInterface *ams_interface;
SABInterface *sab_interface;
};

// the goal with the can interface is that there exists a receive call that appends to a circular buffer
Expand Down Expand Up @@ -70,7 +72,10 @@ template <typename BufferType, typename InterfaceType>
void process_ring_buffer(BufferType &rx_buffer, const InterfaceType &interfaces, unsigned long curr_millis)
{
// TODO switch to using the global CAN receive function from the generated CAN library
// if(rx_buffer.size() > 0){

// Serial.println(rx_buffer.size());
// }
while (rx_buffer.available())
{
CAN_message_t recvd_msg;
Expand Down Expand Up @@ -136,6 +141,11 @@ void process_ring_buffer(BufferType &rx_buffer, const InterfaceType &interfaces,
case ID_MC4_ENERGY:
interfaces.rear_right_inv->receive_energy_msg(recvd_msg);
break;

// SAB msgs
case SAB_SUSPENSION_CANID:
interfaces.sab_interface->retrieve_pots_and_load_cells_CAN(recvd_msg);
break;
}
}
}
Expand All @@ -155,6 +165,7 @@ void send_all_CAN_msgs(bufferType &buffer, FlexCAN_T4_Base *can_interface)
buffer.pop_front(buf, sizeof(CAN_message_t));
memmove(&msg, buf, sizeof(msg));
can_interface->write(msg);
// delayMicroseconds(2500);
}
}

Expand Down
Loading

0 comments on commit 083b47c

Please sign in to comment.