The subsystem design/basis for the final project

Dependencies:   mbed-rtos mbed-src pixylib

Committer:
balsamfir
Date:
Fri Mar 25 19:34:16 2016 +0000
Revision:
7:5ef312aa2678
Parent:
6:52686c25e4af
Child:
9:62fbb69b612c
Child:
14:2d609d465f00
First working version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
balsamfir 2:2bc519e14bae 1 #include "mbed.h"
balsamfir 2:2bc519e14bae 2 #include "rtos.h"
balsamfir 3:dfb6733ae397 3 #include "Pixy.h"
balsamfir 6:52686c25e4af 4 #include "PeriodicPI.h"
balsamfir 2:2bc519e14bae 5
balsamfir 2:2bc519e14bae 6 // ----------------------------------------------------------------
balsamfir 2:2bc519e14bae 7 // Contains common defintions share between modes
balsamfir 2:2bc519e14bae 8 // ----------------------------------------------------------------
balsamfir 2:2bc519e14bae 9
balsamfir 5:f655435d0782 10 // Preprocessor Definitions
balsamfir 5:f655435d0782 11 // ----------------------------------------------------------------
balsamfir 6:52686c25e4af 12 #define SPEED_MAX 10 // rads/s
balsamfir 5:f655435d0782 13 #define MAX_BLOCKS 1
balsamfir 6:52686c25e4af 14
balsamfir 5:f655435d0782 15 #define TARGET_DECIMAL 10
balsamfir 5:f655435d0782 16 #define PWM_PERIOD 0.001
balsamfir 5:f655435d0782 17 #define MOTOR_PERIOD 0.001
balsamfir 5:f655435d0782 18 #define NAVIGATION_PERIOD 0.0167 // 60 times/sec
balsamfir 5:f655435d0782 19
balsamfir 5:f655435d0782 20 #define MOTOR_KP 0.000120
balsamfir 6:52686c25e4af 21 #define MOTOR_KI 0.0000001
balsamfir 5:f655435d0782 22
balsamfir 7:5ef312aa2678 23 #define STEERING_KP 0.01
balsamfir 7:5ef312aa2678 24 #define STEERING_KI 0.1
balsamfir 5:f655435d0782 25
balsamfir 7:5ef312aa2678 26 #define SPEED_KP 0.2
balsamfir 6:52686c25e4af 27 #define SPEED_KI 0.6
balsamfir 6:52686c25e4af 28
balsamfir 5:f655435d0782 29
balsamfir 5:f655435d0782 30 // Global variables
balsamfir 5:f655435d0782 31 // ----------------------------------------------------------------
balsamfir 2:2bc519e14bae 32 // IO Port
balsamfir 2:2bc519e14bae 33 extern DigitalOut led1;
balsamfir 2:2bc519e14bae 34 extern DigitalOut led2;
balsamfir 2:2bc519e14bae 35 extern DigitalOut led3;
balsamfir 2:2bc519e14bae 36 extern DigitalOut led4;
balsamfir 2:2bc519e14bae 37 extern DigitalOut leftDir;
balsamfir 2:2bc519e14bae 38 extern DigitalOut rightDir;
balsamfir 2:2bc519e14bae 39 extern DigitalOut spiReset;
balsamfir 2:2bc519e14bae 40 extern DigitalOut ioReset;
balsamfir 2:2bc519e14bae 41
balsamfir 2:2bc519e14bae 42 // Comunication
balsamfir 2:2bc519e14bae 43 extern SPI deSpi;
balsamfir 3:dfb6733ae397 44 extern Pixy pixy;
balsamfir 2:2bc519e14bae 45 extern Serial pc; // PC serial channel
balsamfir 2:2bc519e14bae 46 extern Serial bt; // Bluetooth serial channel
balsamfir 2:2bc519e14bae 47
balsamfir 5:f655435d0782 48 // Control
balsamfir 6:52686c25e4af 49 extern PeriodicPI leftMotorPI;
balsamfir 6:52686c25e4af 50 extern PeriodicPI rightMotorPI;
balsamfir 6:52686c25e4af 51 extern PeriodicPI heightPI;
balsamfir 6:52686c25e4af 52 extern PeriodicPI xPI;
balsamfir 5:f655435d0782 53
balsamfir 3:dfb6733ae397 54 // Other
balsamfir 3:dfb6733ae397 55 extern PwmOut leftPwm;
balsamfir 3:dfb6733ae397 56 extern PwmOut rightPwm;
balsamfir 3:dfb6733ae397 57 extern InterruptIn bumper; // External interrupt pin declared as Bumper
balsamfir 3:dfb6733ae397 58
balsamfir 2:2bc519e14bae 59 // Method prototypes
balsamfir 3:dfb6733ae397 60 void PI(float error, float *output, float *integral, float kP, float kI, float bound);
balsamfir 3:dfb6733ae397 61 float QE2RadsPerSec(short counts, short time);