The subsystem design/basis for the final project

Dependencies:   mbed-rtos mbed-src pixylib

Committer:
balsamfir
Date:
Mon Apr 24 21:37:50 2017 +0000
Revision:
19:05b8123905fb
Parent:
17:47e107f9587b
Commit before share

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 19:05b8123905fb 8 DigitalOut leftDir(p23); //
balsamfir 6:52686c25e4af 9 DigitalOut rightDir(p22); //
balsamfir 19:05b8123905fb 10 DigitalOut spiReset(p14); //changed
balsamfir 19:05b8123905fb 11 DigitalOut ioReset(p15); //
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 19:05b8123905fb 16 Serial pc(USBTX, USBRX); // PC serial channel
balsamfir 19:05b8123905fb 17 //Serial pc(p9, p10); // Bluetooth serial channel
balsamfir 2:2bc519e14bae 18
balsamfir 5:f655435d0782 19 // Control
balsamfir 6:52686c25e4af 20 PeriodicPI leftMotorPI(MOTOR_PERIOD, MOTOR_KP, MOTOR_KI);
balsamfir 6:52686c25e4af 21 PeriodicPI rightMotorPI(MOTOR_PERIOD, MOTOR_KP, MOTOR_KI);
balsamfir 6:52686c25e4af 22 PeriodicPI heightPI(NAVIGATION_PERIOD, SPEED_KP, SPEED_KI);
balsamfir 6:52686c25e4af 23 PeriodicPI xPI(NAVIGATION_PERIOD, STEERING_KP, STEERING_KI);
balsamfir 5:f655435d0782 24
balsamfir 3:dfb6733ae397 25 // Other
balsamfir 19:05b8123905fb 26 PwmOut leftPwm(p24);
balsamfir 19:05b8123905fb 27 PwmOut rightPwm(p21);
balsamfir 3:dfb6733ae397 28
balsamfir 19:05b8123905fb 29 // Converts measurements from the FPGA to rads/sec
balsamfir 19:05b8123905fb 30 float RadsPerSec(short counts, short time) {
balsamfir 19:05b8123905fb 31 return ((float)counts*26.558)/time;
balsamfir 15:caa5a93a31d7 32 }
balsamfir 15:caa5a93a31d7 33
balsamfir 15:caa5a93a31d7 34 // Returns the last character
balsamfir 19:05b8123905fb 35 void FlushBuffer(void) {
balsamfir 19:05b8123905fb 36 while (pc.readable()) pc.getc();
balsamfir 2:2bc519e14bae 37 }