MCU
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
TorqueControllerMux< num_controllers > Class Template Reference

#include <TorqueControllerMux.h>

Collaboration diagram for TorqueControllerMux< num_controllers >:
Collaboration graph

Public Member Functions

 TorqueControllerMux ()=delete
 
 TorqueControllerMux (std::array< Controller *, num_controllers > controller_pointers, std::array< bool, num_controllers > mux_bypass_limits, float max_change_speed=TC_MUX_DEFAULT_PARAMS::MAX_SPEED_FOR_MODE_CHANGE, float max_torque_pos_change_delta=TC_MUX_DEFAULT_PARAMS::MAX_TORQUE_DELTA_FOR_MODE_CHANGE, float max_power_limit=TC_MUX_DEFAULT_PARAMS::MAX_POWER_LIMIT)
 constructor for the TC mux More...
 
const TorqueControllerMuxStatusget_tc_mux_status ()
 
DrivetrainCommand_s getDrivetrainCommand (ControllerMode_e requested_controller_type, TorqueLimit_e controller_command_torque_limit, const SharedCarState_s &input_state)
 function that evaluates the mux, controllers and gets the active command More...
 

Private Member Functions

TorqueControllerMuxError can_switch_controller_ (DrivetrainDynamicReport_s active_drivetrain_data, DrivetrainCommand_s previous_controller_command, DrivetrainCommand_s desired_controller_out)
 
DrivetrainCommand_s apply_positive_speed_limit_ (const DrivetrainCommand_s &command)
 Clamps negative rpms to 0f. More...
 
DrivetrainCommand_s apply_torque_limit_ (const DrivetrainCommand_s &command, float max_torque)
 Ensure torque is at most at the specified limit. If exceeding, then limit it in the returned DrivetrainCommand_s. More...
 
DrivetrainCommand_s apply_power_limit_ (const DrivetrainCommand_s &command, const DrivetrainDynamicReport_s &drivetrain, float power_limit, float max_torque)
 Apply power limit (watts) such that the mechanical power of all wheels never exceeds the preset mechanical power limit. Scales all wheels down to preserve functionality of torque controllers. More...
 
DrivetrainCommand_s apply_regen_limit_ (const DrivetrainCommand_s &command, const DrivetrainDynamicReport_s &drivetrain_data)
 begin limiting regen at noRegenLimitKPH (hardcoded in func) and completely limit regen at fullRegenLimitKPH (hardcoded in func) More...
 

Private Attributes

std::array< Controller *, num_controllers > controller_pointers_
 
std::array< bool, num_controllers > mux_bypass_limits_
 
std::unordered_map< TorqueLimit_e, float > torque_limit_map_
 
float max_change_speed_
 
float max_torque_pos_change_delta_
 
float max_power_limit_
 
DrivetrainCommand_s prev_command_ = {}
 
TorqueControllerMuxStatus active_status_ = {}
 

Detailed Description

template<std::size_t num_controllers>
class TorqueControllerMux< num_controllers >

Definition at line 60 of file TorqueControllerMux.h.

Constructor & Destructor Documentation

◆ TorqueControllerMux() [1/2]

template<std::size_t num_controllers>
TorqueControllerMux< num_controllers >::TorqueControllerMux ( )
delete

◆ TorqueControllerMux() [2/2]

template<std::size_t num_controllers>
TorqueControllerMux< num_controllers >::TorqueControllerMux ( std::array< Controller *, num_controllers >  controller_pointers,
std::array< bool, num_controllers >  mux_bypass_limits,
float  max_change_speed = TC_MUX_DEFAULT_PARAMS::MAX_SPEED_FOR_MODE_CHANGE,
float  max_torque_pos_change_delta = TC_MUX_DEFAULT_PARAMS::MAX_TORQUE_DELTA_FOR_MODE_CHANGE,
float  max_power_limit = TC_MUX_DEFAULT_PARAMS::MAX_POWER_LIMIT 
)
inlineexplicit

constructor for the TC mux

Parameters
controller_pointersthe array of pointers to the controllers being muxed between
mux_bypass_limitsthe array of aligned bools for determining if the limits should be applied to the controller outputs defaults to TC_MUX_DEFAULT_PARAMS::MAX_SPEED_FOR_MODE_CHANGE
max_change_speedthe max speed difference between the requested controller output and the actual speed of each wheel that if the controller has a diff larger than the mux will not switch to the requested controller
max_torque_pos_change_deltasame as speed but evaluated between the controller commanded torques defaults to TC_MUX_DEFAULT_PARAMS::MAX_TORQUE_DELTA_FOR_MODE_CHANGE
max_power_limitthe max power limit defaults to TC_MUX_DEFAULT_PARAMS::MAX_POWER_LIMIT
Note
TC Mux must be created with at least 1 controller.

Definition at line 116 of file TorqueControllerMux.h.

120 : controller_pointers_(controller_pointers),
121 mux_bypass_limits_(mux_bypass_limits),
122 max_change_speed_(max_change_speed),
123 max_torque_pos_change_delta_(max_torque_pos_change_delta),
124 max_power_limit_(max_power_limit)
125
126
127 {
128 static_assert(num_controllers > 0, "Must create TC mux with at least 1 controller");
129
130 }
std::array< Controller *, num_controllers > controller_pointers_
std::array< bool, num_controllers > mux_bypass_limits_

Member Function Documentation

◆ apply_positive_speed_limit_()

template<std::size_t num_controllers>
DrivetrainCommand_s TorqueControllerMux< num_controllers >::apply_positive_speed_limit_ ( const DrivetrainCommand_s command)
private

Clamps negative rpms to 0f.

Parameters
constDrivetrainCommand_s &command provides the rpm info as a DrivetrainCommand_s
Returns
DrivetrainCommand_s to update the drivetrain command in the getDrivetrainCommand method

◆ apply_power_limit_()

template<std::size_t num_controllers>
DrivetrainCommand_s TorqueControllerMux< num_controllers >::apply_power_limit_ ( const DrivetrainCommand_s command,
const DrivetrainDynamicReport_s drivetrain,
float  power_limit,
float  max_torque 
)
private

Apply power limit (watts) such that the mechanical power of all wheels never exceeds the preset mechanical power limit. Scales all wheels down to preserve functionality of torque controllers.

Parameters
constDrivetrainCommand_s &command provides torque info, which is used to calculate mechanical power
constDrivetrainDynamicReport_s &drivetrain provides RPMS, which are used to calculate radians / s
floatmax_torque is used to indirectly specifiy the max power
Returns
DrivetrainCommand_s to update the drivetrain command in the getDrivetrainCommand method

◆ apply_regen_limit_()

template<std::size_t num_controllers>
DrivetrainCommand_s TorqueControllerMux< num_controllers >::apply_regen_limit_ ( const DrivetrainCommand_s command,
const DrivetrainDynamicReport_s drivetrain_data 
)
private

begin limiting regen at noRegenLimitKPH (hardcoded in func) and completely limit regen at fullRegenLimitKPH (hardcoded in func)

Parameters
constDrivetrainCommand_s &command
constDrivetrainDynamicReport_s &drivetrain_data provides RPMs
Returns
DrivetrainCommand_s to update the drivetrain command in the getDrivetrainCommand method

◆ apply_torque_limit_()

template<std::size_t num_controllers>
DrivetrainCommand_s TorqueControllerMux< num_controllers >::apply_torque_limit_ ( const DrivetrainCommand_s command,
float  max_torque 
)
private

Ensure torque is at most at the specified limit. If exceeding, then limit it in the returned DrivetrainCommand_s.

Parameters
constDrivetrainCommand_s &command is a DrivetrainCommand_s, which provides torque info
floatmax_torque this is the maximum average torque the wheels are allowed to experience before it is limited.
Returns
DrivetrainCommand_s to update the drivetrain command in the getDrivetrainCommand method

◆ can_switch_controller_()

template<std::size_t num_controllers>
TorqueControllerMuxError TorqueControllerMux< num_controllers >::can_switch_controller_ ( DrivetrainDynamicReport_s  active_drivetrain_data,
DrivetrainCommand_s  previous_controller_command,
DrivetrainCommand_s  desired_controller_out 
)
private

◆ get_tc_mux_status()

template<std::size_t num_controllers>
const TorqueControllerMuxStatus & TorqueControllerMux< num_controllers >::get_tc_mux_status ( )
inline

Definition at line 132 of file TorqueControllerMux.h.

132{ return active_status_; }
TorqueControllerMuxStatus active_status_

◆ getDrivetrainCommand()

template<std::size_t num_controllers>
DrivetrainCommand_s TorqueControllerMux< num_controllers >::getDrivetrainCommand ( ControllerMode_e  requested_controller_type,
TorqueLimit_e  controller_command_torque_limit,
const SharedCarState_s input_state 
)

function that evaluates the mux, controllers and gets the active command

Parameters
requested_controller_typethe requested controller type from the dial state
controller_command_torque_limitthe torque limit state enum set by dashboard
input_statethe active state of the car
Returns
the active DrivetrainCommand_s to be sent to the drivetrain to command increases and decreases in torque

Member Data Documentation

◆ active_status_

template<std::size_t num_controllers>
TorqueControllerMuxStatus TorqueControllerMux< num_controllers >::active_status_ = {}
private

Definition at line 77 of file TorqueControllerMux.h.

◆ controller_pointers_

template<std::size_t num_controllers>
std::array<Controller *, num_controllers> TorqueControllerMux< num_controllers >::controller_pointers_
private

Definition at line 67 of file TorqueControllerMux.h.

◆ max_change_speed_

template<std::size_t num_controllers>
float TorqueControllerMux< num_controllers >::max_change_speed_
private

Definition at line 75 of file TorqueControllerMux.h.

◆ max_power_limit_

template<std::size_t num_controllers>
float TorqueControllerMux< num_controllers >::max_power_limit_
private

Definition at line 75 of file TorqueControllerMux.h.

◆ max_torque_pos_change_delta_

template<std::size_t num_controllers>
float TorqueControllerMux< num_controllers >::max_torque_pos_change_delta_
private

Definition at line 75 of file TorqueControllerMux.h.

◆ mux_bypass_limits_

template<std::size_t num_controllers>
std::array<bool, num_controllers> TorqueControllerMux< num_controllers >::mux_bypass_limits_
private

Definition at line 69 of file TorqueControllerMux.h.

◆ prev_command_

template<std::size_t num_controllers>
DrivetrainCommand_s TorqueControllerMux< num_controllers >::prev_command_ = {}
private

Definition at line 76 of file TorqueControllerMux.h.

◆ torque_limit_map_

template<std::size_t num_controllers>
std::unordered_map<TorqueLimit_e, float> TorqueControllerMux< num_controllers >::torque_limit_map_
private
Initial value:
= {
{TorqueLimit_e::TCMUX_FULL_TORQUE, PhysicalParameters::AMK_MAX_TORQUE},
{TorqueLimit_e::TCMUX_MID_TORQUE, 15.0f},
{TorqueLimit_e::TCMUX_LOW_TORQUE, 10.0f}}
const float AMK_MAX_TORQUE

Definition at line 71 of file TorqueControllerMux.h.


The documentation for this class was generated from the following file: