Code to run the microcontrollers on the R5 competition bot

Dependencies:   LineSensors mbed

DriveController.h

Committer:
Hypna
Date:
2014-10-03
Revision:
2:d0ce8e26cbc4
Parent:
1:fa6eb0c33b2f
Child:
3:0d7687b6ef14

File content as of revision 2:d0ce8e26cbc4:

#ifndef DRIVECONTROLLER_H
#define DRIVECONTROLLER_H
#include "mbed.h"

enum Direction
{
    North, South, East, West;
};

struct Command
{
    Direction direction = NORTH;
    int distance;
};

class DriveController
{
private:
    DigitalOut wheels[4] = {{PTC1}, {PTC2}, {PTE29}, {PTE30}};
    
    DigitalIn sensors[24] = {{PTC7}, {PTC0}, {PTC3}, {PTC4}, {PTC5}, {PTC6}, {PTC10}, {PTC11}, {PTC9},
        {PTC8}, {PTA5}, {PTA4}, {PTA12}, {PTD4}, {PTA2}, {PTA1}, {PTC12}, {PTC13}, {PTC16}, {PTC17},
        {PTD2}, {PTD0}, {PTD5}, {PTD13}};
        
    bool sensorStates[24] = {false};
       
    Direction orientation;
    
    Command command;
    
    void move();
    void getCommand();
    void rotate();
    void forward();
    void readSensors();
    double calculateError();
    bool intersection();
    
public:
    DriveController();
    void go();
};

#endif