Runing Programs from the Menu

IMPORTANT: This method has been tested on a Lego EV3 with firmware 1.03H (check Brick Info). The EV3 comes with version 1.01 which does not support using the system command. Update the firmware before using this method

The Lego VM provides a function that can call the system command. This function allows running any command either from the operating system or user-created programs available in the microSD card. Using the lmsasm tool from the EV3 source code, I created a program that runs in the Lego Virtual Machine. Its only purpose is to execute a program located in the microSD card.

run_program

In the following video I chose the “Open Loop Control” program as example. The video shows this program running from a terminal, and after removing the WiFi dongle, directly from the EV3 brick menu.

The following links contain the compiled versions of the Lego-VM program and the motor control program. These files must be copied in the microSD card. The file “program” must be placed directly in the root directory of the microSD card and the “run_program.rbf” file inside a subdirectory “myapps”. I have been using this program to run all my demos when a WiFi network is not available or I can not (or don’t want to) have a computer. As far as I can tell, this program does not interfere with the LVM. In fact, it prevents that from happening, since the program will prevent the LVM to run any other application. It does not prevent user from running applications from a terminal though.

Source Code
This is the source code for the Lego-VM program. Notice that the executable file must be named “program”.

vmthread MAIN
{
DATA32 Timer
DATA32 Status

//Write a message
UI_DRAW(FILLWINDOW,BG_COLOR,0,0)
UI_DRAW(SELECT_FONT,LARGE_FONT)
UI_DRAW(TEXT,FG_COLOR,5,50,'RUNNING!')
UI_DRAW(UPDATE)

//This is the command that executes the program
SYSTEM('/media/card/program',Status)

//Wait before exiting
TIMER_WAIT(1000,Timer)
TIMER_READY(Timer)
}
7 Responses to Runing Programs from the Menu
  1. Christoph says:

    Hello!
    Thanks for the info. We tried running your “run_program.rbf” on a ev3, but are getting a ” VM PROGRAM VALIDATION” error and nothing happens.
    We copied “run_program.rbf ” into the myapps dir and “program” into the root of the SD card.
    We’re running the stock LEGO OS using Linux kernel 2.6.33 and firmware v1.01h.
    Can you offer any advice? Thanks in advance,
    Christoph

    • admin says:

      My current firmware version is 1.03H. The first time I used the EV3 with the provided windows program, it recommended upgrading it.

  2. Stephan orsholm says:

    I get the same problem: “VM PROGRAM VALIDATION”.

    I have tried recompiling the run_program.lms program above. If I leave out the call to SYSTEM, the program runs without validation errors but then it does not help much since the C program is not started.

    I conclude the problem is in the C program which cannot be validated. I don’t know why but will investigate.

    • admin says:

      Lego has a “DISABLE_SYSTEM_BYTECODE” flag that can disable the “system” call (see lms2012.h file). I am wondering if some EV3s had the firmware compiled with that definition enabled. Could check your firmware version? mine is 1.03H

      • Stephan Korsholm says:

        My firmware was 1.01H :-(

        I updated and now it works :-)

        I should have tried that before, so sorry for wasting your time.

        - Stephan

  3. MikoĊ‚aj Karawacki says:

    Hi, I found your blog/website while google-vestigating how to run C programs without telnet-ing to the brick. How exactly do you compile the source for Lego-VM wrapper/caller for your C program? This part got me buffled.