MCU
Loading...
Searching...
No Matches
DrivetrainSystem.h
Go to the documentation of this file.
1#ifndef DRIVETRAINSYSTEM
2#define DRIVETRAINSYSTEM
3
4#include "Utility.h"
5#include <array>
6#include "stdint.h"
7#include "SysClock.h"
8#include "MCUInterface.h"
9#include "SharedDataTypes.h"
10
11
12template <typename InverterType>
14{
15public:
18 DrivetrainSystem(const std::array<InverterType *, 4> &inverters, MCUInterface *mcu_interface, int init_time_limit_ms, uint16_t min_hv_voltage = 60, int min_cmd_period_ms = 1, float max_torque_setpoint_nm = 21.42)
19 : inverters_(inverters), init_time_limit_ms_(init_time_limit_ms), min_hv_voltage_(min_hv_voltage), min_cmd_period_(min_cmd_period_ms), max_torque_setpoint_nm_(max_torque_setpoint_nm)
20 {
21 // values from: https://www.amk-motion.com/amk-dokucd/dokucd/en/content/resources/pdf-dateien/fse/motor_data_sheet_a2370dd_dd5.pdf
24 hv_en_requested_ = false;
25 enable_requested_ = false;
26 reset_requested_ = false;
28 reset_interval_ = 5000; // ms
33 last_general_cmd_time_ = 0; // ms
34 mcu_interface_ = mcu_interface;
35 dynamic_data_ = {};
36 }
37 void tick(const SysTick_s &tick);
38
40 {
42 hv_en_requested_ = false;
43 enable_requested_ = false;
44 }
45
46 bool handle_inverter_startup(unsigned long curr_time);
47 // on entry logic
50 // check to see if init time limit has passed
51 bool inverter_init_timeout(unsigned long curr_time);
52
54 void disable();
59
62
64
65private:
66 std::array<InverterType *, 4> inverters_;
72 // startup statuses:
74 // reset inverters
77 unsigned long reset_interval_;
79 void enable_drivetrain_hv_(unsigned long curr_time);
81 // startup phase 1
82 // status check for start of enable
84 // startup phase 2
86
87 // final check for drivetrain initialization to check if quit inverter on
89
90 unsigned long curr_system_millis_;
91 unsigned int min_cmd_period_;
93
98};
99
100#include "DrivetrainSystem.tpp"
101#endif /* DRIVETRAINSYSTEM */
MCUInterface * mcu_interface_
void enable_drivetrain_hv_(unsigned long curr_time)
unsigned long last_disable_cmd_time_
unsigned long drivetrain_initialization_phase_start_time_
DrivetrainDynamicReport_s dynamic_data_
unsigned long last_reset_cmd_time_
bool handle_inverter_startup(unsigned long curr_time)
float lambda_magnetic_flux_wb_
void enable_drivetrain_reset()
bool drivetrain_error_occured()
uint16_t min_hv_voltage_
void command_drivetrain_debug()
void command_drivetrain(const DrivetrainCommand_s &data)
bool check_drivetrain_quit_dc_on_()
unsigned long last_general_cmd_time_
DrivetrainSystem(const std::array< InverterType *, 4 > &inverters, MCUInterface *mcu_interface, int init_time_limit_ms, uint16_t min_hv_voltage=60, int min_cmd_period_ms=1, float max_torque_setpoint_nm=21.42)
order of array: 0: FL, 1: FR, 2: RL, 3: RR
std::array< InverterType *, 4 > inverters_
bool inverter_init_timeout(unsigned long curr_time)
void tick(const SysTick_s &tick)
unsigned long last_reset_pressed_time_
bool drivetrain_enabled_()
void command_drivetrain_no_torque()
bool drivetrain_ready_()
unsigned long reset_interval_
unsigned long curr_system_millis_
DrivetrainDynamicReport_s get_dynamic_data()
unsigned long last_no_torque_cmd_time_
void check_reset_condition()
bool hv_over_threshold_on_drivetrain()
void disable_no_pins()
DrivetrainCommand_s current_drivetrain_command_
unsigned int min_cmd_period_
void request_enable_()
void reset_drivetrain()
Stores setpoints for a command to the Drivetrain, containing speed and torque setpoints for each moto...