Skip to main content

How to use the Slack Energy algorithm ?

Posted in

First of all, it is necessary to install the Arm-toolchain compiler to rebuild the firmware after changes. Take a look at the tutorial page to know how to install such a compiler.


LeJosRT now has a Slack Energy algorithm. The purpose of this algorithm is to avoid the lack of energy in the battery by interrupting, if it's possible, EnergyRealtimeThreads in order to allow the battery to recharge it.

Currently only MASS works whith this algorithm. To activate it, go to /lejosRT/lejos_rt/src/nxtvm/javavm/configure.h.
At the end of this file, you should find :

  1. /**
  2. * Slack Stealer : none (0), DASS (1), MASS (2)
  3. */
  4. #define SlackStealer 0
  5.  
  6.  
  7. /**
  8. * Energy parameters
  9. */
  10. #define SlackEnergy 0 /* 1 to enable SlackEnergy, 0 to disable it */
  11. #define Emin 20 /* Minimum Level of Energy for battery */
  12. #define Emax 50000 /* Maximum Level of energy for battery */
  13. #define Estart 1100 /*Level of energy when system starts */

Set "SlackStealer" to 2 and "SlackEnergy" to 1 and save the file.

The parameters of the "virtual" battery must also be configured in this file by changing with your own parameters the following variables :

  • Emin
  • Emax
  • Estart

Then save the file.

In order to simulate an external input of energy (like solar panels), go to /lejosRT/lejos_rt/src/nxtvm/javavm/energy.c and modify

  1. int coeff = 1 ; /*linear coefficient for the increase in battery*/

with the value of your choice.
For the moment, only a linear increase in energy is simulated. Then, save the file.

Of course, you must use EnergyRealtimeThreads with this scheduler in order to use EnergyParameters.
Here is an example:

  1. EnergyRealtimeThread t1 = new EnergyRealtimeThread(new PriorityParameters(25),new PeriodicParameters(
  2. new RelativeTime(1000,0),
  3. new RelativeTime(5000,0),
  4. new RelativeTime(2000,0),
  5. new RelativeTime(2000,0), null, null),null,null,new EnergyParameters(3000)){
  6.  
  7. public void run() {
  8. do{
  9. //.....
  10. }while(waitForNextPeriod());
  11. }
  12. };

After making your changes, open a new session in a terminal and go to the folder /lejosRT/lejos_rt/install.
If the java classes were changed, tape and execute :

  1. ./install_lib.sh

Then, make sure your NXT is attached to the PC by its USB cable, and switch it on by pressing the orange button.
Tape and execute :

  1. ./flashfw.sh

The modifications are uploaded on the robot.