Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
kyleliangus
Date:
Fri May 05 01:21:33 2017 +0000
Revision:
8:a0760acdc59e
Parent:
7:6f5cb6377bd4
Child:
9:1d8e4da058cd
Created Motor class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 0:a03c771ab78e 1 #include "mbed.h"
kyleliangus 4:b5b7836ca2b0 2
kyleliangus 6:3d68fedd6fd9 3 #include "irpair.h"
kyleliangus 4:b5b7836ca2b0 4 #include "main.h"
kyleliangus 4:b5b7836ca2b0 5 #include "motor.h"
kyleliangus 4:b5b7836ca2b0 6
sahilmgandhi 0:a03c771ab78e 7 #include <stdlib.h>
sahilmgandhi 1:8a4b2f573923 8 #include "ITG3200.h"
sahilmgandhi 7:6f5cb6377bd4 9 #include "QEI.h"
sahilmgandhi 0:a03c771ab78e 10
kyleliangus 4:b5b7836ca2b0 11 // PID
kyleliangus 4:b5b7836ca2b0 12 #define P_CONSTANT 0.0025
kyleliangus 4:b5b7836ca2b0 13 #define I_CONSTANT 0.0000025
kyleliangus 4:b5b7836ca2b0 14 #define D_CONSTANT 0.25
sahilmgandhi 0:a03c771ab78e 15
kyleliangus 8:a0760acdc59e 16 #include "QEI.h"
kyleliangus 8:a0760acdc59e 17 #define PULSES 880
christine222 3:880f15be8c72 18
sahilmgandhi 0:a03c771ab78e 19 int main()
sahilmgandhi 0:a03c771ab78e 20 {
kyleliangus 8:a0760acdc59e 21 //enableMotors();
christine222 3:880f15be8c72 22 //Set highest bandwidth.
sahilmgandhi 1:8a4b2f573923 23 gyro.setLpBandwidth(LPFBW_42HZ);
christine222 3:880f15be8c72 24 serial.baud(9600);
sahilmgandhi 7:6f5cb6377bd4 25 serial.printf("The gyro's address is %s", gyro.getWhoAmI());
sahilmgandhi 7:6f5cb6377bd4 26
sahilmgandhi 1:8a4b2f573923 27 wait (0.1);
sahilmgandhi 7:6f5cb6377bd4 28
christine222 3:880f15be8c72 29 // IR_1.write(1);
sahilmgandhi 2:771db996cee0 30 // IR_2.write(1);
sahilmgandhi 2:771db996cee0 31 // IR_3.write(1);
sahilmgandhi 2:771db996cee0 32 // IR_4.write(1);
christine222 3:880f15be8c72 33
sahilmgandhi 2:771db996cee0 34 redLed.write(1);
sahilmgandhi 2:771db996cee0 35 greenLed.write(0);
sahilmgandhi 2:771db996cee0 36 blueLed.write(1);
sahilmgandhi 1:8a4b2f573923 37
kyleliangus 8:a0760acdc59e 38 //rightWheelForward(0.1);
kyleliangus 8:a0760acdc59e 39 //leftWheelForward(0.1);
kyleliangus 8:a0760acdc59e 40
kyleliangus 8:a0760acdc59e 41 // PA_1 is A of right
kyleliangus 8:a0760acdc59e 42 // PA_0 is B of right
kyleliangus 8:a0760acdc59e 43 // PA_5 is A of left
kyleliangus 8:a0760acdc59e 44 // PB_3 is B of left
kyleliangus 8:a0760acdc59e 45 QEI encoder0( PA_5, PB_3, NC, PULSES, QEI::X4_ENCODING );
kyleliangus 8:a0760acdc59e 46 QEI encoder1( PA_1, PA_0, NC, PULSES, QEI::X4_ENCODING );
sahilmgandhi 7:6f5cb6377bd4 47
christine222 3:880f15be8c72 48 while (1) {
kyleliangus 8:a0760acdc59e 49
kyleliangus 8:a0760acdc59e 50 wait(0.1);
kyleliangus 8:a0760acdc59e 51 //serial.printf("%i, %i, %i\n", gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ());
kyleliangus 8:a0760acdc59e 52 serial.printf("Pulse Count=> e0:%d, e1:%d \r\n", encoder0.getPulses(),encoder1.getPulses());
sahilmgandhi 7:6f5cb6377bd4 53
christine222 3:880f15be8c72 54 //reading = Rec_4.read();
christine222 3:880f15be8c72 55 // serial.printf("reading: %f\n", reading);
sahilmgandhi 1:8a4b2f573923 56 // redLed.write(0);
sahilmgandhi 1:8a4b2f573923 57 // wait_ms(1000);
sahilmgandhi 1:8a4b2f573923 58 // redLed.write(1);
sahilmgandhi 1:8a4b2f573923 59 // greenLed.write(0);
sahilmgandhi 1:8a4b2f573923 60 // wait_ms(1000);
sahilmgandhi 1:8a4b2f573923 61 // greenLed.write(1);
sahilmgandhi 1:8a4b2f573923 62 // blueLed.write(0);
sahilmgandhi 1:8a4b2f573923 63 // wait_ms(1000);
sahilmgandhi 1:8a4b2f573923 64 // blueLed.write(1);
christine222 3:880f15be8c72 65 }
sahilmgandhi 0:a03c771ab78e 66 }