Racing Robots Session

Dependencies:   MbedJSONValue m3pi

This is the library for the Racing Robots session. It supports the M3PI robot of Polulu.

It is based on the "Arduino" principle of the init and loop function.

Just add a main.cpp file which contains:

Racing Robots main file

#include "robot_logic.h"

void init()
{
   //put your initialization logic here
}

void loop()
{
    //put your robot control logic here    
}

Features include:

  1. Controlling the LEDS
  2. Move forward and backward
  3. Turn
  4. Read the sensor values
  5. Use a PID controller

robot_logic.h

Committer:
dwini
Date:
2015-02-23
Revision:
0:c0ae66a0ec7a
Child:
2:356bb8d99326

File content as of revision 0:c0ae66a0ec7a:

#include "mbed.h"
#include "m3pi.h"

#ifndef H_ROBOT_LOGIC
#define H_ROBOT_LOGIC

//typedef enum {
//    LED_1 = 0,
//    LED_2 = 1,
//    LED_3 = 2,
//    LED_4 = 3
//    //.....
//} LedIndex;

typedef enum {
    LED_ON = 0,
    LED_OFF = 1,
    LED_TOGGLE = 2
} LedState;


/*
 * Drive the robot forward or backward.
 *
 * @speed The speed percentage with which to drive forward or backward [-100, +100].
 */
void drive(int speed);

// speed between -100% en +100%
void turn(int turnspeed);

// Stop the robot
void stop();

void sensor_calibrate();

// Read the value from the line sensor
int line_sensor();

// PID drive control
void pid_init(int p, int i, int d);


// returns turnspeed
int pid_turn(int line_position);

// Show drive speed and sensor data
void showStats();

// Show text on display
void display(char* fmt, ...);

// Turn a led on or off
//void led(LedIndex i, LedState state);

// Wait for a number of milliseconds
void await(int milliseconds);

#endif