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 V2
Calli:bot
Currently supported robotic libraries:
mbrobot_plusV2.py
Microcomputer simulator#
The microcomputer simulators are embedded iframes to the following to pre-existing simulators.
There is no embedable 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 mico: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 adds. 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 defalt 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 mbrobot.py, mbrobot_plusV2 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_plusV2.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) |
✕ |
✕ |
- |
setMinServoDuty(x) |
- |
✕ |
- |
setMaxServoDuty(x) |
- |
✕ |
- |
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(x,r,g,b) |
✓ |
✓ |
- |
clearRGB(x,r,g,b) |
✓ |
✓ |
- |
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 to enable plans to share environements via URL, as urls have rather small data limitations. 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.