Create a program with JetStorm

JetStorm is highly coupled with phratch, because it is the main goal for my courses. But, it is possible to write a program with lines of code. And the number of possibilities are unlimited.

Let’s take a simple example: I want to draw a square on the Ev3 screen. To do that, I need three commands: clear the screen, draw the square and update the screen view. In phratch, the blocks looks like this:

It is simple. One thing that is important is that in JetStorm, each block is a command. In term of the Ev3 protocol, it means that for each block we build and send a message to the Mindstorm.

So, programmatically, you can do that by writing these lines:

|ev3 command|

ev3 := Ev3Vehicle newIp: '192.168.1.3' daisyChain: #EV3.

ev3 screen cleanUI.

ev3 screen drawRectangleColor: #Foreground x0: 10 y0: 20 width: 50 height: 50 filled: true.

ev3 screen updateUI.  

ev3 bridge disconnect.

For this case especially, but also for parametrization of sensors of motors, it is not efficient to send three commands. So, JetStorms includes the possibility to create “programs”, it means multiple commands in the same message.

It is not complicated, we just need to create a Command object that we complete with the atomic command we want to pass. Here is the same example, but sending only one command to the Mindstorm:

|ev3 command|

ev3 := Ev3Vehicle newIp: '192.168.1.3' daisyChain: #EV3.

command := Ev3Command newWithSequence: 1 reply: false.

ev3 screen buildCleanUIForCommand: command.
ev3 screen buildDrawRectangleColor: #Foreground x0: 10 y0: 20 width: 50 height: 50 filled: true forCommand: command.
ev3 screen buildUpdateUIForCommand: command. 

ev3 bridge send: command. 

ev3 bridge disconnect.

With this feature, we can build programs. Next steps is to save these programs inside the Mindstorms.

To access to the API, just go to the package EV3Bricks and browse the classes. In the JetStorm classes, you wil find methods with the patern name: build_XXXX_ForCommand: command. These methods are the interesting methods to build programs.