NXT Battery and Power Control

From ROBOTC API Guide
Jump to: navigation, search
NXTFunctions and Variables → Battery and Power Control


The NXT firmware keeps track of the minutes of inactivity on a NXT. When this exceeds a configurable limit, then the NXT will automatically power off. Inactivity is defined as time without a user keypress.

The inactivity timeout value can be set via the NXT GUI. It can also be set via editing ROBOTC property pages. Whenever ROBOTC makes a connection to a NXT it will set the timeout value to the value from the property page configuration.

Note that the NXT can behave unpredictably at low voltages and when trying to write to flash memory. So whenever ROBOTC attempts a connection between PC and NXT, it checks the battery voltage. If the voltage is too low for reliable operation, the ROBOTC connection will be aborted.


Color Key
Function:
Variable:


alive

void alive()
(void) Periodically calling this function will reset the timer used to put the controller to sleep after long periods of inactivity.
alive();  // reset the timer


powerOff

void powerOff()
(void) Immediately powers off the controller.
powerOff();  // power off the controller


bNoPowerDownOnACAdaptor

bool bNoPowerDownOnACAdaptor
(bool) A flag to tell the NXT not to power down if it is connected to an AC power source. True = will NOT power down, False = WILL power down.
bNoPowerDownOnACAdaptor = true;   // will NOT power down when connected to AC adapter
bNoPowerDownOnACAdaptor = false;  // WILL power down when connected to AC adapter


bNxtRechargable

bool bNxtRechargable
(bool) Boolean variable. Indicates whether the NXT is currently using a rechargable battery pack.
if(bNxtRechargable)
{
  // this code runs if evaluated as TRUE
}


LowVoltageBatteryCountLimits

int LowVoltageBatteryCountLimits
(int) The NXT will generate a "low voltage" pop up on the display when a specified amount of consecutive battery voltage samples are at a low voltage. Set this variable to the amount you wish, where 0 disabes the pop up entirely.
LowVoltageBatteryCountLimits = 10;  // notify me when 10 consecutive readings are low


nAvgBatteryLevel

int nAvgBatteryLevel
(int) The average battery level in millivolts. (A value of 9458 represent 9.458 volts.) It's the average of 20 recent samples and smoothes out sudden voltage transients.
int nBatteryAverage = nAvgBatteryLevel;  // create and set integer variable 'nBatteryAverage' 
                                         // to the average batter level of the device


nImmediateBatteryLevel

int nImmediateBatteryLevel
(int) The last sampled battery level in millivolts. (A value of 9458 represent 9.458 volts.)
int nBatteryLevel = nImmediateBatteryLevel;  // create and set integer variable 'nBatteryLevel'
                                             // to the immediate battery level


nPowerDownDelayMinutes

int nPowerDownDelayMinutes
(int) Specifies the number of minutes of inactivity (i.e. no buttons pressed) used by the sleep timer for automatic power off of controller. The controller automatically powers off to conserve battery power.
nPowerDownDelayMinutes = 15;  // power off after 15 minutes of inactivity


nPowerDownDelayMinutesDefault

int nPowerDownDelayMinutesDefault
(int) The default number of minutes of inactivity used by the sleep timer for automatic power off of controller.
nPowerDownDelayMinutes = nPowerDownDelayMinutesDefault;  // power off after the default amount
                                                         // of time has passed without any activity