Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tap::control::chassis::PowerLimiter Class Reference

#include <power_limiter.hpp>

Public Member Functions

 PowerLimiter (const tap::Drivers *drivers, tap::communication::sensors::current::CurrentSensorInterface *currentSensor, tap::communication::sensors::voltage::VoltageSensorInterface *voltageSensor, float startingEnergyBuffer, float energyBufferLimitThreshold, float energyBufferCritThreshold)
 
float getPowerLimitRatio ()
 

Detailed Description

A utility to limit the power consumption of a chassis system according to its live current draw and available power buffer (from the referee system). Assumes the motors being used are M3508s and that the referee system is connected via UART.

This class currently requires the referee system connected via its default UART port and an object that implements the current sensor interface (specified upon construction). The following issues address improved versatility of this class:

This class will report a fraction between [0, 1] that you should then multiply your motors by after running a control loop and before sending to the motors.

Here is an example of how to use this class. This example assumes you have leftWheel and rightWheel DjiMotor objects declared as well as a PowerLimiter instance called powerLimiter. It is assumed you call this function repeatedly at the same rate that you run your chassis controller.

// ... run some chassis control algorithm ...
float powerLimitFrac = powerLimiter.getPowerLimitRatio();
leftWheel.setDesiredOutput(powerLimitFrac * leftWheel.getOutputDesired());
rightWheel.setDesiredOutput(powerLimitFrac * rightWheel.getOutputDesired());

If the referee system is not connected (valid data has not recently arrived), this class does nothing.

Constructor & Destructor Documentation

◆ PowerLimiter()

tap::control::chassis::PowerLimiter::PowerLimiter ( const tap::Drivers drivers,
tap::communication::sensors::current::CurrentSensorInterface currentSensor,
tap::communication::sensors::voltage::VoltageSensorInterface voltageSensor,
float  startingEnergyBuffer,
float  energyBufferLimitThreshold,
float  energyBufferCritThreshold 
)

Constructs a power limiter helper object.

Parameters
[in]driversGlobal drivers object.
[in]currentSensorCurrentSensorInterface that will be used when power limiting. The current sensor should be connected in parallel with the main chassis power line.
[in]energyBufferLimitThresholdEnergy in Joules. The amount of energy left in the energy buffer before power limiting is applied.
[in]energyBufferCritThresholdEnergy in Joules. If the amount of energy in the energy buffer is equal or less than this value, the power limiting fraction will be 0.

Member Function Documentation

◆ getPowerLimitRatio()

float tap::control::chassis::PowerLimiter::getPowerLimitRatio ( )

A function to be called repeatedly (in a subsystem's refresh function, for example). Checks the voltage through the referee system and the current using the current sensor to calculate current power consumption, which is used to update the energy buffer by integrating power. Once the energy buffer is known, it is used in conjunction with the constants passed in through the constructor to compute a fraction that can be used to perform power limiting.

Note
Must be called immediately after setpoints are configured. This function returns a value between [0, 1] that you should then multiply the desired output of your motors by. See class comment for more details.
Tested with a normal four-wheel mecanum chassis and a two-wheel sentry chassis.

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