Class PowerLimiter
Defined in File power_limiter.hpp
Class Documentation
-
class PowerLimiter
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
andrightWheel
DjiMotor
objects declared as well as aPowerLimiter
instance calledpowerLimiter
. 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.
Public Functions
-
PowerLimiter(const tap::Drivers *drivers, tap::communication::sensors::current::CurrentSensorInterface *currentSensor, float startingEnergyBuffer, float energyBufferLimitThreshold, float energyBufferCritThreshold)
Constructs a power limiter helper object.
- Parameters:
drivers – [in] Global drivers object.
currentSensor – [in]
CurrentSensorInterface
that will be used when power limiting. The current sensor should be connected in parallel with the main chassis power line.energyBufferLimitThreshold – [in] Energy in Joules. The amount of energy left in the energy buffer before power limiting is applied.
energyBufferCritThreshold – [in] Energy 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.
-
float 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.
Note
Tested with a normal four-wheel mecanum chassis and a two-wheel sentry chassis.
-
PowerLimiter(const tap::Drivers *drivers, tap::communication::sensors::current::CurrentSensorInterface *currentSensor, float startingEnergyBuffer, float energyBufferLimitThreshold, float energyBufferCritThreshold)