View unanswered posts | View active topics It is currently Wed Nov 26, 2014 10:32 am






Reply to topic  [ 3 posts ] 
Batery Status as Senor? 
Author Message
Rookie

Joined: Wed Mar 07, 2007 1:28 pm
Posts: 4
Location: Zürich Switzerland
Post Batery Status as Senor?
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
Profile
Rookie

Joined: Wed Mar 07, 2007 5:07 pm
Posts: 3
Post 
Hi
you should find many interesting things there in the RobotC Software Help:

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

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
//
/////////////////////////////////////////////////////////////////////////////////////////////



const int kMinimumBatteryLvel = 6300;

task main()
{
  int nCounter = 0;

  while (true)
  {
      if (nImmediateBatteryLevel < kMinimumBatteryLvel)
      {
         //
         // Battery level too low to proceeed.
         //
         PlaySound(soundLowBuzz);
         break;
      }
      nxtDisplayTextLine(0, "Battery Levels");

      //
      // Display the Battery levels
      //
      nxtDisplayTextLine(2, "Avg %3.1fV;Now %3.1f", nAvgBatteryLevel / (float) 1000, nImmediateBatteryLevel / (float) 1000);

     //
     // Display the voltage level at which the NXT will "shutdown"
     //
     nxtDisplayTextLine(4, "Shutdown at%4.1fV", nShutdownVoltage / (float) 1000);

     //
     // DIsplay the voltage level at which the NXT will "shutdown"
     //
     nxtDisplayTextLine(5, "Sleep Tmr: %d min", nPowerDownDelayMinutes);

     //
      // Display the Battery type: rechargeable or one-time only
      //
      if (bNxtRechargable)
         nxtDisplayTextLine(7, "Rechargable");
      else
        nxtDisplayTextLine(7, "Non-Rechargable");

     //
     // You can also immediately power off the NXT as follows:
     //
     wait1Msec(10);
     ++nCounter;
     if (nCounter > 15000)
       powerOff();
  }
  return;
}


Thu Mar 08, 2007 3:30 am
Profile
Rookie

Joined: Wed Mar 07, 2007 1:28 pm
Posts: 4
Location: Zürich Switzerland
Post 
THX a lot.


Thu Mar 08, 2007 5:13 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.