-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInverterInterface.h
More file actions
192 lines (157 loc) · 4.38 KB
/
InverterInterface.h
File metadata and controls
192 lines (157 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#ifndef INVERTERINTERFACE_H
#define INVERTERINTERFACE_H
#include <stdint.h>
#include "FlexCAN_T4.h"
#include "MessageQueueDefine.h"
#include <hytech.h>
#include "DrivetrainSystem.h"
#include <CANInterface.h>
namespace HTUnits
{
using celcius = float;
using watts = float;
using var = float;
using torque_nm = float;
using speed_rpm = float;
using volts = float;
};
struct InverterParams_s
{
float MINIMUM_HV_VOLTAGE;
};
/**
* Struct containing id info for this specific inverter interface
*/
struct InverterIds_s
{
uint32_t inv_control_word_id;
uint32_t inv_control_input_id;
uint32_t inv_control_parameter_id;
};
/**
* Drivetrain system accessible structs for
* requesting change of state
*/
struct InverterControlWord_s
{
bool inverter_enable : 1;
bool hv_enable : 1;
bool driver_enable : 1;
bool remove_error : 1;
};
struct InverterControlInput_s
{
int16_t speed_rpm_setpoint;
int16_t positive_torque_limit;
int16_t negative_torque_limit;
};
struct InverterControlParams_s
{
uint16_t speed_control_kp;
uint16_t speed_control_ki;
uint16_t speed_control_kd;
};
/**
* For the most part these are mirrors of the lower-level CAN struct data,
* except with already fully float-ized data
**/
struct InverterStatus_s
{
bool hv_present : 1;
bool connected : 1;
bool new_data : 1;
bool system_ready : 1;
bool error : 1;
bool warning : 1;
bool quit_dc_on : 1;
bool dc_on : 1;
bool quit_inverter_on : 1;
bool inverter_on : 1;
bool derating_on : 1;
HTUnits::volts dc_bus_voltage;
uint16_t diagnostic_number;
};
struct InverterTemps_s
{
bool new_data : 1;
HTUnits::celcius motor_temp;
HTUnits::celcius inverter_temp;
HTUnits::celcius igbt_temp;
};
struct InverterPower_s
{
bool new_data : 1;
HTUnits::watts active_power;
HTUnits::var reactive_power;
};
struct MotorMechanics_s
{
bool new_data : 1;
HTUnits::watts actual_power;
HTUnits::torque_nm actual_torque;
HTUnits::speed_rpm actual_speed;
};
struct InverterControlFeedback_s
{
bool new_data : 1;
uint16_t speed_control_kp;
uint16_t speed_control_ki;
uint16_t speed_control_kd;
};
struct InverterFeedbackData_s
{
InverterStatus_s status;
InverterTemps_s temps;
InverterPower_s power;
MotorMechanics_s motor_mechanics;
InverterControlFeedback_s control_feedback;
};
/**
* Inverter interface
*/
class InverterInterface
{
public:
InverterInterface(
CANBufferType *msg_output_queue,
uint32_t inv_control_word_id,
uint32_t inv_control_input_id,
uint32_t inv_control_params_id,
InverterParams_s inverter_params) : msg_queue_(msg_output_queue), _inverter_params(inverter_params)
{
inverter_ids.inv_control_word_id = inv_control_word_id;
inverter_ids.inv_control_parameter_id = inv_control_params_id;
inverter_ids.inv_control_input_id = inv_control_input_id;
}
// TODO un-public these (they are public for testing)
/* receiving callbacks */
void receive_INV_STATUS(CAN_message_t &can_msg);
void receive_INV_TEMPS(CAN_message_t &can_msg);
void receive_INV_DYNAMICS(CAN_message_t &can_msg);
void receive_INV_POWER(CAN_message_t &can_msg);
void receive_INV_FEEDBACK(CAN_message_t &can_msg);
/* Sending */
void send_INV_SETPOINT_COMMAND();
void send_INV_CONTROL_WORD();
void send_INV_CONTROL_PARAMS();
/* Inverter Functs */
void set_speed(float desired_rpm, float torque_limit_nm);
void set_idle();
void set_inverter_control_word(InverterControlWord_s control_word);
InverterStatus_s get_inverter_status();
private:
InverterIds_s inverter_ids;
InverterControlInput_s _inverter_control_inputs;
InverterControlWord_s _inverter_control_word;
InverterControlParams_s _inverter_control_params;
InverterFeedbackData_s _feedback_data;
InverterParams_s _inverter_params;
/* Getters */
InverterStatus_s get_status();
InverterTemps_s get_temps();
InverterPower_s get_power();
MotorMechanics_s get_motor_mechanics();
InverterControlFeedback_s get_control_params();
CANBufferType *msg_queue_;
};
#endif // __INVERTERINTERFACE_H__