MiRo and Layered Control Architectures¶
This page will help you get started with the MiRoCode starter code.
Tip
Please, read the comment blocks in the provided starter code carefully.
Initialisation¶
A function called initialisation
has been defined for you, where initial values have been given to some variables (namely, step
, energy
, speed
, tumble_rate
, tumble
, obstacle_ahead
, bmr
, energy_flow
, tags_seen
).
You are expected to use these variables in your code and change their values accordingly when necessary.
Additionally, you are encouraged to experiment with different neck lift angle values to find the one that works best for detecting AprilTags and walls.
Success
You can disable the blocks which you do not require by right clicking on them and selecting disable
.
In the Periodic Control Loop
, a number of functions are called.
In this layered architecture, the agent’s actions in each layer depend on the perception of the agent’s environment.
Therefore, it is necessary to keep track of the sensor values and act accordingly.
This is the purpose of the sense function, in which you are asked to complete the code so that the sonar, cliff sensor and light sensor readings are stored in separate variables, so that they are accessed in each layer.
Afterwards, there are calls to the functions that correspond to each of the layers of the architecture:
Warning
If you refresh the page, make sure to disable the flags in the Program Start block.
Control layers¶
L1_Run
¶
This is the basic drive of Elowen to go forward, based on the brightness level.
L2_Tumble
¶
Elowen every once in a while performs a ‘tumble’. When in brighter areas, the tumble will happen less often and the angle will tend to be smaller compared to dimmer areas. This behaviour will eventually lead Elowen to move away from dimmer areas.
The decision whether to tumble or not at any given step can be made, for example, by comparing the probability of a tumble to an output of a random fraction
block.
L3_Avoid
¶
In this layer, checks for obstacle detection and cliff detection take place. Sonar and cliff sensor readings should be used to this end, and Elowen’s behaviour should be adjusted accordingly if any obstacle is detected.
L4_Boost
¶
This layer determines Elowen’s behaviour when detecting an AprilTag. You should keep in mind that each AprilTag can act as energy booster only once, and this should be reflected in your definition of this function.
L5_Metabolism
¶
In this layer, the inflow and outflow of energy are summed up. You are required to complete the definition of these functions, with the help of the provided comments in the starter code.
Helper functions¶
Some additional, helper functions, are available too:
print_status
This has already been defined for you, and it prints Elowen’s status for every step.iterate
This has already been defined for you as well. It checks whether the current energy level is above or below zero and updates the step counter. If the energy level is zero, Elowen stops moving.Velocity
Using the brightness level as input, you should define this function to determine the velocity of speed.Replenish
This function should be defined and called inL5_Metabolism
to determine the energy flow.Poisson
This should be defined and called inL2_Tumble
.
Function usage example¶
Please see below a typical usage example of a function that takes an input:
You should aim to have your helper functions structured this way.