David's dead reckoning code for the LVBots competition on March 6th. Uses the mbed LPC1768, DRV8835, QTR-3RC, and two DC motors with encoders.

Dependencies:   PololuEncoder Pacer mbed GeneralDebouncer

test.cpp

Committer:
DavidEGrayson
Date:
2014-02-22
Revision:
9:9734347b5756
Parent:
8:78b1ff957cba
Child:
10:e4dd36148539

File content as of revision 9:9734347b5756:

// A file for testing routines that will not be used in the final firmware.

#include <mbed.h>
#include "motors.h"
#include <Pacer.h>

#include "test.h"
#include "leds.h"
#include "encoders.h"
#include "pc_serial.h"

void testEncoders()
{
    Pacer reportPacer(500000);
    Pacer blinkPacer(200000);
    while(1)
    {
        while(encoderBuffer.hasEvents())
        {
            PololuEncoderEvent event = encoderBuffer.readEvent();
        }
        
        if(reportPacer.pace())
        {
            led2 = 1;
            pc.printf("%8d %8d\n", encoderLeft.getCount(), encoderRight.getCount());
            led2 = 0;
        }
        
        if (blinkPacer.pace())
        {
            led1 = !led1;
        }
    }
}

void testMotors()
{
    led1 = 1;
    led2 = 0;
    led3 = 0;
    while(1)
    {
        motorsSpeedSet(0, 0);
        led2 = 0;
        led3 = 0;
        wait(2);
        
        motorsSpeedSet(300, 300);
        wait(2);
        
        motorsSpeedSet(-300, 300);
        wait(2);
        
        motorsSpeedSet(0, 0);
        led2 = 1;
        wait(2);
        
        motorsSpeedSet(600, 600);
        wait(2);
        
        motorsSpeedSet(0, 0);
        led3 = 1;
        wait(2);
        
        motorsSpeedSet(1200, 1200);
        wait(2);
    }
}