Skip to content

Commit

Permalink
Merge pull request #16 from hytech-racing/inverter_error_checking
Browse files Browse the repository at this point in the history
Inverter error checking. Fixed Include paths (TM).
  • Loading branch information
walkermburns committed Feb 5, 2024
2 parents d7231a4 + 22039e0 commit eb7a23b
Show file tree
Hide file tree
Showing 13 changed files with 1,652 additions and 25 deletions.
7 changes: 6 additions & 1 deletion lib/interfaces/include/InverterInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ class InverterInterface
void request_enable_inverter();
void command_no_torque();
void handle_command(const InverterCommand &command);
void command_reset();


bool inverter_system_ready()
{
return system_ready_;
}

bool error()
{
return error_;
}
bool dc_quit_on()
{
return quit_dc_on_;
Expand All @@ -63,6 +67,7 @@ class InverterInterface
void write_cmd_msg_to_queue_(const MC_setpoints_command &msg);
int16_t speed_;
uint16_t dc_bus_voltage_;
bool error_;
bool quit_dc_on_;
bool quit_inverter_on_;
bool system_ready_;
Expand Down
20 changes: 14 additions & 6 deletions lib/interfaces/include/InverterInterface.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@ template <typename message_queue>
void InverterInterface<message_queue>::request_enable_hv()
{

MC_setpoints_command mc_setpoints_command;
MC_setpoints_command mc_setpoints_command{};
mc_setpoints_command.set_hv_enable(true);
write_cmd_msg_to_queue_(mc_setpoints_command);
}

template <typename message_queue>
void InverterInterface<message_queue>::request_enable_inverter()
{
MC_setpoints_command mc_setpoints_command;
MC_setpoints_command mc_setpoints_command{};
mc_setpoints_command.set_speed_setpoint(0);
mc_setpoints_command.set_pos_torque_limit(0);
mc_setpoints_command.set_neg_torque_limit(0);
mc_setpoints_command.set_driver_enable(true);
mc_setpoints_command.set_inverter_enable(true);

write_cmd_msg_to_queue_(mc_setpoints_command);
}

template <typename message_queue>
void InverterInterface<message_queue>::command_no_torque()
{
MC_setpoints_command mc_setpoints_command;
MC_setpoints_command mc_setpoints_command{};
mc_setpoints_command.set_speed_setpoint(0);
mc_setpoints_command.set_pos_torque_limit(0);
mc_setpoints_command.set_neg_torque_limit(0);
Expand All @@ -48,7 +47,7 @@ void InverterInterface<message_queue>::command_no_torque()
template <typename message_queue>
void InverterInterface<message_queue>::handle_command(const InverterCommand &command)
{
MC_setpoints_command mc_setpoints_command;
MC_setpoints_command mc_setpoints_command{};
// TODO handle the correct conversion to the over the wire data from real-world data type
mc_setpoints_command.set_speed_setpoint(command.speed_setpoint_rpm);

Expand All @@ -65,15 +64,24 @@ void InverterInterface<message_queue>::handle_command(const InverterCommand &com
write_cmd_msg_to_queue_(mc_setpoints_command);
}


template <typename message_queue>
void InverterInterface<message_queue>::command_reset()
{
MC_setpoints_command mc_setpoints_command{};
mc_setpoints_command.set_remove_error(true);
write_cmd_msg_to_queue_(mc_setpoints_command);
}

template <typename message_queue>
void InverterInterface<message_queue>::receive_status_msg(CAN_message_t &msg)
{
MC_status mc_status(&msg.buf[0]);

system_ready_ = mc_status.get_system_ready();
quit_dc_on_ = mc_status.get_quit_dc_on();
quit_inverter_on_ = mc_status.get_quit_inverter_on();
speed_ = mc_status.get_speed();
error_ = mc_status.get_error();
}

// TODO fill this in with the correct receiving
Expand Down
1 change: 0 additions & 1 deletion lib/interfaces/include/SteeringEncoderInterface.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef __UPPERSTEERINGSENSOR_H__
#define __UPPERSTEERINGSENSOR_H__

#include "AnalogSensorsInterface.h"
#include <tuple>

enum SteeringEncoderStatus_e
Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/include/WatchdogInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "HyTech_CAN.h"
#include "SysClock.h"

const unsigned long WATCHDOG_KICK_INTERVAL = 7 // milliseconds
const unsigned long WATCHDOG_KICK_INTERVAL = 7; // milliseconds

class WatchdogInterface
{
Expand Down
7 changes: 7 additions & 0 deletions lib/interfaces/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "interfaces-lib",
"version": "1.0.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*"
}
3 changes: 2 additions & 1 deletion lib/interfaces/src/DashboardInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ bool DashboardInterface::safetySystemOK() {return _data.ssok;}
bool DashboardInterface::shutdownHAboveThreshold() {return _data.shutdown;}

void DashboardInterface::soundBuzzer(bool state) {_data.buzzer_cmd = state;}
bool DashboardInterface::checkBuzzer() {return _data.buzzer_state;}
bool DashboardInterface::checkBuzzer() {return _data.buzzer_state;}

5 changes: 2 additions & 3 deletions lib/systems/include/DrivetrainSystem.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#ifndef DRIVETRAINSYSTEM
#define DRIVETRAINSYSTEM

#include "InverterSystem.h"
#include "InverterInterface.h"
#include "Utility.h"
#include <array>

#include "stdint.h"
struct DrivetrainCommand_s
{
float speeds[NUM_MOTORS];
Expand Down Expand Up @@ -58,6 +56,7 @@ class DrivetrainSystem
bool hv_over_threshold_on_drivetrain();
void disable();
bool drivetrain_error_occured();
void reset_drivetrain();

void command_drivetrain(const DrivetrainCommand_s& data);
private:
Expand Down
34 changes: 28 additions & 6 deletions lib/systems/include/DrivetrainSystem.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,35 @@ void DrivetrainSystem<InverterType>::command_drivetrain_no_torque()
}

template <typename InverterType>
void DrivetrainSystem<InverterType>::command_drivetrain(const DrivetrainCommand& data)
bool DrivetrainSystem<InverterType>::drivetrain_error_occured()
{
for (auto inv_pointer : inverters_)
{
if(inv_pointer->error())
{
return true;
}
}
return false;
}

inverters_[0]->handle_command(data.left_front_inverter_cmd);
inverters_[1]->handle_command(data.right_front_inverter_cmd);
inverters_[2]->handle_command(data.left_rear_inverter_cmd);
inverters_[3]->handle_command(data.right_rear_inverter_cmd);
template <typename InverterType>
void DrivetrainSystem<InverterType>::reset_drivetrain()
{
for (auto inv_pointer : inverters_)
{
inv_pointer->command_reset();
}
}

template <typename InverterType>
void DrivetrainSystem<InverterType>::command_drivetrain(const DrivetrainCommand_s& data)
{

// inverters_[0]->handle_command(data.left_front_inverter_cmd);
// inverters_[1]->handle_command(data.right_front_inverter_cmd);
// inverters_[2]->handle_command(data.left_rear_inverter_cmd);
// inverters_[3]->handle_command(data.right_rear_inverter_cmd);

}

Expand Down Expand Up @@ -96,4 +118,4 @@ bool DrivetrainSystem<InverterType>::drivetrain_enabled()
}
}
return true;
}
}
8 changes: 4 additions & 4 deletions lib/systems/include/TorqueControllerMux.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define __TORQUECTRLMUX_H__

#include <unordered_map>
#include <TorqueControllers.h>
#include <DrivetrainSystem.h>
#include <PedalsSystem.h>
#include <SteeringSystem.h>
#include "TorqueControllers.h"
#include "DrivetrainSystem.h"
#include "PedalsSystem.h"
#include "SteeringSystem.h'
#include "DashboardInterface.h"
#include "AnalogSensorsInterface.h"
Expand Down
10 changes: 10 additions & 0 deletions lib/systems/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "systems-lib",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"interfaces-lib": "*"
},
"frameworks": "*",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion lib/systems/src/SteeringSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <SteeringSystem.h>
#include "SteeringSystem.h"

void SteeringSystem::tick(const SysTick_s &tick, const AnalogConversion_s &secondaryConversion)
{
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build_src_filter =
; refactoring
build_src_filter =
-<**/*.cpp>
+<main.cpp>
+<old_main.cpp>
build_unflags = -std=gnu++11
build_flags = -std=c++17
platform = teensy
Expand Down
Loading

0 comments on commit eb7a23b

Please sign in to comment.