Skip to content

Commit

Permalink
Fixed MCU and Telemetry interface compile issue
Browse files Browse the repository at this point in the history
  • Loading branch information
CL16gtgh committed Feb 6, 2024
1 parent d4e6f8e commit 33c0b3e
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 91 deletions.
4 changes: 4 additions & 0 deletions include/MCU_rev15_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ const unsigned long SETUP_PRESENT_ACTION_INTERVAL = 5000;
const unsigned long BUZZER_ON_INTERVAL = 2000;
const unsigned long INVERTER_ENABLING_TIMEOUT_INTERVAL = 5000;

// Communication speeds
const unsigned long INV_CAN_BAUDRATE = 500000;
const unsigned long TELEM_CAN_BAUDRATE = 500000;

#endif /* __MCU15_H__ */
5 changes: 4 additions & 1 deletion lib/interfaces/include/AnalogSensorsInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ class AnalogMultiSensor

/// @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();
const AnalogConversionPacket_s<N>& get()
{
return data;
}

/// @brief Performs unit conversions on all channels
void convert()
Expand Down
68 changes: 34 additions & 34 deletions lib/interfaces/include/MCUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include <stdint.h>
#include "FlexCAN_T4.h"
#include "HyTech_CAN.h"
#include "hytech.h"
// #include "hytech.h"
#include "MessageQueueDefine.h"
#include "SysClock.h"
#include "MCUStateMachine.h"
// #include "MCUStateMachine.h"

const int DEFAULT_BMS_OK_READ = 5; // SHDN_D_READ
const int DEFAULT_IMD_OK_READ = 4; // SHDN_C_READ
Expand Down Expand Up @@ -52,25 +53,24 @@ class MCUInterface
int pin_inv_24V_en_;

public:
MCUInterface(){};
// MCUInterface(message_queue *msg_output_queue, int bms_pin, int imd_pin, int bspd_pin, int sw_ok_pin, int bots_ok_pin, int brake_light_pin, int inv_pin, int inv_24V_pin):
// msg_queue_(msg_output_queue),
// pin_bms_ok_read_(bms_pin),
// pin_imd_ok_read_(imd_pin),
// pin_bspd_ok_read_(bspd_pin),
// pin_software_ok_read_(sw_ok_pin),
// pin_bots_ok_read_(bots_ok_pin),
// pin_brake_light_ctrl_(brake_light_pin),
// pin_inv_en_(inv_pin),
// pin_inv_24V_en_(inv_24V_pin)
// {
// // Set pin mode
// pinMode(pin_brake_light_ctrl_, OUTPUT);
// pinMode(pin_inv_en_, OUTPUT);
// pinMode(pin_inv_24V_en_, OUTPUT);
// };
// MCUInterface(message_queue *msg_output_queue):
// MCUInterface(msg_output_queue, DEFAULT_BMS_OK_READ, DEFAULT_IMD_OK_READ, DEFAULT_BSPD_OK_READ, DEFAULT_SOFTWARE_OK_READ, DEFAULT_BOTS_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL, DEFAULT_INVERTER_EN, DEFAULT_INVERTER_24V_EN) {};
MCUInterface(CANBufferType *msg_output_queue, int bms_pin, int imd_pin, int bspd_pin, int sw_ok_pin, int bots_ok_pin, int brake_light_pin, int inv_pin, int inv_24V_pin):
msg_queue_(msg_output_queue),
pin_bms_ok_read_(bms_pin),
pin_imd_ok_read_(imd_pin),
pin_bspd_ok_read_(bspd_pin),
pin_software_ok_read_(sw_ok_pin),
pin_bots_ok_read_(bots_ok_pin),
pin_brake_light_ctrl_(brake_light_pin),
pin_inv_en_(inv_pin),
pin_inv_24V_en_(inv_24V_pin)
{
// Set pin mode
pinMode(pin_brake_light_ctrl_, OUTPUT);
pinMode(pin_inv_en_, OUTPUT);
pinMode(pin_inv_24V_en_, OUTPUT);
};
MCUInterface(CANBufferType *msg_output_queue):
MCUInterface(msg_output_queue, DEFAULT_BMS_OK_READ, DEFAULT_IMD_OK_READ, DEFAULT_BSPD_OK_READ, DEFAULT_SOFTWARE_OK_READ, DEFAULT_BOTS_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL, DEFAULT_INVERTER_EN, DEFAULT_INVERTER_24V_EN) {};

/* Initialize shutdown circuit input readings */
void init();
Expand All @@ -88,7 +88,7 @@ class MCUInterface

/* Update MCU_status CAN (main loop) */
// State machine
void update_mcu_status_CAN_fsm(CAR_STATE fsm_state);
// void update_mcu_status_CAN_fsm(CAR_STATE fsm_state);
// Systems
void update_mcu_status_CAN_drivetrain(bool has_error);
void update_mcu_status_CAN_safety(bool is_ok);
Expand All @@ -100,20 +100,20 @@ class MCUInterface
void update_mcu_status_CAN_dashboard(bool is_pressed);

/* Enqueue MCU_status CAN */
void enqueue_CAN_mcu_status(CAN_message_t &msg);
void enqueue_CAN_mcu_status();

/* Tick SysClock to send CAN at 10Hz */
void tick(
const SysTick_s &tick,
CAR_STATE fsm_state,
bool inv_has_error,
bool software_is_ok,
// TCMux return
bool buzzer_is_on,
// Pedal system return
bool pack_charge_is_critical,
bool button_is_pressed
);
// void tick(
// const SysTick_s &tick,
// CAR_STATE fsm_state,
// bool inv_has_error,
// bool software_is_ok,
// // TCMux return
// bool buzzer_is_on,
// // Pedal system return
// bool pack_charge_is_critical,
// bool button_is_pressed
// );

};

Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/include/ORBIS_BR10.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const uint16_t ORBIS_BR10_BITMASK_DETAILED_DIST_FAR = (0b1 << 6);
const uint16_t ORBIS_BR10_BITMASK_DETAILED_DIST_NEAR = (0b1 << 7);
const uint16_t ORBIS_BR10_BITMASK_DETAILED = (ORBIS_BR10_BITMASK_DETAILED_COUNTER_ERROR | ORBIS_BR10_BITMASK_DETAILED_SPEED_HIGH | ORBIS_BR10_BITMASK_DETAILED_TEMP_RANGE | ORBIS_BR10_BITMASK_DETAILED_DIST_FAR | ORBIS_BR10_BITMASK_DETAILED_DIST_NEAR);

class OrbisBR10 : SteeringEncoderInterface
class OrbisBR10 : public SteeringEncoderInterface
{
private:
// Data
Expand Down
6 changes: 3 additions & 3 deletions lib/interfaces/include/SteeringEncoderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class SteeringEncoderInterface
public:
// Functions
/// @brief Commands the underlying steering sensor to sample and hold the result
void sample();
virtual void sample();
/// @brief Calculate steering angle and whether result is in sensor's defined bounds. DOES NOT SAMPLE.
/// @return Calculated steering angle in degrees, upperSteeringStatus_s
SteeringEncoderConversion_s convert();
virtual SteeringEncoderConversion_s convert();
/// @brief Set the upper steering sensor's offset. 0 degrees should be centered.
/// @param newOffset
void setOffset(float newOffset);
virtual void setOffset(float newOffset);
};

#endif /* __UPPERSTEERINGSENSOR_H__ */
15 changes: 8 additions & 7 deletions lib/interfaces/include/TelemetryInterface.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef __TELEMETRY_INTERFACE_H__
#define __TELEMETRY_INTERFACE_H__

#include "stdint.h"
#include "FlexCAN_T4.h"
#include "HyTech_CAN.h"
#include "hytech.h"
// #include "hytech.h"
#include "MessageQueueDefine.h"
#include "SysClock.h"
#include "AnalogSensorsInterface.h"
#include "SteeringEncoderInterface.h"
Expand All @@ -18,12 +20,11 @@ class TelemetryInterface
MCU_rear_potentiometers mcu_rear_potentiometers_;
MCU_analog_readings mcu_analog_readings_;
/* CAN Tx buffer */
// CANBufferType *msg_queue_;
CANBufferType *msg_queue_;

public:
TelemetryInterface(){};
// TelemetryInterface(message_queue *msg_output_queue):
// msg_queue_(msg_output_queue) {};
TelemetryInterface(CANBufferType *msg_output_queue):
msg_queue_(msg_output_queue) {};

/* Update CAN messages (main loop) */
// Interfaces
Expand Down Expand Up @@ -60,8 +61,8 @@ class TelemetryInterface
void tick(
const SysTick_s &tick,
const AnalogConversionPacket_s<8> &adc1,
const AnalogConversionPacket_s<4> &adc2,
const AnalogConversionPacket_s<4> &adc3,
const AnalogConversionPacket_s<8> &adc2,
const AnalogConversionPacket_s<8> &adc3,
const SteeringEncoderConversion_s &encoder
);

Expand Down
31 changes: 17 additions & 14 deletions lib/interfaces/src/MCUInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ bool MCUInterface::imd_ok_is_high() {

/* Send CAN message */
// MCU status
// void MCUInterface::enqueue_CAN_mcu_status() {
void MCUInterface::enqueue_CAN_mcu_status() {

// CAN_message_t msg;
// mcu_status_.write(msg.buf);
// msg.id = ID_MCU_STATUS;
// msg.len = sizeof(mcu_status_);
CAN_message_t msg;
mcu_status_.write(msg.buf);
msg.id = ID_MCU_STATUS;
msg.len = sizeof(mcu_status_);
uint8_t buf[sizeof(CAN_message_t)];
memmove(buf, &msg, sizeof(msg));

// msg_queue_->push_back(msg, sizeof(CAN_message_t));
// }
msg_queue_->push_back(buf, sizeof(CAN_message_t));
}

/* Update MCU_status CAN */
// MCUInterface
Expand All @@ -103,12 +105,12 @@ void MCUInterface::update_mcu_status_CAN() {

// Main loop
// State machine
void MCUInterface::update_mcu_status_CAN_fsm(CAR_STATE fsm_state) {
// State machine returns struct in main loop
// fsm.get_state()
// might not be compatible anymore, using new states
// mcu_status_.set_state(fsm_state);
}
// void MCUInterface::update_mcu_status_CAN_fsm(CAR_STATE fsm_state) {
// // State machine returns struct in main loop
// // fsm.get_state()
// // might not be compatible anymore, using new states
// // mcu_status_.set_state(fsm_state);
// }
//DriveTrain
void MCUInterface::update_mcu_status_CAN_drivetrain(bool has_error) {
// Drivetrain returns struct in main loop
Expand Down Expand Up @@ -138,7 +140,8 @@ void MCUInterface::update_mcu_status_CAN_TCMux() {
void MCUInterface::update_mcu_status_CAN_dashboard(bool is_pressed) {
// DashboardInterface (?) returns struct in main loop
// dash.lauchControlButtonPressed()
// mcu_status_.toggle_launch_ctrl_active(is_pressed);
if (is_pressed)
mcu_status_.toggle_launch_ctrl_active();
}
// BuzzerSystem
void MCUInterface::update_mcu_status_CAN_buzzer(bool is_on) {
Expand Down
24 changes: 17 additions & 7 deletions lib/interfaces/src/TelemetryInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ void TelemetryInterface::enqueue_CAN_mcu_pedal_readings() {
mcu_pedal_readings_.write(msg.buf);
msg.id = ID_MCU_PEDAL_READINGS;
msg.len = sizeof(mcu_pedal_readings_);
uint8_t buf[sizeof(CAN_message_t)];
memmove(buf, &msg, sizeof(msg));

// msg_queue_->push_back(msg, sizeof(CAN_message_t));
msg_queue_->push_back(buf, sizeof(CAN_message_t));
}
// Loadcell readings
void TelemetryInterface::enqueue_CAN_mcu_load_cells() {
Expand All @@ -18,8 +20,10 @@ void TelemetryInterface::enqueue_CAN_mcu_load_cells() {
mcu_load_cells_.write(msg.buf);
msg.id = ID_MCU_LOAD_CELLS;
msg.len = sizeof(mcu_load_cells_);
uint8_t buf[sizeof(CAN_message_t)];
memmove(buf, &msg, sizeof(msg));

// msg_queue_->push_back(msg, sizeof(CAN_message_t));
msg_queue_->push_back(buf, sizeof(CAN_message_t));
}
// Suspension potentiometers
// Front
Expand All @@ -29,8 +33,10 @@ void TelemetryInterface::enqueue_CAN_mcu_front_potentiometers() {
mcu_front_potentiometers_.write(msg.buf);
msg.id = ID_MCU_FRONT_POTS;
msg.len = sizeof(mcu_front_potentiometers_);
uint8_t buf[sizeof(CAN_message_t)];
memmove(buf, &msg, sizeof(msg));

// msg_queue_->push_back(msg, sizeof(CAN_message_t));
msg_queue_->push_back(buf, sizeof(CAN_message_t));
}
// Rear
void TelemetryInterface::enqueue_CAN_mcu_rear_potentiometers() {
Expand All @@ -39,8 +45,10 @@ void TelemetryInterface::enqueue_CAN_mcu_rear_potentiometers() {
mcu_rear_potentiometers_.write(msg.buf);
msg.id = ID_MCU_REAR_POTS;
msg.len = sizeof(mcu_rear_potentiometers_);
uint8_t buf[sizeof(CAN_message_t)];
memmove(buf, &msg, sizeof(msg));

// msg_queue_->push_back(msg, sizeof(CAN_message_t));
msg_queue_->push_back(buf, sizeof(CAN_message_t));
}
// Analog sensor readings
void TelemetryInterface::enqueue_CAN_mcu_analog_readings() {
Expand All @@ -49,8 +57,10 @@ void TelemetryInterface::enqueue_CAN_mcu_analog_readings() {
mcu_analog_readings_.write(msg.buf);
msg.id = ID_MCU_ANALOG_READINGS;
msg.len = sizeof(mcu_analog_readings_);
uint8_t buf[sizeof(CAN_message_t)];
memmove(buf, &msg, sizeof(msg));

// msg_queue_->push_back(msg, sizeof(CAN_message_t));
msg_queue_->push_back(buf, sizeof(CAN_message_t));
}

/* Update CAN messages */
Expand Down Expand Up @@ -102,8 +112,8 @@ void TelemetryInterface::update_analog_readings_CAN_msg(const SteeringEncoderCon
/* Tick SysClock */
void TelemetryInterface::tick(const SysTick_s &tick,
const AnalogConversionPacket_s<8> &adc1,
const AnalogConversionPacket_s<4> &adc2,
const AnalogConversionPacket_s<4> &adc3,
const AnalogConversionPacket_s<8> &adc2,
const AnalogConversionPacket_s<8> &adc3,
const SteeringEncoderConversion_s &encoder) {

if (tick.triggers.trigger50) {
Expand Down
4 changes: 2 additions & 2 deletions lib/systems/include/SteeringSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ struct SteeringSystemData_s
class SteeringSystem
{
private:
SteeringEncoderInterface& primarySensor_;
SteeringEncoderInterface *primarySensor_;
SteeringEncoderConversion_s primaryConversion_;
SteeringSystemData_s data_;
public:
SteeringSystem(SteeringEncoderInterface &primarySensor) : primarySensor_(primarySensor) {}
SteeringSystem(SteeringEncoderInterface *primarySensor) : primarySensor_(primarySensor) {}

/// @brief Computes steering angle and status of the steering system.
/// @param secondaryAngle The computed steering angle as reported by the secondary steering sensor.
Expand Down
4 changes: 2 additions & 2 deletions lib/systems/src/SteeringSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ void SteeringSystem::tick(const SysTick_s &tick, const AnalogConversion_s &secon
if (tick.triggers.trigger100)
{
// Poll upper steering sensor
primarySensor_.sample();
primaryConversion_ = primarySensor_.convert();
primarySensor_->sample();
primaryConversion_ = primarySensor_->convert();

// Compute internal state

Expand Down
Loading

0 comments on commit 33c0b3e

Please sign in to comment.