Driver for controlling Renishaw RenBuggy

Dependencies:   SevenSegmentDisplay DCMotorDrive mbed MotorController

Committer:
jf1452
Date:
Wed Jan 15 11:51:19 2014 +0000
Revision:
3:0dd99309381e
Parent:
2:4180acdfa77a
Child:
4:64d065d6d072
Preliminary code for Renishaw RenBuggy control for the Skills Gap Project

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jf1452 0:ae927e3c7264 1 /*******************************************************************************
jf1452 0:ae927e3c7264 2 * This program demonstrates how to drive the seven segment display *
jf1452 0:ae927e3c7264 3 * *
jf1452 0:ae927e3c7264 4 * Jon Fuge *
jf1452 0:ae927e3c7264 5 * V1.0 24/12/2013 First issue of code *
jf1452 0:ae927e3c7264 6 *******************************************************************************/
jf1452 0:ae927e3c7264 7
jf1452 0:ae927e3c7264 8 #include "mbed.h"
jf1452 0:ae927e3c7264 9 #include "SevenSegmentDisplay.h"
jf1452 3:0dd99309381e 10 #include "MotorController.h"
jf1452 0:ae927e3c7264 11
jf1452 3:0dd99309381e 12 uint16_t u16LeftSpeed = 0, u16RightSpeed = 0;
jf1452 0:ae927e3c7264 13
jf1452 1:919b214c583c 14 // Options to instantiate SevenSegmentDisplay are...
jf1452 1:919b214c583c 15 // FADE: causes the number changes to fade in smoothly
jf1452 1:919b214c583c 16 // INSTANT: causes the an instant number change
jf1452 1:919b214c583c 17 // + FLASH: causes the display to flash
jf1452 1:919b214c583c 18 SevenSegmentDisplay segmentled( FADE );
jf1452 0:ae927e3c7264 19
jf1452 3:0dd99309381e 20 MotorController RenBuggy(p5, p7, p6, p8);
jf1452 3:0dd99309381e 21 DigitalIn LFast(p9), LSlow(p12), RFast(p15), RSlow(p18);
jf1452 3:0dd99309381e 22
jf1452 0:ae927e3c7264 23 void attimeout(); //declare prototype for timeout handler.
jf1452 0:ae927e3c7264 24
jf1452 0:ae927e3c7264 25 Ticker timeout; //Create an instance of class Ticker called timeout.
jf1452 0:ae927e3c7264 26
jf1452 0:ae927e3c7264 27 int main()
jf1452 0:ae927e3c7264 28 {
jf1452 3:0dd99309381e 29 LFast.mode(PullUp);
jf1452 3:0dd99309381e 30 LSlow.mode(PullUp);
jf1452 3:0dd99309381e 31 RFast.mode(PullUp);
jf1452 3:0dd99309381e 32 RSlow.mode(PullUp);
jf1452 0:ae927e3c7264 33
jf1452 3:0dd99309381e 34 timeout.attach(&attimeout, 3);
jf1452 3:0dd99309381e 35 // LeftMotor.SetMotorPwmAndRevolutions(18000,32);
jf1452 1:919b214c583c 36
jf1452 3:0dd99309381e 37
jf1452 3:0dd99309381e 38 for(;;) {
jf1452 3:0dd99309381e 39 } // Loop forever (the program uses interrupts)
jf1452 0:ae927e3c7264 40 }
jf1452 0:ae927e3c7264 41
jf1452 1:919b214c583c 42 void attimeout()
jf1452 0:ae927e3c7264 43 {
jf1452 3:0dd99309381e 44 int MotorConv = 0;
jf1452 3:0dd99309381e 45 static int Flip = 0;
jf1452 3:0dd99309381e 46
jf1452 3:0dd99309381e 47 if ((RFast == 0) && (u16RightSpeed < PWM_PERIOD * 1000))
jf1452 3:0dd99309381e 48 {
jf1452 3:0dd99309381e 49 u16RightSpeed += 15;
jf1452 3:0dd99309381e 50 // RightMotor.SetMotorPwm(u16RightSpeed);
jf1452 3:0dd99309381e 51 }
jf1452 3:0dd99309381e 52 if ((RSlow == 0) && (u16RightSpeed > 0))
jf1452 3:0dd99309381e 53 {
jf1452 3:0dd99309381e 54 u16RightSpeed -= 15;
jf1452 3:0dd99309381e 55 // RightMotor.SetMotorPwm(u16RightSpeed);
jf1452 3:0dd99309381e 56 }
jf1452 3:0dd99309381e 57 if ((LFast == 0) && (u16LeftSpeed < PWM_PERIOD * 1000))
jf1452 3:0dd99309381e 58 {
jf1452 3:0dd99309381e 59 u16LeftSpeed += 15;
jf1452 3:0dd99309381e 60 // LeftMotor.SetMotorPwm(u16LeftSpeed);
jf1452 3:0dd99309381e 61 }
jf1452 3:0dd99309381e 62 if ((LSlow == 0) && (u16LeftSpeed > 0))
jf1452 3:0dd99309381e 63 {
jf1452 3:0dd99309381e 64 u16LeftSpeed -= 15;
jf1452 3:0dd99309381e 65 // LeftMotor.SetMotorPwm(u16LeftSpeed);
jf1452 0:ae927e3c7264 66 }
jf1452 1:919b214c583c 67 // Updates display with new values.
jf1452 3:0dd99309381e 68 if (Flip++ == 0)
jf1452 3:0dd99309381e 69 MotorConv = RenBuggy.LeftReadOdometer();
jf1452 3:0dd99309381e 70 else
jf1452 3:0dd99309381e 71 {
jf1452 3:0dd99309381e 72 MotorConv = RenBuggy.RightReadOdometer();
jf1452 3:0dd99309381e 73 Flip = 0;
jf1452 3:0dd99309381e 74 }
jf1452 3:0dd99309381e 75 //MotorConv = RenBuggy.LeftReadOdometer();
jf1452 3:0dd99309381e 76 segmentled.DisplayInt(MotorConv);
jf1452 1:919b214c583c 77 }