Skip to content

PeterM-13/MicroMouse-HelpCode-2026

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Leonardo MicroMouse Help Code 2026

Here you will find the help code for MicroMouse.
For context, see video of MicroMouse 2025 here: LinkedIn

Contents

MicroMouse Title Page

Documentation

Config.h

This file contains ALL the variables to control every aspect of your mouse, all in one place.

// *** Recommended order to configure: ***
CELL_DISTANCE
LEFT_MOTOR_BIAS
RIGHT_MOTOR_BIAS
// Use `testMotors()` for these.

LC_LEFT_RIGHT_BIAS
LC_LEFT_IR_VALUE
LC_RIGHT_IR_VALUE
FRONT_IR_VALUE_DIFF
// Use `testIrReadings()` for these, looking at Serial Plotter.

TURN_LEFT_DEG_TO_STEPS_MULTIPLIER
TURN_RIGHT_DEG_TO_STEPS_MULTIPLIER
// Watch it turning and adjust accordilngly.

How to move your mouse

It's recommended to call these methods from 'YourAlgorithm'.

void startOffsetAction();
// Moves the mouse forwards 80% of a cell. Offsetting it enough to check the walls in the next cell.
// Called at the begining of the algorithm and after `turnAroundAction`.

void moveForwardAction();
// Moves the mouse 1 cell forwards.
// Lane centering is active.

void turnRightAction();
// Turns the mouse 90 degrees right.

void turnLeftAction();
// Turns the mouse 90 degrees left.

void turnAroundAction();
// Turns the mouse 180 degress, in the direction furthest from a wall to avoid collision.

int* getCell(int direction);
// Returns the cell in the `direction` relative to mouse.
// For example, if mouse at [10, 5] facing EAST, getCell(NORTH) returns [9, 5].
// For example, if mouse at [10, 5] facing SOUTH, getCell(NORTH) returns [10, 4].

float distToMiddle(Cell coord);
// Returns the distance from `coord` to middle.
// Use this in combination with `getCell`, like: distToMiddle(getCell(NORTH));

Global variables

bool wallLeft = true;
bool wallRight = true;
bool wallBack = true;
bool wallFront = false;
// Variables to store current surrounding walls.

bool fatalError = false; 
// If `true`, causes mouse to stop. 
// Updates this in `Main.ino` line 82.

bool collisionDetectionActive = false;
// When `true`, monitors the IMU and sets `fatalError` to `true` if IMU data goes above threshold, indicating a collision. 
// Threshold set in `Gyro.cpp` line 3.

bool laneCenteringActive = false;
// When `true`, enables lane centering. Also enables contunuous IR sensor readings.

bool updateGyroData = false;
// When `true`, continuously gets data from gyro, and updates Z angle.
// This is quite intensive, and slows down the program loop. So only enables when required, like when turning.
// But gyro seems inacurate anyway. So not being used.

Global Methods

void print(String text, int priority);
// Logs the text `text` to the serial console if the global variable `DEBUG_MODE` is greater than `priority`.

void printLoopTime();
// If called from a `loop`ing function, it prints the time to complete 1 cycle.

Getting Started

Begin in YourAlgorithm.cpp.
Here you will find a default algorithm, and this is where you should make edits, using the action functions described above.

The other important file is Config.h.
You need to adjust these variuables to your specifc mouse. Use trial and error.

Dependencies

Install these using the Arduino IDE Library Manager:

  • <Arduino_LSM9DS1> Used to control the IMU & Gyro.
  • <Adafruit_VL6180X> Used to control the IR Sensors.

Contributor

  • Peter Metcalfe (Please reach out for support - I'm more than happy to help :)


License

CC BY-NC-SA 4.0

About

Leonardo MicroMouse Code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published