Skip to content

Commit

Permalink
Merge pull request #86 from hytech-racing/feature/tc_mux_simplification
Browse files Browse the repository at this point in the history
send it
  • Loading branch information
jhwang04 authored Sep 20, 2024
2 parents 17b934e + 2277f4c commit 2a9272e
Show file tree
Hide file tree
Showing 61 changed files with 2,077 additions and 2,722 deletions.
20 changes: 9 additions & 11 deletions include/MCU_rev15_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#define __MCU15_H__

#include "PedalsSystem.h"
#ifndef TESTING_SYSTEMS
#include "InterfaceParams.h"
#endif



// pindefs
Expand Down Expand Up @@ -54,17 +52,17 @@ const unsigned long TELEM_CAN_BAUDRATE = 500000;
// All of these values are the PEDAL min/max
// the sensor min/max that trip implaus are calculated
// in the PedalsSystem constructor
const int ACCEL1_PEDAL_MAX = 3409; // 3330
const int ACCEL2_PEDAL_MAX = 259; // 388
const int ACCEL1_PEDAL_MAX = 3491;
const int ACCEL2_PEDAL_MAX = 189;

const int ACCEL1_PEDAL_MIN = 2129;
const int ACCEL2_PEDAL_MIN = 1517;
const int ACCEL1_PEDAL_MIN = 2244;
const int ACCEL2_PEDAL_MIN = 1405;

const int BRAKE1_PEDAL_MAX = 1945; // 2200;
const int BRAKE2_PEDAL_MAX = 1742; // 2200;
const int BRAKE1_PEDAL_MAX = 1945;
const int BRAKE2_PEDAL_MAX = 1742;

const int BRAKE1_PEDAL_MIN = 1230; // 785; // 1230 to 1750
const int BRAKE2_PEDAL_MIN = 2437; // 785; // 2450 to 1930
const int BRAKE1_PEDAL_MIN = 1192;
const int BRAKE2_PEDAL_MIN = 2476;

const int ACCEL1_PEDAL_OOR_MIN = 90;
const int ACCEL2_PEDAL_OOR_MIN = 90;
Expand Down
44 changes: 44 additions & 0 deletions include/PrintLogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef __PRINTLOGGER_H__
#define __PRINTLOGGER_H__
#include <stddef.h>
#include <stdint.h>
#ifdef ARDUINO
#include <Arduino.h>
#else
#include <cstdarg>
#include <stdio.h>
#include <iostream>
#endif

#ifdef ARDUINO
template <typename T>
void logger_println(T out){
Serial.println(out);
}
#else
template <typename T>
void logger_println(T out){
std::cout << out<<std::endl;
}
#endif

class RateLimitedLogger
{
private:
unsigned long last_out_time_;
public:
RateLimitedLogger()
{
last_out_time_ = 0;
}

template <typename T>
void log_out(T out, unsigned long current_millis, unsigned long period=100) {
if((current_millis - last_out_time_) > period)
{
logger_println<T>(out);
last_out_time_ = current_millis;
}
}
};
#endif // __PRINTLOGGER_H__
47 changes: 13 additions & 34 deletions lib/interfaces/include/DashboardInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,9 @@
#include "hytech.h"
#include "MCUInterface.h"
#include "InverterInterface.h"
#include "SharedDataTypes.h"

#include "TorqueControllers.h"

/*
Enum for the car's torque limits
MOVE ME! - ideally into a TorqueControllerDefs.h file
to prevent circular dependencies
*/
enum class TorqueLimit_e
{
TCMUX_LOW_TORQUE = 0,
TCMUX_MID_TORQUE = 1,
TCMUX_FULL_TORQUE = 2,
TCMUX_NUM_TORQUE_LIMITS = 3,
};

/* Enum for the modes on the dial, corresponds directly to dial index pos. */
enum class DialMode_e
{
/* No torque vectoring */
MODE_0,
/* Normal force torque vectoring */
MODE_1,
/* PID torque vectoring */
MODE_2,
/* Launch Ctrl */
MODE_3,
MODE_4,
MODE_5,
};

/* Enum for defined LED colors. ON will be LED's default color on dashboard*/
enum class LEDColors_e
Expand Down Expand Up @@ -77,13 +50,15 @@ struct DashButtons_s
bool right_shifter;
};


/* Struct holding all data for the DashboardInterface (inputs and outputs) */
struct DashComponentInterface_s
{
/* READ DATA */
// enum for dial position read by controller mux
DialMode_e dial_mode;
DialMode_e cur_dial_mode;
ControllerMode_e dial_mode;
ControllerMode_e cur_dial_mode;
TorqueLimit_e torque_limit_mode;
// Buttons struct for better naming
DashButtons_s button;
bool ssok; // safety system OK (IMD?) RENAME
Expand Down Expand Up @@ -111,6 +86,8 @@ class DashboardInterface
CANBufferType *msg_queue_;
/* The instantiated data struct used to access data by member functions */
DashComponentInterface_s _data;
bool prev_button_pressed_state_;
void update_torque_mode_(bool button_pressed);

public:
/*!
Expand All @@ -121,6 +98,8 @@ class DashboardInterface
*/
DashboardInterface(CANBufferType *msg_output_queue)
{
_data.torque_limit_mode = TorqueLimit_e::TCMUX_FULL_TORQUE;
prev_button_pressed_state_ = false;
msg_queue_ = msg_output_queue;
};

Expand All @@ -145,14 +124,14 @@ class DashboardInterface
float min_cell_voltage,
AnalogConversion_s glv_voltage,
int launch_state,
DialMode_e dial_mode);
ControllerMode_e dial_mode);

/*!
getter for the dashboard's current dial position (drive profile)
@return returns a DialMode_e enum with the current dial position
@return returns a ControllerMode_e enum with the current dial position
*/
DialMode_e getDialMode();

ControllerMode_e getDialMode();
TorqueLimit_e getTorqueLimitMode();
/* gets whether the safety system is ok (wtf is a safety system - rename this)*/
bool safetySystemOK();

Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/include/HytechCANInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void process_ring_buffer(BufferType &rx_buffer, const InterfaceType &interfaces,
case VN_LAT_LON_CANID:
interfaces.vn_interface->retrieve_lat_lon_CAN(recvd_msg);
break;
case VN_GPS_TIME_CANID:
case VN_GPS_TIME_MSG_CANID:
interfaces.vn_interface->retrieve_gps_time_CAN(recvd_msg);
break;
case VN_STATUS_CANID:
Expand Down
7 changes: 1 addition & 6 deletions lib/interfaces/include/LoadCellInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Utility.h"
#include "SysClock.h"
#include "AnalogSensorsInterface.h"
#include "SharedDataTypes.h"

/* Structs */

Expand All @@ -15,12 +16,6 @@ struct LoadCellInterfaceTick_s
const AnalogConversion_s &RRConversion;
};

struct LoadCellInterfaceOutput_s
{
veh_vec<float> loadCellForcesFiltered;
veh_vec<AnalogConversion_s> loadCellConversions;
bool FIRSaturated;
};

class LoadCellInterface
{
Expand Down
5 changes: 2 additions & 3 deletions lib/interfaces/include/MCUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "hytech.h"
#include "MessageQueueDefine.h"
#include "PedalsSystem.h"
#include "SharedDataTypes.h"

const int DEFAULT_BMS_OK_READ = 17; // SHDN_D_READ
const int DEFAULT_BMS_SENSE_PIN = 16; // BMS_OK_SENSE
Expand Down Expand Up @@ -123,9 +124,7 @@ class MCUInterface
int fsm_state,
bool inv_has_error,
bool software_is_ok,
int drive_mode,
int torque_mode,
float max_torque,
const TorqueControllerMuxStatus& tc_mux_status,
bool buzzer_is_on,
const PedalsSystemData_s &pedals_data,
bool pack_charge_is_critical,
Expand Down
46 changes: 0 additions & 46 deletions lib/interfaces/include/ParameterInterface.h

This file was deleted.

29 changes: 8 additions & 21 deletions lib/interfaces/include/ProtobufMsgInterface.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#ifndef PROTOBUFMSGINTERFACE
#define PROTOBUFMSGINTERFACE

#include "ht_eth.pb.h"
#include "pb_encode.h"
#include "pb_decode.h"
#include "pb_common.h"
#include "ParameterInterface.h"
#include "circular_buffer.h"
#include "NativeEthernet.h"
#include "MCU_rev15_defs.h"

#include "InterfaceParams.h"

struct ETHInterfaces
{
ParameterInterface* param_interface;
};

using recv_function_t = void (*)(const uint8_t* buffer, size_t packet_size, ETHInterfaces& interfaces);
Expand Down Expand Up @@ -50,27 +47,17 @@ bool handle_ethernet_socket_send_pb(EthernetUDP* socket, const pb_struct& msg, c
return true;
}

//
void recv_pb_stream_union_msg(const uint8_t *buffer, size_t packet_size, ETHInterfaces& interfaces)

template <typename pb_msg_type>
std::pair<pb_msg_type, bool> recv_pb_stream_msg(const uint8_t *buffer, size_t packet_size, ETHInterfaces& interfaces, const pb_msgdesc_t * desc_pointer)
{
pb_istream_t stream = pb_istream_from_buffer(buffer, packet_size);
HT_ETH_Union msg = HT_ETH_Union_init_zero;
if (pb_decode(&stream, HT_ETH_Union_fields, &msg))
pb_msg_type msg = {};
if (pb_decode(&stream, desc_pointer, &msg))
{
Serial.println("decoded!");

switch (msg.which_type_union)
{
case HT_ETH_Union_config__tag:
interfaces.param_interface->update_config(msg.type_union.config_);
break;
case HT_ETH_Union_get_config__tag:
interfaces.param_interface->set_params_need_sending();
break;
default:
break;
}
return {msg, true};
}
return {msg, };
}


Expand Down
Loading

0 comments on commit 2a9272e

Please sign in to comment.