Robot using IMU and IR sensor data to drive autonomously and create a map
Dependencies: mbed mbed-rtos LSM9DS1_Library_cal Motor
Diff: main.cpp
- Revision:
- 7:cbccf5c5da6d
- Parent:
- 6:a51f4ac6f42b
- Child:
- 8:198568d5746b
--- a/main.cpp Sun Apr 24 21:08:30 2016 +0000 +++ b/main.cpp Thu Apr 28 05:20:35 2016 +0000 @@ -10,12 +10,22 @@ AnalogIn infraredF(p17); //Front infrared distance sensor Serial pc(USBTX, USBRX); Timer t; +char str[40]; float leftDist, rightDist, frontDist; //Distances from robot to obstacles float xaccel, yaccel, zaccel; //Acceleration in the x, y, and z directions float xmag, ymag, zmag, head; //Magnetic readings int ldist, rdist, fdist; +//dual H bridge Polulu +PwmOut PWMA(p21); //connect p21 to PWMA +PwmOut PWMB(p22); //connect p22 to PWMB +DigitalOut Ain1(p23); //connect p23 to Ain1 +DigitalOut Ain2(p24); //connect p24 to Ain2 + + + + void printAttitude(float ax, float ay, float az, float mx, float my, float mz) { float roll = atan2(ay, az); @@ -100,14 +110,25 @@ } } +void send_thread(void const *args) { + while (1) { + sprintf (str, "%0.6f,%0.6f,%0.6f,%d,%d,%d,%d\n", xaccel, zaccel, ymag, fdist, ldist, rdist, t.read_us()); //buffer data to be sent to computer + Thread::wait(500); + } +} + + int main() { //Test - t.begin(); + t.start(); Thread left(left_thread); Thread right(right_thread); Thread front(front_thread); Thread IMU(IMU_thread); + Thread send(send_thread); + Ain1=Ain2=1; //enabling PWM while(1) { - + PWMA.write(0.5f); //writing 50% duty cycle + PWMB.write(0.5f); //to pwm A and B } }