1 / 14

VisualStorms Tools

Università degli Studi di Pisa. VisualStorms Tools. Another Brick in the Robot. Introduction. Lego MindStorms allow building small robots based on the popular Lego bricks A programmable brick allows controlling up to three devices (motors) and test up to three input sensors

Download Presentation

VisualStorms Tools

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Università degli Studi di Pisa VisualStorms Tools Another Brick in the Robot . . . Antonio Cisternino & Diego Colombo

  2. Introduction • Lego MindStorms allow building small robots based on the popular Lego bricks • A programmable brick allows controlling up to three devices (motors) and test up to three input sensors • Programs are expressed in a bytecode interpreted by an interpreter in the brick’s ROM • The execution model is concurrent (up to ten threads) and there is a (very) small amount of memory representing the state of the execution Antonio Cisternino & Diego Colombo

  3. Programming the Brick • Lego provides a visual programming system to program the brick • Other tools have been developed to program MindStorms: a tiny JVM is being written (to replace the Lego VM), NQC is a C-Like language for programming the Brick • We have written a library to program MindStorms with .NET and Visual Studio • The library compiles Intermediate Language (IL) into Lego bytecode, in this way (almost) any .NET compiler can be used to program the Brick. Antonio Cisternino & Diego Colombo

  4. Compilation Scheme C# VB bcI File VisualStorms IL SML Brick Downloader . . . Antonio Cisternino & Diego Colombo

  5. Memory Organization • The compilation process should map a stack based machine into a register based machine • Class fields are mapped to global variables • Stack of a method is mapped to local variables starting from index 47 towards 32 • Local variables are mapped starting from 32 • Thus maxstack + #locals < 32 Global variables (0-31) Task 0 (Main) 32-47 Task 1 (32-47) V1 V2 .. . . Task 9 (32-47) sp . . . Stack 46 47 Antonio Cisternino & Diego Colombo

  6. Global variables are expressed as fields Inheritance to indicate the type of Brick Custom attribute to indicate tasks, subs and functions Inherited methods for I/O Compilation: an Example using System; namespace StormTestAdvanced { public class AracnoBrickTop : VisualStormsTypes.RCX2 { public int x; public int y; [FunctionType(Function.Task, 0)] public void main() { int i = Sensor2(); while(Sensor1() == 0) if (i != 0) SetMotorsPower(VisualStormsTypes.Motor.A, Sensor3()); else SetMotorsPower(VisualStormsTypes.Motor.C, Sensor3()); }}} Antonio Cisternino & Diego Colombo

  7. Compilation Example: IL SetVar : 20 32 9 1 0 IL_0000: ldarg.0 IL_0001: call instance int32 VisualStormsTypes.LegoBrick::Sensor2() IL_0006: stloc.0 IL_0007: br.s IL_0028 IL_0009: ldloc.0 IL_000a: brfalse.s IL_001b IL_000c: ldarg.0 IL_000d: ldc.i4.1 IL_000e: ldarg.0 IL_000f: call instance int32 VisualStormsTypes.LegoBrick::Sensor3() IL_0014: call instance void LegoBrick::SetMotorsPower(Motor, int32) IL_0019: br.s IL_0028 IL_001b: ldarg.0 IL_001c: ldc.i4.4 IL_001d: ldarg.0 IL_001e: call instance int32 VisualStormsTypes.LegoBrick::Sensor3() IL_0023: call instance void LegoBrick::SetMotorsPower(Motor, int32) IL_0028: ldarg.0 IL_0029: call instance int32 VisualStormsTypes.LegoBrick::Sensor1() IL_002e: brfalse.s IL_0009 IL_0030: ret LJump : 114 26 0 (26 f) SetVar : 20 47 0 32 0 LCheckDo : 149 192 2 47 0 0 9 0 (9 f) SetPower : 19 1 9 2 LJump : 114 6 0 (6 f) SetPower : 19 4 9 2 SetVar : 20 47 9 0 0 LCheckDo : 149 192 2 47 0 0 221 255 (35 b) Antonio Cisternino & Diego Colombo

  8. Compilation Example: Output SetVar : 20 32 9 1 0 LJump : 114 26 0 (26 f) SetVar : 20 47 0 32 0 LCheckDo : 149 192 2 47 0 0 9 0 (9 f) SetPower : 19 1 9 2 LJump : 114 6 0 (6 f) SetPower : 19 4 9 2 SetVar : 20 47 9 0 0 LCheckDo : 149 192 2 47 0 0 221 255 (35 b) Antonio Cisternino & Diego Colombo

  9. Compilation Example: NQC int x; int y; task main () { int i = SENSOR_2; while(SENSOR_1 == 0) { if (i != 0) { SetPower (OUT_A,SENSOR_3); } else { SetPower (OUT_C,SENSOR_3); } } } Antonio Cisternino & Diego Colombo

  10. Compilation Example: NQC’s output SetVar : 20 32 9 1 0 LJump : 114 26 0 (26 f) SetVar : 20 47 0 32 0 LCheckDo : 149 192 2 47 0 0 9 0 (9 f) SetPower : 19 1 9 2 LJump : 114 6 0 (6 f) SetPower : 19 4 9 2 SetVar : 20 47 9 0 0 LCheckDo : 149 192 2 47 0 0 221 255 (35 b) *** Var 0 = x *** Var 1 = y *** Var 47 = i *** Task 0 = main pwr ABC, 7 dir ABC, Fwd setv var[47], Input(1) jmpl 33 chkl 0 == var[47], 29 pwr A, Input(2) jmpl 33 pwr C, Input(2) chkl 0 == Input(0), 14 Antonio Cisternino & Diego Colombo

  11. Structure of the System VisualStudio User VisualStorms AddIn AssemblyLoader VisualStormsCompiler CliFileReader Reflection SharpStormsLib SharpSerial Antonio Cisternino & Diego Colombo

  12. Demo Antonio Cisternino & Diego Colombo

  13. Applications • Teaching: the ability of programming simple robots with real world languages allow a gentle introduction to programming • Use of Lego to prototype robots controlled by remote programs running on a full fledged PC and radio controlled • Application of extensible reflection provided by .NET • It is Possibile to implement emulators and debug programs in Visual Studio (or guidbg) for .NET Antonio Cisternino & Diego Colombo

  14. Conclusions and Future Work • IL is a rich binary format that can be exploited for purposes different than execution • The ability of compiling a subset of C# programs to the robot allows a neat environment for experimenting with easy-to-build robots • In the future the compiler will recognize call to external methods generating RPC code and distributing a computation between the robot and the PC automatically Antonio Cisternino & Diego Colombo

More Related