MCU
Loading...
Searching...
No Matches
InverterInterface.h
Go to the documentation of this file.
1#ifndef INVERTERINTERFACE
2#define INVERTERINTERFACE
3
4#include <stdint.h>
5
6#include "MC_setpoints_command.h"
7#include "MC_energy.h"
8#include "MC_status.h"
9#include "MC_temps.h"
10
11#include "FlexCAN_T4.h"
12#include "MCUInterface.h"
13
14#include <Arduino.h>
15#include <Metro.h>
16/* Struct holding torque and speed setpoint */
18{
21};
22
23template <typename message_queue>
25{
26public:
27 InverterInterface(message_queue *msg_output_queue, uint32_t can_id)
28 {
29 // TODO fix me with correct value from config of inverter
30 id110_val_ = 1.0;
31 msg_queue_ = msg_output_queue;
32 can_id_ = can_id;
33 }
34
35 // getter for MC id
36 uint32_t get_id() { return can_id_; };
37
38 /* read energy messages handler from HytechCANInterface */
39 void receive_energy_msg(CAN_message_t &msg);
40 /* read status messages handler from HytechCANInterface */
41 void receive_status_msg(CAN_message_t &msg);
42 /* read temp messages handler from HytechCANInterface */
43 void receive_temp_msg(CAN_message_t &msg);
44
45 /* send MC disable message */
46 void disable();
47 /* send MC enable HV message */
49 /* send MC enable message */
51 /* send MC command no torque message*/
54 /* sends torque and rpm setpoints to MC */
55 void handle_command(const InverterCommand &command);
56 /* send MC command reset message*/
58
59 /* Returns the value stored in system_ready_, which is
60 read from the MC in receive_status_msg() */
62 {
63 return system_ready_;
64 }
65
66 /* Returns the value stored in error_, which is
67 read from the MC in receive_status_msg() */
68 bool get_error()
69 {
70 return error_;
71 }
72
73 /* Returns the value stored in error_, which is
74 read from the MC in receive_status_msg() */
76 {
77 return warning_;
78 }
79
80 /* Returns the value stored in quit_dc_on_, which is
81 read from the MC in receive_status_msg() */
83 {
84 return quit_dc_on_;
85 }
86
87 /* Returns the value stored in dc_on_, which is
88 read from the MC in receive_status_msg() */
89 bool get_dc_on()
90 {
91 return dc_on_;
92 }
93
94 /* Returns the value stored in quit_inverter_on_, which is
95 read from the MC in receive_status_msg() */
97 {
98 return quit_inverter_on_;
99 }
100
101 /* Returns the value stored in inverter_on_, which is
102 read from the MC in receive_status_msg() */
104 {
105 return inverter_on_;
106 }
107
108 /* Returns the value stored in derating_on_, which is
109 read from the MC in receive_status_msg() */
111 {
112 return derating_on_;
113 }
114
115 /* check for dc bus voltage */
116 uint16_t dc_bus_voltage()
117 {
118 return dc_bus_voltage_;
119 }
120
121 int16_t get_speed() { return speed_; }
126 MC_temps get_temps_msg() { return mc_temps_; }
127 MC_setpoints_command get_cmd_msg() { return curr_cmd_; }
128
129private:
130 float id110_val_; // for scaling to proper iq and id vals
133 /* write setpoints message to the CAN buffer */
134 void write_cmd_msg_to_queue_(MC_setpoints_command msg);
135 int16_t speed_;
137
138 /* Booleans to store data from the MC. Updated in receive_status_msg() */
140 bool error_;
143 bool dc_on_;
147 MC_setpoints_command curr_cmd_; // TODO unfuck this this is stupid HACK
148 MC_temps mc_temps_; // TODO unfuck this this is stupid HACK
149 message_queue *msg_queue_;
150 uint32_t can_id_;
151 Metro timer_can_ = Metro(20);
153};
154
155#include "InverterInterface.tpp"
156#endif /* INVERTERINTERFACE */
void receive_temp_msg(CAN_message_t &msg)
void command_no_torque()
void handle_command(const InverterCommand &command)
void request_enable_inverter()
void request_enable_hv()
uint16_t get_error_status()
void receive_energy_msg(CAN_message_t &msg)
MC_setpoints_command curr_cmd_
void receive_status_msg(CAN_message_t &msg)
int16_t get_commanded_torque()
MC_setpoints_command get_cmd_msg()
message_queue * msg_queue_
void write_cmd_msg_to_queue_(MC_setpoints_command msg)
InverterInterface(message_queue *msg_output_queue, uint32_t can_id)
CAN_message_t msg