Hi all! I'm new to C in general but I have a very specific question: How can I read out the battery status and make my NXT's actions dependent from it? I would like it to go charge itself when batery is low. THX for your help.

CranoBot

Wed Mar 07, 2007 6:59 pm

Jesspepette

Rookie

Joined: Wed Mar 07, 2007 5:07 pmPosts: 3

Hi
you should find many interesting things there in the RobotC Software Help:

Battery & Power ControlThe 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.

alive()

Calling this function resets the “inactive power down” timer.

If a application program is running and it periodically calls the ‘alive()’ function, then this will prevent the NXT from auto power off.

powerOff()

This function call will immediately turn off the NXT

bNoPowerDownOnACAdaptor

A Boolean flag that, when set, indicates the NXT should not automatically power off when powered by an AC adaptor.

bNxtRechargable

A Boolean flag that indicates whether the NXT is powered from a LEGO rechargeable battery. There is a hidden switch inside the NXT battery compartment that is depressed when a LEGO rechargeable battery is used. This variable reads the value of this switch.

nAvgBatteryLevel

The average of several recent samples of the battery voltage. A value of 7500 indicates a voltage of 7.5 volts.

nImmediateBatteryLevel

The most recent sampled value of the battery voltage.

nPowerDownDelayMinutes

The number of minutes of inactivity that will trigger automatic power off of the NXT.

nShutdownVoltage

The low voltage value that will trigger automatic shutdown of the NXT. A value of 6100 indicates a shut down at 6.1V.

And this sample program should help:

Code:

///////////////////////////////////////////////////////////////////////////////////////////////// NXT Battery Level Access//// Test program to:// 1. Read the NXT battery levels and display on LCD.// 2. Ue the battery level in a user program to make a decision on program flow.//// Two RobotC intrinisc variables are available:// nAvgBatteryLevel// nImmediateBatteryLevel//// Some sensors and other devices require///////////////////////////////////////////////////////////////////////////////////////////////

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum