Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Mindstorms is a product family from Lego, with sensors, motors and a programmable brick. The newest iteration of the product family is the EV3 programmable brick. Its predecessors are NXT and RCX. In the following we will see how to develop applications for the NXT brick, thus Mindstorms will be used exchangeable with NXT brick.

Several open-source, third-party replacements for the offical Lego firmware have been developed. These support many well known programming languages, such as Java, C/C++, Python, Lua, etc. In the following we will use KIELER SCCharts to program Mindstorms running the Lego Java Operating System (leJOS). Therefore we will first install leJOS NXJ and flash its firmware. Afterwards we will create a simple SCCharts project in KIELER that we will compile and deploy to the NXT brick.

...

There is an Eclipse plugin for leJOS which adds a project creation wizard and launch configuration to the platform. You can have to install it via the Eclipse Marketplace (Help > Eclipse Marketplace...). If you have an NXT brick, install the leJOS NXJ Plug-in. If you have an EV3 brick, install the leJOS EV3 plugin.

After the installation, the plugin requires a little configuration. Go to Window > Preferences > leJOS NXJ and enter the base directory of your leJOS installation in the NXJ_HOME field.

Configure KIELER

With the Eclipse plugin for leJOS installed, you can now use KIELER SCCharts for an model-based approach of programming.

First check the environment settings for NXJ of the KIELER tool (For the EV3 plugin, the required dialog is under Window > Preferences > KIELER > Environments). On the Execute tab, ensure that only the commands for your operating system are checked.

Hit the Variables button and search for nxj.home. If the variable exists, your good. If it does not exist, ensure that you installed and configured the Ecplise plugin for leJOS NXJ correctly.

Image Removed

Note: If you already created and launched a project, the settings of the environment are copied to the launch configuration. It thus may be necessary to alter settings on the launch configuration as well as the environmentleJOS EV3. You have to set the leJOS installation directory. Furthermore the leJOS EV3 plugin requires the IP address to connect to the brick (it may work without, but its safer to directly set the name. Reduces headache (wink)). Check Connect to named brick and enter the IP adress of the brick (displayed on the brick at startup).

...

Creating an Example Project

...

  1. Choose File > New > Project > KIELER SCCharts > SCCharts Project
  2. In the project creation wizard that opens, select Mindstorms NXJ or Mindstorms EV3 (depending on your brick) as environment and hit finish
  3. The project wizard from the leJOS plugin opens. Set the project name to Flashlight and click finish.
  4. The project is created and the model file is opened in an editor (This might take a few seconds).

...

The annotations on the input and output variable are used to define which wrapper code is used to set / read them. @Wrapper TouchSensor, S4 will set the input variable to true iff the touch sensor on the port S4 is pressed. @Wrapper Floodlight, S1 on the output variable will turn on the red led of the light sensor that is attatched to port S1 iff the variable is true.

The available wrapper code snippets are defined in the snippets directory of the project in ftl files (FreeMarker template files). (To view ftl files with highlighting, you may want to install the FreeMarker IDE feature from the JBoss tools that is available in the Eclipse Market Place.)

Note: The Floodlight of the EV3 has a pretty high latency when switching between on and off.

Launch the project:

With the mouse over the SCT file in the project explorer, perform Right Click > Run As > KiCo Compilation.

A launch config is created, which compiles the model to Java code and creates wrapper code from the annotations in the model file. Afterwards this output is compiled and deployed to the Mindstorms brick, by using the shell commands that are defined in the Mindstorms NXJ environmentlaunch shortcut from the leJOS plugin. If any errors occur, you can see them in the Console View.

For a deeper understanding of the project launch and initialization, take a look at the wiki page for Prom.

...

Using the Remote Console (RConsole)

The display of the NXT brick is rather small compared to a Monitor. To ease debugging, one can print to a Remote Console (RConsole), if the USB cable is connected. This enables easier collection for example of sensor data.

To use the RConsole, uncomment the RConsole lines in the wrapper code template Main.ftl. Start the nxjconsoleviewer tool in the bin directory of your leJOS installation. Now, when starting the application, the brick tries to connect with the nxjconsoleviewer. Press the Connect button. If connected succesfully, RConsole.println(...) commands will be written to this window.

The EV3 brick has a similar feature. However it does not require any code changes. Just run the ev3console program in the bin directory of your leJOS installation from command line. The output of the brick will be printed to this command line.