The subsystem design/basis for the final project

Dependencies:   mbed-rtos mbed-src pixylib

global.cpp

Committer:
balsamfir
Date:
2016-03-25
Revision:
5:f655435d0782
Parent:
3:dfb6733ae397
Child:
6:52686c25e4af

File content as of revision 5:f655435d0782:

#include "global.h"

// IO Port
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
DigitalOut leftDir(p29);
DigitalOut rightDir(p30);
DigitalOut spiReset(p11);
DigitalOut ioReset(p12);

// Comunication 
SPI deSpi(p5, p6, p7);
Pixy pixy(Pixy::SPI, p11, p12, p13);
Serial pc(USBTX, USBRX); // PC serial channel
Serial bt(p9, p10); // Bluetooth serial channel

// Control
PI leftMotorPi(MOTOR_PERIOD, MOTOR_KP, MOTOR_KI);
PI rightMotorPi(MOTOR_PERIOD, MOTOR_KP, MOTOR_KI);
PI targetHeightPi(NAVIGATION_PERIOD, SPEED_KP SPEED_KI);
PI targetXPi(NAVIGATION_PERIOD, STEERING_KP, STEERING_KI);

// Other
PwmOut leftPwm(p21); 
PwmOut rightPwm(p22); 
InterruptIn bumper(p8);

// Converts measurements from the QE2 to rads/sec
float QE2RadsPerSec(short counts, short time) {  
    int cnt32;   
    if (counts & 0x00008000) {
        cnt32 = counts | 0xFFFF0000;
    } else {
        cnt32 = counts;
    }   
    return (cnt32*122.62)/time;
}