The subsystem design/basis for the final project

Dependencies:   mbed-rtos mbed-src pixylib

Committer:
balsamfir
Date:
Fri Mar 25 13:36:14 2016 +0000
Revision:
5:f655435d0782
Parent:
3:dfb6733ae397
Child:
6:52686c25e4af
Backup before revert

Who changed what in which revision?

UserRevisionLine numberNew contents of line
balsamfir 2:2bc519e14bae 1 #include "global.h"
balsamfir 2:2bc519e14bae 2
balsamfir 2:2bc519e14bae 3 // IO Port
balsamfir 2:2bc519e14bae 4 DigitalOut led1(LED1);
balsamfir 2:2bc519e14bae 5 DigitalOut led2(LED2);
balsamfir 2:2bc519e14bae 6 DigitalOut led3(LED3);
balsamfir 2:2bc519e14bae 7 DigitalOut led4(LED4);
balsamfir 2:2bc519e14bae 8 DigitalOut leftDir(p29);
balsamfir 2:2bc519e14bae 9 DigitalOut rightDir(p30);
balsamfir 2:2bc519e14bae 10 DigitalOut spiReset(p11);
balsamfir 2:2bc519e14bae 11 DigitalOut ioReset(p12);
balsamfir 2:2bc519e14bae 12
balsamfir 2:2bc519e14bae 13 // Comunication
balsamfir 2:2bc519e14bae 14 SPI deSpi(p5, p6, p7);
balsamfir 3:dfb6733ae397 15 Pixy pixy(Pixy::SPI, p11, p12, p13);
balsamfir 2:2bc519e14bae 16 Serial pc(USBTX, USBRX); // PC serial channel
balsamfir 2:2bc519e14bae 17 Serial bt(p9, p10); // Bluetooth serial channel
balsamfir 2:2bc519e14bae 18
balsamfir 5:f655435d0782 19 // Control
balsamfir 5:f655435d0782 20 PI leftMotorPi(MOTOR_PERIOD, MOTOR_KP, MOTOR_KI);
balsamfir 5:f655435d0782 21 PI rightMotorPi(MOTOR_PERIOD, MOTOR_KP, MOTOR_KI);
balsamfir 5:f655435d0782 22 PI targetHeightPi(NAVIGATION_PERIOD, SPEED_KP SPEED_KI);
balsamfir 5:f655435d0782 23 PI targetXPi(NAVIGATION_PERIOD, STEERING_KP, STEERING_KI);
balsamfir 5:f655435d0782 24
balsamfir 3:dfb6733ae397 25 // Other
balsamfir 3:dfb6733ae397 26 PwmOut leftPwm(p21);
balsamfir 3:dfb6733ae397 27 PwmOut rightPwm(p22);
balsamfir 3:dfb6733ae397 28 InterruptIn bumper(p8);
balsamfir 3:dfb6733ae397 29
balsamfir 2:2bc519e14bae 30 // Converts measurements from the QE2 to rads/sec
balsamfir 3:dfb6733ae397 31 float QE2RadsPerSec(short counts, short time) {
balsamfir 3:dfb6733ae397 32 int cnt32;
balsamfir 3:dfb6733ae397 33 if (counts & 0x00008000) {
balsamfir 3:dfb6733ae397 34 cnt32 = counts | 0xFFFF0000;
balsamfir 3:dfb6733ae397 35 } else {
balsamfir 3:dfb6733ae397 36 cnt32 = counts;
balsamfir 3:dfb6733ae397 37 }
balsamfir 3:dfb6733ae397 38 return (cnt32*122.62)/time;
balsamfir 2:2bc519e14bae 39 }