Skip to content

Commit

Permalink
working on making build
Browse files Browse the repository at this point in the history
  • Loading branch information
RCMast3r committed Feb 5, 2024
2 parents fd0cb51 + eb7a23b commit ec59278
Show file tree
Hide file tree
Showing 65 changed files with 3,885 additions and 892 deletions.
27 changes: 27 additions & 0 deletions include/MCU_rev15_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef __MCU15_H__
#define __MCU15_H__

// pindefs
const int ADC1_CS = 34;
const int ADC2_CS = 33;
const int ADC3_CS = 29;
const HardwareSerial* STEERING_SERIAL = &Serial5;
const int SOFTWARE_OK = 28;
const int WATCHDOG_INPUT = 32;

// ADC1 channel defs
const int MCU15_ACCEL1_CHANNEL = 2;
const int MCU15_ACCEL2_CHANNEL = 1;
const int MCU15_BRAKE1_CHANNEL = 5;
const int MCU15_BRAKE2_CHANNEL = 3;
const int MCU15_GLV_SENSE_CHANNEL = 4;
const int MCU15_STEERING_CHANNEL = 7;
const int MCU15_CUR_POS_SENSE_CHANNEL = 6;
const int MCU15_CUR_NEG_SENSE_CHANNEL = 0;

// Time intervals
const unsigned long SETUP_PRESENT_ACTION_INTERVAL = 5000;
const unsigned long BUZZER_ON_INTERVAL = 2000;
const unsigned long INVERTER_ENABLING_TIMEOUT_INTERVAL = 5000;

#endif /* __MCU15_H__ */
79 changes: 71 additions & 8 deletions lib/interfaces/include/AMSInterface.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,76 @@
#ifndef AMSINTERFACE
#define AMSINTERFACE
#ifndef __AMS_INTERFACE_H__
#define __AMS_INTERFACE_H__

#include "FlexCAN_T4.h"
#include "HyTech_CAN.h"
#include "SysClock.h"

const unsigned long HEARTBEAT_INTERVAL = 20; // milliseconds
const unsigned long PACK_CHARGE_CRIT_TOTAL_THRESHOLD = 420;
const unsigned long PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD = 35000;

const float DEFAULT_INIT_TEMP = 40.0;
const float DEFAULT_INIT_VOLTAGE = 3.5;
const float DEFAULT_TEMP_ALPHA = 0.8;
const float DEFAULT_VOLTAGE_ALPHA = 0.8;

class AMSInterface
{
public:
AMSInterface() {}
bool ok_high();
bool heartbeat_check(unsigned long curr_time);
private:
public:
AMSInterface(int sw_ok_pin, float init_temp, float init_volt, float temp_alpha, float volt_alpha):
pin_software_ok_(sw_ok_pin),
filtered_max_cell_temp(init_temp),
filtered_min_cell_voltage(init_volt),
cell_temp_alpha(temp_alpha),
cell_voltage_alpha(volt_alpha) {};
AMSInterface(int sw_ok_pin):
AMSInterface(sw_ok_pin, DEFAULT_INIT_TEMP, DEFAULT_INIT_VOLTAGE, DEFAULT_TEMP_ALPHA, DEFAULT_VOLTAGE_ALPHA) {};

/* Initialize interface pin mode */
void init(const SysTick_s &tick);

/* Write to Main ECU */
// Initialize output value
void set_start_state();
// Set output value
void set_state_ok_high(bool ok_high);

/* Monitor AMS state */
void set_heartbeat(const SysTick_s &tick);
bool heartbeat_received(const SysTick_s &tick);
bool is_below_pack_charge_critical_low_thresh();
bool is_below_pack_charge_critical_total_thresh();
bool pack_charge_is_critical();

/* IIR filtered AMS readings */
float get_filtered_max_cell_temp();
float get_filtered_min_cell_voltage();

/* Retrieve CAN */
void retrieve_status_CAN(CAN_message_t &recvd_msg, const SysTick_s &tick);
void retrieve_temp_CAN(CAN_message_t &recvd_msg);
void retrieve_voltage_CAN(CAN_message_t &recvd_msg);

private:
/* AMS CAN messages */
// Outbound
BMS_status bms_status_;
BMS_temperatures bms_temperatures_;
BMS_voltages bms_voltages_;

/* AMS heartbeat check */
unsigned long last_heartbeat_time;

/* IIR filter parameters */
float bms_high_temp;
float bms_low_voltage;
float filtered_max_cell_temp;
float filtered_min_cell_voltage;
float cell_temp_alpha;
float cell_voltage_alpha;

/* Hardware interface pins */
int pin_software_ok_;
};

#endif /* AMSINTERFACE */
#endif /* __AMS_INTERFACE_H__ */
65 changes: 0 additions & 65 deletions lib/interfaces/include/AnalogSensor.h

This file was deleted.

5 changes: 0 additions & 5 deletions lib/interfaces/include/AnalogSensorInterface.h

This file was deleted.

98 changes: 98 additions & 0 deletions lib/interfaces/include/AnalogSensorsInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#ifndef __ANALOGSENSOR_H__
#define __ANALOGSENSOR_H__

#include <tuple>
#include <algorithm>
#include <SysClock.h>

enum AnalogSensorStatus_e
{
ANALOG_SENSOR_GOOD = 0,
ANALOG_SENSOR_CLAMPED = 1,
};

struct AnalogConversion_s
{
int raw;
float conversion;
AnalogSensorStatus_e status;
};

template <int N>
struct AnalogConversionPacket_s
{
AnalogConversion_s conversions[N];
};

class AnalogChannel
{
public:
// Data
float scale;
float offset;
bool clamp;
float clampLow;
float clampHigh;
int lastSample;

// Constructors
AnalogChannel(float scale_, float offset_, bool clamp_, float clampLow_, float clampHigh_)
: scale(scale_),
offset(offset_),
clamp(clamp_),
clampLow(clampLow_),
clampHigh(clampHigh_) {}
AnalogChannel(float scale_, float offset_)
: AnalogChannel(scale_, offset_, false, __FLT_MIN__, __FLT_MAX__) {}
AnalogChannel()
: AnalogChannel(1.0, 0.0, false, __FLT_MIN__, __FLT_MAX__) {}

// Functions
/// @brief Calculate sensor output and whether result is in sensor's defined bounds. DOES NOT SAMPLE.
/// @return Sensor's calculated output in real units, whether the result was clamped (AnalogSensorStatus_s)
AnalogConversion_s convert()
{
float conversion = lastSample * scale + offset;
float clampedConversion = std::min(std::max(conversion, clampLow), clampHigh);
AnalogSensorStatus_e returnStatus = ANALOG_SENSOR_GOOD;
if (clamp && (conversion > clampHigh || conversion < clampLow))
returnStatus = ANALOG_SENSOR_CLAMPED;
return {
lastSample,
clamp ? clampedConversion : conversion,
returnStatus
};
}
};

template <int N>
class AnalogMultiSensor
{
private:
public:
// Data
AnalogChannel channels[N];
AnalogConversionPacket_s<N> data;
// Functions
/// @brief Called by the main loop. Allows AnalogMultiSensor devices not owned by a single system to self-actualize sampling & conversion.
/// @param tick
void tick(const SysTick_s &tick);

/// @brief Used by systems to get data out of this device when it's self-actualizing sampling & conversion.
/// @return Const ref to last data conversion.
const AnalogConversionPacket_s<N>& get();

/// @brief Performs unit conversions on all channels
void convert()
{
for (int i = 0; i < N; i++)
{
data.conversions[i] = channels[i].convert();
}
}

/// @brief Commands the underlying device to sample all channels and internally store the results
void sample();
};

#endif /* __ANALOGSENSOR_H__ */
Loading

0 comments on commit ec59278

Please sign in to comment.