Skip to content

MiRo and Layered Control Architectures

This page will help you get started with the lab template code.

Overview

Elowen template

Main control loop

Make sure to toggle off all the checkboxes in the Program Start Block:

These settings are not saved

You'll need to repeat this procedure every time you refresh or close/open the MiRoCODE page.

Elowen settings

The step variable keeps track of the main control loop iterations.

All the other helper functions are explained below.

Initialisation function

  1. The Move Neck block puts the MiRo's head in a position where it can use both sonar to detect walls and edges, and vision to detect AprilTags.
  2. The boolean variables boost, tumble and obstacle_ahead can be useful for inter-layer communication.
  3. The tags_seen list stores AprilTags, in the order they have been seen.
  4. The tumble rate should be adjusted to provide a rate of 0.2 tumble per second for your machine (details in the brief).
  5. The modified variable is used to toggle between the base and the modified model.

All the rest of the variables here should be self-evident.

Sensing function

Here, all the data from the sensors is acquired and specific readings are stored for later use.

  1. Sonar range: readings are within a range of 0.03 to 1m. The neck position (given above) should make it possible to use this both for cliff and wall detection.
  2. Cliff sensors: list of two readings (left and right sensor) which can be set to return either True/False or float values. Float values allow for a more nuanced thresholding for cliff detection.

This function outputs the state of the agent at each step.

Step: 1
Energy: 100.00%
Energy Flow: 0.00%
Brightness: 63.1%
Speed: 0.00m/s [0%]
Tumbles: 0
Tags seen: []

Formatted strings

Note the use of Python strings with format to print variables with a specified precision.
This way of formatting is agnostic to Python version (2 or 3) and is compatible with MiRo.

Layer 1: Metabolism

This layer should compute all the energy incomings and outgoings.
At each step, it should add/subtract energy_flow to/from the energy and keep watch for the stopping condition (energy = 0).

Layer 2: Safety

This layer should use the sonar and cliff_sensors to detect obstacles.
Different sonar thresholds can be used to detect both cliffs and walls.

Tip

Using two sensors is more reliable than one.

You can use the obstacle_ahead variable to subsume the higher Run layer.

Layer 3: Run

Makes MiRo move forward, with velocity as a function of overall brightness.

Layer 4: Tumble

How to do random tumbles?

Below is a toy example that should help you with writing the L4_Tumble layer.

Coin flip

You should aim to have all your helper functions structured this way.

Layer 5: Acquisition

You should check if an AprilTag is detected, and if so, if it is at 1 meter or closer.
Only then you should add it to the tags_seen list. You can use the boost variable to arrange inter-layer communication to L1.