Skip to content

Commit 8b40715

Browse files
committed
WIP
1 parent 76efd62 commit 8b40715

5 files changed

Lines changed: 30 additions & 4 deletions

File tree

Core/Inc/HVSCU/Communication/Ethernet.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "HVSCU/Actuators/Contactors.hpp"
4+
#include "HVSCU/Sensors/IMD.hpp"
45
#include "ST-LIB.hpp"
56

67
namespace HVSCU::Communication {
@@ -87,6 +88,9 @@ class Ethernet {
8788
double *average_current_v;
8889
double *average_current_w;
8990

91+
Sensors::IMD::State *imd_state;
92+
float *imd_isolation_resistance;
93+
9094
static void on_close_contactors() { has_received_close_contactors = true; }
9195

9296
static void on_open_contactors() { has_received_open_contactors = true; }
@@ -338,6 +342,8 @@ class Ethernet {
338342
HeapPacket bcu_current_sense_packet{1703, average_current_u,
339343
average_current_v, average_current_w};
340344

345+
HeapPacket imd_state_packet{1610, imd_isolation_resistance, imd_state};
346+
341347
public:
342348
Ethernet(float *total_supercaps_voltage,
343349
std::array<std::array<float *, 48>, 3> cells_voltage,
@@ -357,12 +363,14 @@ class Ethernet {
357363
float *average_dc_link_voltage, float *dc_link_voltage_1,
358364
float *dc_link_voltage_2, float *dc_link_voltage_3,
359365
float *dc_link_voltage_4, double *average_current_u,
360-
double *average_current_v, double *average_current_w);
366+
double *average_current_v, double *average_current_w,
367+
Sensors::IMD::State *imd_state, float *imd_isolation_resistance);
361368

362369
void send_supercaps_data();
363370
void send_sdc_data();
364371
void send_contactors_data();
365372
void send_current_sense();
373+
void send_imd_data();
366374
void send_bcu_data();
367375
bool is_connected();
368376
};

Core/Inc/HVSCU/Sensors/IMD.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class IMD {
3939
const State &get_state() const;
4040
const float &get_isolation_resistance() const;
4141

42+
State *get_state_pointer();
43+
float *get_isolation_resistance_pointer();
44+
4245
void update();
4346
};
4447

Core/Src/HVSCU/Board.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ Board::Board()
3737
&can.dc_link_voltage_1, &can.dc_link_voltage_2,
3838
&can.dc_link_voltage_3, &can.dc_link_voltage_4,
3939
&can.average_current_u, &can.average_current_v,
40-
&can.average_current_w) {
40+
&can.average_current_w, imd.get_state_pointer(),
41+
imd.get_isolation_resistance_pointer()) {
4142
initialize_state_machine();
4243

4344
can.start();
45+
imd.turn_on();
4446

4547
Time::register_low_precision_alarm(100, [&]() {
4648
ethernet.send_supercaps_data();
4749
ethernet.send_sdc_data();
4850
ethernet.send_contactors_data();
51+
ethernet.send_imd_data();
4952
});
5053

5154
Time::register_low_precision_alarm(1, [&]() { send_ethernet_1khz = true; });

Core/Src/HVSCU/Communication/Ethernet.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Ethernet::Ethernet(
1919
float *dc_link_voltage_1, float *dc_link_voltage_2,
2020
float *dc_link_voltage_3, float *dc_link_voltage_4,
2121
double *average_current_u, double *average_current_v,
22-
double *average_current_w)
22+
double *average_current_w, Sensors::IMD::State *imd_state,
23+
float *imd_isolation_resistance)
2324
: control_station_tcp(local_ip, tcp_server_port),
2425
control_station_udp(local_ip, udp_port, control_station_ip, udp_port),
2526
sdc_good(sdc_good),
@@ -48,7 +49,9 @@ Ethernet::Ethernet(
4849
dc_link_voltage_4(dc_link_voltage_4),
4950
average_current_u(average_current_u),
5051
average_current_v(average_current_v),
51-
average_current_w(average_current_w) {}
52+
average_current_w(average_current_w),
53+
imd_state(imd_state),
54+
imd_isolation_resistance(imd_isolation_resistance) {}
5255

5356
void Ethernet::send_supercaps_data() {
5457
control_station_udp.send_packet(total_voltage);
@@ -77,5 +80,10 @@ void Ethernet::send_bcu_data() {
7780
control_station_udp.send_packet(bcu_current_sense_packet);
7881
}
7982

83+
void Ethernet::send_imd_data() {
84+
control_station_udp.send_packet(imd_state_packet);
85+
}
86+
8087
bool Ethernet::is_connected() { return control_station_tcp.is_connected(); }
88+
8189
}; // namespace HVSCU::Communication

Core/Src/HVSCU/Sensors/IMD.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const float &IMD::get_isolation_resistance() const {
2929
return isolation_resistance;
3030
}
3131

32+
IMD::State *IMD::get_state_pointer() { return &state; }
33+
float *IMD::get_isolation_resistance_pointer() { return &isolation_resistance; }
34+
3235
#define Kohms(ohms) (ohms * 1000000.0f)
3336

3437
inline float duty_cycle_to_resistance(const float &duty_cycle) {
@@ -41,6 +44,7 @@ inline float duty_cycle_to_resistance(const float &duty_cycle) {
4144
}
4245

4346
void IMD::update() {
47+
output.read();
4448
if (output_frequency <= SHORTCIRCUIT_STATE_FREQ_THRESHOLD) {
4549
state = IMD::State::ShortCircuit;
4650
isolation_resistance = 0.0f;

0 commit comments

Comments
 (0)