Calysto Simulator


Both can be installed via pip. These are already installed on Athena at Bryn Mawr College.

For the %%brain magic, you need to use the calysto magics:

from calysto import register_ipython_magics

These are already loaded locally on the Athena server.

You can also program the simulator without the magic, but it requires some boiler-plate code.

Start the simulator

The simulator runs in a thread and has a GUI via the IPython widgets:

In [1]:
from calysto.simulation import View

You won't be able to see the simulation view above, unless you are running a live kernel. But it would look something like this:


Write a brain controller

Each robot/agent also runs in a thread. You can easily create a thread (with any error messages going to the simulator above) using the %%brain magic:

In [2]:


The following methods on robot are defined:

  • forward(seconds)
  • backward(seconds)
  • turnLeft(seconds)
  • turnRight(seconds)
  • sleep(seconds)
  • stop()


  • takePicture() - returns a 256 x 128 image from agent's camera
  • getIR(position) - floating point numbers indicating 0 to 1 obstacle (1 means no obstacle, less than 1 means detection, with lower meaning closer)
  • stalled - Boolean indicating bumping against something

You can define a simulation file like

from calysto.simulation import LadyBug, Spider, Simulation, Color
import math

def makeSimulation():
    ladybug = LadyBug(550, 350, -math.pi/2)
    spider = Spider(50, 50, 0)
    def spiderBrain():
        direction = 1
        while simulation.is_running.is_set():
            if spider.stalled:
                direction = direction * -1
            if direction == 1:
    spider.brain = spiderBrain
    simulation = Simulation(600, 400, ladybug, spider)
    simulation.makeWall(500, 100, 10, 200, Color(255, 255, 0))
    simulation.makeWall(10, 100, 190, 10, Color(255, 255, 0))
    simulation.makeWall(300, 100, 200, 10, Color(255, 255, 0))
    simulation.makeWall(100, 300, 410, 10, Color(255, 255, 0))
    simulation.makeWall(10, 200, 390, 10, Color(255, 255, 0))
    return simulation

There are three robots types:

  • Spider
  • LadyBug
  • Robot - based on the Scribbler/IPRE robot

Implementation details

Some effort has been taken to reduce the load on the server, and between notebook and kernel.

  • minimum update computation: computes collisions, and IR hits
  • camera images taken on request (expensive)
  • simulator view is transfered to notebook as SVG for efficient size and speed
  • each controller/brain runs in its own thread


You can use the simulator in a variety of styles, including without graphics, faster than real time, multiple controllers, etc.

Here is an example getting an image from the LadyBug's camera:

In [4]:
from calysto.simulation import get_robot
from calysto.display import display
In [5]:
with get_robot() as robot: