code of robot bike

Dependencies:   SDFileSystem mbed

Fork of Robot_Bicycle by Chris LU

Committer:
YCTung
Date:
Thu Jun 09 09:46:38 2016 +0000
Revision:
0:830ddddc129f
Child:
1:709be64ca63c
add header files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YCTung 0:830ddddc129f 1 #include "mbed.h"
YCTung 0:830ddddc129f 2
YCTung 0:830ddddc129f 3 #include "RobotServo.h"
YCTung 0:830ddddc129f 4 #include "SensorFusion.h"
YCTung 0:830ddddc129f 5 #include "SPI_9dSensor.h"
YCTung 0:830ddddc129f 6 #include "RobotBicycleConst.h"
YCTung 0:830ddddc129f 7
YCTung 0:830ddddc129f 8 AnalogIn analog_value(A5);//When using the ADC module, those pins connected to AnalogIn can't be used to output.
YCTung 0:830ddddc129f 9
YCTung 0:830ddddc129f 10 Ticker timer1;
YCTung 0:830ddddc129f 11 Ticker timer2;
YCTung 0:830ddddc129f 12
YCTung 0:830ddddc129f 13 //Serial pc(D1, D0) declared in SPI_9dSensor.h
YCTung 0:830ddddc129f 14
YCTung 0:830ddddc129f 15 float meas, L_inver;
YCTung 0:830ddddc129f 16
YCTung 0:830ddddc129f 17 void timer1_interrupt(void);
YCTung 0:830ddddc129f 18 void timer2_interrupt(void);
YCTung 0:830ddddc129f 19
YCTung 0:830ddddc129f 20 int main() {
YCTung 0:830ddddc129f 21 setupServo();
YCTung 0:830ddddc129f 22
YCTung 0:830ddddc129f 23 timer1.attach_us(&timer1_interrupt, 4000);//4.0ms interrupt period (250 Hz)
YCTung 0:830ddddc129f 24 timer2.attach_us(&timer2_interrupt, 4098);//4.098ms interrupt period (244 Hz)
YCTung 0:830ddddc129f 25
YCTung 0:830ddddc129f 26 pc.printf("\nAnalogIn example\r\n");
YCTung 0:830ddddc129f 27
YCTung 0:830ddddc129f 28 while(1) {
YCTung 0:830ddddc129f 29 pc.printf("measure: %f V,\t%f cm\r\n", meas, 1/L_inver);
YCTung 0:830ddddc129f 30 wait(0.1); // 200 ms
YCTung 0:830ddddc129f 31 }
YCTung 0:830ddddc129f 32 }
YCTung 0:830ddddc129f 33
YCTung 0:830ddddc129f 34 void timer1_interrupt(void)
YCTung 0:830ddddc129f 35 {
YCTung 0:830ddddc129f 36 meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
YCTung 0:830ddddc129f 37 meas = meas * 3.3f; // Change the value to be in the 0 to 3300 range
YCTung 0:830ddddc129f 38 L_inver = 0.0063f * meas - 0.005769f;
YCTung 0:830ddddc129f 39 }
YCTung 0:830ddddc129f 40
YCTung 0:830ddddc129f 41 void timer2_interrupt(void)
YCTung 0:830ddddc129f 42 {
YCTung 0:830ddddc129f 43 ;
YCTung 0:830ddddc129f 44 }