Skip to main content

Use of LeJosRT

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.

How to use Slack Stealer?

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 two Slack Stealer algorithms : Dynamic Approximate Slack Stealer (DASS) and Minimal Approximate Slack Stealer (MASS).

The purpose of these two algorithms is to obtain the laxity of the processor continously.

To activate one of these algorithms, 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

As stated,

  • to activate DASS , set SlackStealer to 1,
  • to activate MASS , set SlackStealer to 2,
  • to desactivate these algorithms , set SlackStealer to 0.

Then, save the file.

If you want to modify the virtual machine by using the laxity, you must use the function "instant_laxity()" defined in the file realtime_threads.c.
This function returns the instant laxity.

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.

How to modify the virtual machine?

Posted in

Having modified the virtual machine, it is necessary to reconstruct the firmware before to upload it on the robot.
For that purpose, it is necessary to install an Arm Toolchain compiler. Refer to tutorials.

Start a session and take place in the directory "/lejosRT/lejos_rt/install".

Make sure your NXT is attached to the PC by its USB cable, and switch it on by pressing the orange button.

If the classes were modified, execute "./install_lib.sh".
Then execute "./flashfw.sh".

The modifications are then uploaded on the robot.

How to use Real-Time ?

Posted in

You need to include the lejos.realtime.* package in your program.

You can also include others packages to allow any of the standard lejos classes to be used in the program.

For example :

  1. import lejos.charset.*;
  2. import lejos.nxt.LCD;
  3. import lejos.nxt.comm.*;
  4. import lejos.io.*;
  5. import lejos.realtime.*;
  6. import lejos.util.*;
  7. import lejos.nxt.*;
  8. import java.lang.*;

Here is an example to create a RealTimeThread :

  1. RealtimeThread t2 = new RealtimeThread(new PriorityParameters(19),new PeriodicParameters(
  2. new RelativeTime(0,0), //start
  3. new RelativeTime(3000,0), // period
  4. new RelativeTime(2000,0), // cost
  5. new RelativeTime(3000,0), null, null)) { // deadline
  6.  
  7. public void run() {
  8. do{
  9.  
  10. }while(waitForNextPeriod());
  11. }
  12. };

Take a look to the API for more details.

Syndicate content