Skip to content

Commit 222171e

Browse files
RCMast3rjhwang04
andauthored
Feature/drivetrain system pre inverter interface (#7)
* adding in linter w/ rules and step * added in check steps * updating clang / ide stuff * adding in linter w/ rules and step * added in check steps * updating clang / ide stuff * WIP: Fixing linter errors * WIP: Fixing Linter errors * Updated code to abide by clangtidy rules * (feat) changed some more linting rules * adding in v2 for now * progress on drivetrain system * added reqs / todos * working through more of the state machine * added current docs for drivetrain state machine * new adds to drivetrain system * added more design docs to the drivetrain system * added description for the inverter command messages * updated system and interface docs for inverter / drivetrain * updated inverter messaging * adding in feedback types for the inverter interface * working through state machine * adding in drivetrain system * addressing linter errors * fixing due to upstream --------- Co-authored-by: Justin Hwang <justin@goliath.org>
1 parent d5e8ba9 commit 222171e

File tree

11 files changed

+1045
-247
lines changed

11 files changed

+1045
-247
lines changed

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_Tasks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bool run_tick_state_machine_task(const unsigned long& sysMicros, const HT_TASK::
4848
extern HT_TASK::Task tick_state_machine_task;
4949

5050

51-
51+
5252
/**
5353
* The read_adc0 task will command adc0 to sample all eight channels, convert the outputs, and
5454
* store them in structs defined in shared_firmware_types. This function relies on adc_0 being

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__

lib/state_machine/include/VehicleStateMachine.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ enum class CAR_STATE
3838
class VehicleStateMachine
3939
{
4040
public:
41-
static VehicleStateMachine& getInstance()
42-
{
43-
static VehicleStateMachine instance;
44-
return instance;
45-
}
41+
VehicleStateMachine(DrivetrainSystem & drivetrain_system) :
42+
_current_state(CAR_STATE::STARTUP),
43+
_drivetrain(drivetrain_system),
44+
_buzzer(BuzzerController::getInstance()) {};
45+
4646

4747
/**
4848
* This tick() function handles all the update logic for traversing states, and calls the functions
@@ -57,10 +57,6 @@ class VehicleStateMachine
5757
CAR_STATE get_state() { return _current_state; }
5858

5959
private:
60-
VehicleStateMachine() :
61-
_current_state(CAR_STATE::STARTUP),
62-
_drivetrain(DrivetrainSystem<uint32_t>::getInstance()),
63-
_buzzer(BuzzerController::getInstance()) {};
6460

6561
void set_state_(CAR_STATE new_state, unsigned long curr_time);
6662

@@ -79,7 +75,7 @@ class VehicleStateMachine
7975
CAR_STATE _current_state;
8076

8177
/* System references to show dependence on systems library */
82-
DrivetrainSystem<uint32_t> &_drivetrain; //TODO: Make this InverterInterface instead of uint32_t
78+
DrivetrainSystem &_drivetrain; //TODO: Make this InverterInterface instead of uint32_t
8379
BuzzerController &_buzzer;
8480
// AMSSystem &_ams_system;
8581
};

0 commit comments

Comments
 (0)