Skip to content

Commit 688b024

Browse files
committed
Merged main
2 parents 7b00aca + 222171e commit 688b024

26 files changed

+1287
-387
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.pio
22
.vscode/*
33
compile_commands.json
4-
.cache/
4+
.cache/
5+
**.DS_Store

getcompilecommands.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -o pipefail
3+
pio run -e teensy41
4+
pio run -t compiledb -e teensy41

include/VCR_Constants.h

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,49 @@ const int ADC1_CS = 11; // MCP3208. ADC1 in VCR schematic. Used for extra thermi
1616
/* -------------------------------------------------- */
1717

1818
/* Channels on adc_0 */
19-
const int GLV_SENSE_CHANNEL = 0;
20-
const int CURRENT_SENSE_CHANNEL = 1;
21-
const int REFERENCE_SENSE_CHANNEL = 2;
22-
const int RL_LOADCELL_CHANNEL = 3;
23-
const int RR_LOADCELL_CHANNEL = 4;
24-
const int RL_SUS_POT_CHANNEL = 5;
25-
const int RR_SUS_POT_CHANNEL = 6;
19+
constexpr int GLV_SENSE_CHANNEL = 0;
20+
constexpr int CURRENT_SENSE_CHANNEL = 1;
21+
constexpr int REFERENCE_SENSE_CHANNEL = 2;
22+
constexpr int RL_LOADCELL_CHANNEL = 3;
23+
constexpr int RR_LOADCELL_CHANNEL = 4;
24+
constexpr int RL_SUS_POT_CHANNEL = 5;
25+
constexpr int RR_SUS_POT_CHANNEL = 6;
2626
// const int UNUSED_CHANNEL = 7;
2727

2828
/* Channels on ADC_1 */
29-
const int THERMISTOR_0 = 0;
30-
const int THERMISTOR_1 = 1;
31-
const int THERMISTOR_2 = 2;
32-
const int THERMISTOR_3 = 3;
33-
const int THERMISTOR_4 = 4;
34-
const int THERMISTOR_5 = 5;
35-
const int THERMISTOR_6 = 6;
36-
const int THERMISTOR_7 = 7;
29+
constexpr int THERMISTOR_0 = 0;
30+
constexpr int THERMISTOR_1 = 1;
31+
constexpr int THERMISTOR_2 = 2;
32+
constexpr int THERMISTOR_3 = 3;
33+
constexpr int THERMISTOR_4 = 4;
34+
constexpr int THERMISTOR_5 = 5;
35+
constexpr int THERMISTOR_6 = 6;
36+
constexpr int THERMISTOR_7 = 7;
3737

3838
/* Scaling and offset */
39-
const float GLV_SENSE_SCALE = -1; //TODO: FIGURE THIS OUT
40-
const int GLV_SENSE_OFFSET = -1; //TODO: FIGURE THIS OUT
41-
const float CURRENT_SENSE_SCALE = -1; //TODO: FIGURE THIS OUT
42-
const int CURRENT_SENSE_OFFSET = -1; //TODO: FIGURE THIS OUT
43-
const float REFERENCE_SENSE_SCALE = -1; //TODO: FIGURE THIS OUT
44-
const int REFERENCE_SENSE_OFFSET = -1; //TODO: FIGURE THIS OUT
45-
const float RL_LOADCELL_SCALE = -1; //TODO: FIGURE THIS OUT
46-
const int RL_LOADCELL_OFFSET = -1; //TODO: FIGURE THIS OUT
47-
const float RR_LOADCELL_SCALE = -1; //TODO: FIGURE THIS OUT
48-
const int RR_LOADCELL_OFFSET = -1; //TODO: FIGURE THIS OUT
49-
const float RL_SUS_POT_SCALE = -1; //TODO: FIGURE THIS OUT
50-
const int RL_SUS_POT_OFFSET = -1; //TODO: FIGURE THIS OUT
51-
const float RR_SUS_POT_SCALE = -1; //TODO: FIGURE THIS OUT
52-
const int RR_SUS_POT_OFFSET = -1; //TODO: FIGURE THIS OUT
39+
constexpr float GLV_SENSE_SCALE = (float)(24.0/((2.77149877/3.3)*4096.0)); //unsure about the multiplication by 4.0865
40+
constexpr int GLV_SENSE_OFFSET = 0; //No offset for GLV
41+
constexpr float CURRENT_SENSE_SCALE = (float)(24/((2.77149877/3.3)*4096)); //unsure about the multiplication by 4.0865
42+
constexpr int CURRENT_SENSE_OFFSET = 0; //No offset for CURRENT_SENSE
43+
constexpr float REFERENCE_SENSE_SCALE = (float)(24/((2.77149877/3.3)*4096)); //unsure about the multiplication by 4.0865
44+
constexpr int REFERENCE_SENSE_OFFSET = 0; //No offset for REFERENCE_SENSE
5345

46+
//Values are from the old MCU rev15
47+
constexpr float RL_LOADCELL_SCALE = 0.1149f;
48+
constexpr float RL_LOADCELL_OFFSET = 13.526f / RL_LOADCELL_SCALE;
49+
constexpr float RR_LOADCELL_SCALE = 0.118f;
50+
constexpr float RR_LOADCELL_OFFSET = 25.721f / RR_LOADCELL_SCALE;
5451

52+
//does not matter that much
53+
constexpr float RL_SUS_POT_SCALE = 1;
54+
constexpr int RL_SUS_POT_OFFSET = 1;
55+
constexpr float RR_SUS_POT_SCALE = 1;
56+
constexpr int RR_SUS_POT_OFFSET = 1;
5557

58+
constexpr int WATCHDOG_PIN = 36;
59+
60+
namespace default_system_params
61+
{
62+
constexpr unsigned long KICK_INTERVAL_MS = 10UL;
63+
}
5664
#endif /* VCR_CONSTANTS */

include/VCR_Globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ constexpr unsigned int channels_within_mcp_adc = 8;
1919
extern MCP_ADC<channels_within_mcp_adc> adc_0; // MCP3208. ADC0 in VCR schematic. Used for valuable telem data.
2020
extern MCP_ADC<channels_within_mcp_adc> adc_1; // MCP3208. ADC1 in VCR schematic. Used for extra thermistors or extra sensors while testing.
2121

22+
2223
#endif /* VCR_GLOBALS */

include/VCR_Tasks.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,19 @@
2525

2626
#ifndef VCR_TASKS
2727
#define VCR_TASKS
28-
// NOLINTBEGIN // Allow tasks to be non-constant to avoid updating the HT_SCHED library.
2928

3029
/* From HT_SCHED library */
3130
#include "ht_sched.hpp"
3231

3332
/* From shared_firmware_types library */
3433
#include "SharedFirmwareTypes.h"
3534

36-
/**
37-
* This "Test" function is purely for validation of the HT_SCHED dependency. This is intended to be removed when
38-
* further development occurs.
39-
*/
40-
bool init_test_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
41-
bool run_test_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
42-
extern HT_TASK::Task test_task;
43-
35+
/* Local includes */
36+
#include "WatchdogSystem.h"
37+
#include "VCR_Constants.h"
38+
#include "VehicleStateMachine.h"
39+
#include "VCR_Globals.h"
40+
#include "Buzzer.h"
4441

4542
/**
4643
* The "tick state machine" task will simply call the state machine's tick function with the current
@@ -51,11 +48,11 @@ bool run_tick_state_machine_task(const unsigned long& sysMicros, const HT_TASK::
5148
extern HT_TASK::Task tick_state_machine_task;
5249

5350

54-
51+
5552
/**
5653
* The read_adc0 task will command adc0 to sample all eight channels, convert the outputs, and
5754
* store them in structs defined in shared_firmware_types. This function relies on adc_0 being
58-
* defined in ADC_interface.h.
55+
* defined in VCRGlobals.h.
5956
*/
6057
bool init_read_adc0_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
6158
bool run_read_adc0_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
@@ -67,9 +64,9 @@ extern HT_TASK::Task read_adc0_task;
6764
* NOTE: These channels are UNUSED BY DEFAULT and exist ONLY FOR TESTING. You may edit this
6865
* manually to add sensors.
6966
*
70-
* The read_adc1 task will command adc0 to sample all eight channels, convert the outputs, and
67+
* The read_adc1 task will command adc1 to sample all eight channels, convert the outputs, and
7168
* store them in a struct defined in shared_firmware_types. This function relies on adc_1 being
72-
* defined in ADC_interface.h.
69+
* defined in VCRGlobals.h.
7370
*/
7471
bool init_read_adc1_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
7572
bool run_read_adc1_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
@@ -84,4 +81,12 @@ extern HT_TASK::Task read_adc1_task;
8481
bool run_update_buzzer_controller_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
8582
extern HT_TASK::Task update_buzzer_controller_task;
8683

84+
85+
86+
/**
87+
* This task will fetch the watchdog state from WatchdogSystem and write it to the watchdog pin
88+
*/
89+
bool run_kick_watchdog(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
90+
extern HT_TASK::Task kick_watchdog_task;
91+
8792
#endif /* VCR_TASKS */

lib/interfaces/README.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
## Inverter Interface
2+
3+
4+
### GPIO connections
5+
6+
7+
### CAN parameter / message descriptions
8+
9+
#### VCR output / control messages:
10+
11+
below is the description of the control messages that will be configured within the free CAN configuration of the AMKs. these are subject to change, however it is primarily a modification of the "fixed CAN commnicaiton" protocol that the AMK kit ships with / is documented
12+
13+
- Control Word (will be sent every 50ms, monitored by the inverter to be expected at least every 75ms)
14+
- `bool inverter_enable`
15+
- AKA (`AMK_bInverterOn`)
16+
- `bool hv_enable`
17+
- AKA (`AMK_bDcOn`)
18+
- `bool driver_enable`
19+
- AKA (`AMK_bEnable`)
20+
- `bool remove_error`
21+
- AKA (`AMK_bErrorReset`)
22+
23+
- Control Input Message (will be attempted to be sent every 5ms, monitored by the inverter to be expected at least every 20ms)
24+
- `int16_t speed_setpoint`
25+
- __NOTE: active only when in speed control mode__
26+
- AKA (`AMK_TargetVelocity`) / Special Signal index 6 / AKA 16-bit version of SERCOS parameter ID36 (unknown why this is 16 bit vs the 32 bit SERCOS parameter in manual)
27+
- the RPM setpoint for the inverter in units of RPM.
28+
- `int16_t positive_torque_limit`
29+
- AKA (`AMK_TorqueLimitPositiv`) / SERCOS parameter ID82 / Special Signal index 13
30+
- positive torque limit for reaching the desired rpm in units of 0.1% of the nominal torque (=9.8Nm)(known as Mn in docs).
31+
32+
EXAMPLE: `positive_torque_limit=1000` means that the positive torque limit is set to 100% of the nominal torque, so the actual torque limit being set by this is equal to 9.8Nm, and 200% would be equal to 19.6Nm.
33+
- `int16_t negative_torque_limit`
34+
- AKA (`AMK_TorqueLimitNegativ`) / SERCOS parameter ID83 / Special Signal index 14
35+
- `positive_torque_limit` with a negative sign.
36+
- `int16_t torque_setpoint`
37+
- __NOTE: active only when in torque control mode.__
38+
- AKA SERCOS parameter ID80 / Special Signal index 17
39+
- the torque setpoint for the inverter in units of percentage as described in the `positive_torque_limit` message member above
40+
41+
- Control parameter message (will be sent intermitently, not monitored by the inverter to be expected at any regular period)
42+
- `uint16_t speed_control_kp`
43+
- P for the speed control mode
44+
- AKA SERCOS parameter ID100
45+
- `uint16_t speed_control_ki`
46+
- I parameter to be set internally on the inverter
47+
- AKA SERCOS parameter ID101
48+
- `uint16_t speed_control_kd`
49+
- D parameter to be set internally on the inverter
50+
- AKA SERCOS parameter ID102
51+
52+
#### inverter messages
53+
54+
- inverter status / ( `AMK_Status` (16 bit) + + DC bus voltage (16 bit) + `AMK_ErrorInfo` (16 bit kinda(?))) (will be periodically sent from the inverter every 20ms)
55+
- `bool system_ready`
56+
- AKA (`AMK_bSystemReady`) / bit 9 within Special Signal Status word formula student (System Ready (SBM)) /
57+
- displays when the system is error free / ready to be initialized
58+
- `bool error`
59+
- AKA (`AMK_bError`) / bit 10 within Special Signal Status word formula student
60+
- displays that an error is present
61+
- `bool warning`
62+
- AKA (`AMK_bWarn`) / bit 11
63+
- warning present (such as if derating is on)
64+
- `bool quit_dc_on`
65+
- AKA (`AMK_bQuitDcOn`) / bit 12
66+
- HV activation acknowledgment / verification (says whether or not HV is ACTUALLY present to the inverter)
67+
- `bool dc_on`
68+
- AKA (`AMK_bDcOn`) / bit 13
69+
- mirrors / is feedback of what is set by the VCR for its `hv_enable`
70+
- `bool quit_inverter_on`
71+
- AKA (`AMK_bQuitInverterOn`) / bit 14
72+
- controller is enabled
73+
- `bool inverter_on`
74+
- AKA (`AMK_bInverterOn`) / bit 15
75+
- mirror / feedback of `inverter_enable` set by the control word
76+
- `bool derating_on`
77+
- AKA (`AMK_bDerating`) / bit 16
78+
- says whether or not derating is active (torque derating)
79+
- `uint16_t dc_bus_voltage`
80+
- AKA SERCOS Paramter ID32836
81+
- actual DC bus voltage
82+
- `uint16_t diagnostic_number`
83+
- AKA (`AMK_ErrorInfo`)
84+
85+
- inverter temps (will be periodically sent from the inverter every 20ms)
86+
- `int16_t motor_temp`
87+
- temperature of the motor in units of 0.1 degrees celcius
88+
- AKA (`AMK_TempMotor`) / Special Signal index 7 / SERCOS parameter ID33117
89+
- `int16_t inverter_temp`
90+
- temp of the inverter cold plate in units of 0.1 degrees celcius
91+
- AKA (`AMK_TempInverter`) / Special Signal index 8 / SERCOS parameter ID33116
92+
93+
- details: "ID33116 shows the temperature of the cold plate (heat sink of the IGBT and at the same time of the rear wall of the device).
94+
The triggering thresholds are device-specific, are set in the SEEP (Device-internal memory, serial EEPROM) at the factory and cannot be changed by the user.
95+
If critical temperatures occur for the devices, the warning 2350 'Device temperature warning' is generated as well as the error
96+
message 2346 'Converter temperature error' after the warning time1) (ID32943) has expired."
97+
- `int16_t igbt_temp`
98+
- temp of the IGBTs in units of 0.1 degrees celcius
99+
- AKA (`AMK_TempIGBT`) / Special Signal index 27 / SERCOS parameter ID34215
100+
101+
- inverter dynamics data (will be periodically sent from the inverter every 5ms)
102+
- `uint32_t actual_power_w`
103+
- mechanical motor power in watts (from actual torque and actual speed)
104+
- AKA SERCOS parameter ID33100
105+
- `int16_t actual_torque_nm`
106+
- actual torque value in the same units as `positive_torque_limit`
107+
- AKA Special Signal index 19 / SERCOS parameter ID84
108+
- `int16_t actual_speed_rpm`
109+
- motor speed in units of rpm
110+
- AKA Special Signal value index 6
111+
112+
- inverter electrical power data (will be periodically sent from the inverter every 5ms)
113+
- `int32_t active_power_w`
114+
- electrical power (use / creation) in watts of the inverter
115+
- can be negative when in regen / positive when driving motor
116+
- AKA SERCOS parameter ID33171
117+
- `int32_t reactive_power_var`
118+
- electrical reactive power (inductive or capacitive)
119+
- positive value = inductive consumer, negative value = capacitive consumer
120+
- AKA SERCOS parameter ID33172
121+
122+
- inverter parameter feedback (inverter's speed PID vals) (will be sent periodically from the inverter every 20ms)
123+
- `uint16_t speed_control_kp`
124+
- inverter's internal value of kp
125+
- AKA SERCOS parameter ID100
126+
- `uint16_t speed_control_ki`
127+
- inverter's internal value of (TN) ki
128+
- AKA SERCOS parameter ID101
129+
- `uint16_t speed_control_kd`
130+
- inverter's internal value of (TD) kd
131+
- AKA SERCOS parameter ID102
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#ifndef INVERTERINTERFACE_H
2+
#define INVERTERINTERFACE_H
3+
#include <stdint.h>
4+
5+
namespace HTUnits
6+
{
7+
using celcius = float;
8+
using watts = float;
9+
using var = float;
10+
using torque_nm = float;
11+
using speed_rpm = float;
12+
using volts = float;
13+
};
14+
15+
// for the most part these are mirrors of the lower-level CAN struct data, except with already fully float-ized data
16+
17+
struct InverterStatus_s
18+
{
19+
bool system_ready : 1;
20+
bool error : 1;
21+
bool warning : 1;
22+
bool quit_dc_on : 1;
23+
bool dc_on : 1;
24+
bool quit_inverter_on : 1;
25+
bool inverter_on : 1;
26+
bool derating_on : 1;
27+
HTUnits::volts dc_bus_voltage;
28+
uint16_t diagnostic_number;
29+
};
30+
31+
struct InverterTemps_s
32+
{
33+
HTUnits::celcius motor_temp;
34+
HTUnits::celcius inverter_temp;
35+
HTUnits::celcius igbt_temp;
36+
};
37+
38+
struct InverterPower_s
39+
{
40+
HTUnits::watts active_power;
41+
HTUnits::var reactive_power;
42+
};
43+
44+
struct MotorMechanics_s
45+
{
46+
HTUnits::watts actual_power;
47+
HTUnits::torque_nm actual_torque;
48+
HTUnits::speed_rpm actual_speed;
49+
};
50+
51+
struct InverterControlParams_s
52+
{
53+
uint16_t speed_control_kp;
54+
uint16_t speed_control_ki;
55+
uint16_t speed_control_kd;
56+
};
57+
58+
struct InverterFeedbackData_s
59+
{
60+
InverterStatus_s status;
61+
InverterTemps_s temps;
62+
InverterPower_s power;
63+
MotorMechanics_s motor_mechanics;
64+
InverterControlParams_s control_params;
65+
};
66+
67+
// struct InverterMotorControl_s
68+
// {
69+
70+
// }
71+
72+
class InverterInterface
73+
{
74+
75+
};
76+
#endif // __INVERTERINTERFACE_H__

0 commit comments

Comments
 (0)