Simulator#

Switching to the corresponding device automatically shows the simulator for microcomputers and the robotic simulator.

Currently supported devices are:

  • micro:bit

  • Calliope mini 3

  • Calliope mini 1/2 (code is run on Calliope mini 3 simulator)

Currently supported robots:

  • Maqueen Lite

  • Maqueen Plus

  • Maqueen Plus V2

  • Maqueen Plus V3 (since version 1.4.0)

  • Calli:bot

Currently supported robotic libraries:

Microcomputer simulator#

The microcomputer simulators are embedded iframes to the following to pre-existing simulators.

There is no embeddable iframe for the calliope mini 1/2, so the code is adjusted by adding the special library calliope_mini.py. With this additional library the code for the calliope mini 1/2 can be simulated on the calliope mini 3 simulator.

calliope_mini.py:

from calliopemini import *

Communication#

To send the code to the simulator and other commands such as stop, mute, etc, we used postMessage() messages, as well documented in the micro:bit simulator documentation. The calliope mini 3 simulator is an adjusted version of the micro:bit simulator, so most code for the simulator is independent of the device.

To successfully communicate with the iframe, it needs to be touched once, due to iframes frequent use as ads. Because of this, the control buttons for the iframe are hidden until it is started once by pressing on it.

Simulation#

The microcomputer simulators have a simulated screen, and the buttons can also be interacted with. They also simulate hardware limitations like memory constraints of the microcomputers. Sounds are also supported.

The sensors of the microcomputers are currently not simulated and will return default values. In the future, simulations for the sensors could be added through an interface similar to the micro:bit Python Editor.

They also currently have no simulation of the pins.

Robotic simulator#

The robotic simulator is built upon the microcomputer simulators and executes the commands simulated on the microcomputer simulator. The robotic simulator was created using Phaser 3, a 2D web game engine.

Pin simulation workaround#

The microcomputer simulators currently have no pin simulation, the pins are normally used to control the robots. As a workaround, we parsed the code pre execution and replaced pin read/writes with print() and input() functions. These are the processed and used to communicate between the microcomputer and robotic simulator. To differentiate between actual print statements from pin reads/writes, a predetermined random string has been added in front of the pin reads/writes related statements.

We did not achieve to keep the parsing process general enough to enable support for custom-written robotic libraries. So the robotics simulator currently only works with the libraries listed above (mbrobot, mbrobot_plus, mbrobot_plusV2, mbrobot_plusV3 and callibot).

To add support for other libraries, additional parsers can be added to simulatorParser.ts, but it would be more beneficial in the long run to implement actual pin simulation.

Simulated commands#

Almost all commands of the supported libraries are simulated.

Table of currently supported commands: ✓ (supported) ✕ (not supported) - (not in the library)

Command

mbrobot.py

mbrobot_plus.py

mbrobot_plusV2.py

mbrobot_plusV3.py

callibot.py

General Movement

forward()

✓

✓

✓

✓

✓

backward()

✓

✓

✓

✓

✓

left()

✓

✓

✓

✓

✓

right()

✓

✓

✓

✓

✓

stop()

✓

✓

✓

✓

✓

setSpeed(s)

✓

✓

✓

✓

✓

leftArc®

✓

✓

✓

✓

✓

rightArc®

✓

✓

✓

✓

✓

calibrate(o, d, a)

✓

-

✓

-

-

motL.rotate(s)

✓

✓

✓

✓

-

motR.rotate(s)

✓

✓

✓

✓

-

Servo Control

setServo(s,a)

✕

✕

✕

✕

-

Sensors

getDistance()

✓

✓

✓

✓

✓

irLeft.read_digital()

✓

✓

✓

✓

-

irRight.read_digital()

✓

✓

✓

✓

-

irL1.read_digital()

-

✓

✓

✓

-

irL2.read_digital()

-

✓

✓

✓

-

irM.read_digital()

-

-

✓

✓

-

irR1.read_digital()

-

✓

✓

✓

-

irR2.read_digital()

-

✓

✓

✓

-

irL1.read_analog()

-

-

✓

✓

-

irL2.read_analog()

-

-

✓

✓

-

irM.read_analog()

-

-

✓

✓

-

irR1.read_analog()

-

-

✓

✓

-

irR2.read_analog()

-

-

✓

✓

-

irLeftValue()

-

-

-

-

✓

irRightValue()

-

-

-

-

✓

tsValue()

-

-

-

-

✓

tsLeftValue()

-

-

-

-

✓

tsRightValue()

-

-

-

-

✓

Signaling

setLED(b)

✓

✓

✓

✓

✓

setLED(l,r)

✓

✓

✓

✓

-

setLEDLeft(x)

✓

✓

✓

✓

✓

setLEDRight(x)

✓

✓

✓

✓

✓

setAlarm(x)

✓

✓

✓

✓

-

beep()

✓

✓

✓

✓

-

fillRGB(r,g,b)

✓

-

✓

✓

-

setRGB(r,g,b)

-

-

-

✓

-

posRGB(x,r,g,b)

✓

-

✓

✓

-

clearRGB()

✓

-

✓

✓

-

The columns for mbrobot_plus and mbrobot_plusV3 are based on the libraries (@tigerpython/robotics-libraries 1.4.2) and simulatorParser.ts, and were spot-checked in the simulator for version 1.9.0. On the Maqueen Plus V3, getDistance() uses the simulated lidar sensor. Servos can be called on all Maqueen robots, but are not shown in the simulation.

Configuring the simulation from Python (RobotContext)#

Since version 1.8.0, the Maqueen libraries (mbrobot, mbrobot_plus, mbrobot_plusV2 and mbrobot_plusV3) contain the class RobotContext, known from TigerJython, to configure the simulated environment from the program:

Function

Description

RobotContext.setStartPosition(x, y)

Start position of the robot

RobotContext.setStartDirection(w)

Start direction of the robot (in degrees)

RobotContext.enableTrace(on=True)

Draws the path of the robot

RobotContext.enableRotCenter(on=True)

Shows the rotation center of the robot

RobotContext.useBackground(sprite)

Uses an image as background

RobotContext.useObstacle(sprite, x, y)

Adds an obstacle

RobotContext.useTarget(sprite, mesh, x, y)

Adds a target with the given mesh

setBeamAreaColor(color), setProximityCircleColor(color), setMeshTriangleColor(color)

Colors of the sensor visualisation

eraseBeamArea()

Removes the visualised beam area

from mbrobot import *

RobotContext.setStartPosition(100, 300)
RobotContext.enableTrace()
forward()
delay(2000)
stop()

Environment editor#

To simulate the sensors, an environment editor has also been added for the robotic simulator. While hovering over the robotic simulator, a tool bar will appear, which gives you various tools, to build a custom environment. To make the environment shareable, they can be saved to JSON files and loaded to the simulator again.

Data size#

The saved data to the JSON files was kept rather compact, so that environments can be shared via URL, as URLs have rather small data limitations. Share links of a program include the current environment in the playground argument (see URL arguments). The biggest outlier here is the pen tool, which draws lines by adding many circles to the environment, which are all saved as their coordinates(some optimizations as minimal distance between circles were made). In case the data turns out to be too big to share via URL, the pen tool should probably be saved as entire lines.