Robot using IMU and IR sensor data to drive autonomously and create a map

Dependencies:   mbed mbed-rtos LSM9DS1_Library_cal Motor

Committer:
wschon
Date:
Sun Apr 10 21:23:17 2016 +0000
Revision:
2:fcf6f5901ee6
Parent:
1:27c32ba9fe93
Child:
3:70f624c5fe26
added threads to measure distance from left, right, and front IR sensors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wschon 0:8e17f11689f2 1 #include "mbed.h"
wschon 2:fcf6f5901ee6 2 #include "rtos.h"
wschon 2:fcf6f5901ee6 3
wschon 2:fcf6f5901ee6 4 AnalogIn infraredR(p20); //Right infrared distance sensor
wschon 2:fcf6f5901ee6 5 AnalogIn infraredL(p19); //Left infrared distance sensor
wschon 2:fcf6f5901ee6 6 AnalogIn infraredF(p17); //Front infrared distance sensor
wschon 2:fcf6f5901ee6 7
wschon 2:fcf6f5901ee6 8 float leftDist, rightDist, frontDist; //Distances from robot to obstacles
wschon 0:8e17f11689f2 9
wschon 2:fcf6f5901ee6 10 void left_thread(void const *args) {
wschon 2:fcf6f5901ee6 11 while (1) {
wschon 2:fcf6f5901ee6 12 leftDist = infraredL * 3.3f;
wschon 2:fcf6f5901ee6 13 Thread::wait(500); //wait 1/2 second before updating
wschon 2:fcf6f5901ee6 14 }
wschon 2:fcf6f5901ee6 15 }
wschon 2:fcf6f5901ee6 16
wschon 2:fcf6f5901ee6 17 void right_thread(void const *args) {
wschon 2:fcf6f5901ee6 18 while (1) {
wschon 2:fcf6f5901ee6 19 rightDist = infraredR * 3.3f;
wschon 2:fcf6f5901ee6 20 Thread::wait(500); //wait 1/2 second before updating
wschon 2:fcf6f5901ee6 21 }
wschon 2:fcf6f5901ee6 22 }
wschon 2:fcf6f5901ee6 23
wschon 2:fcf6f5901ee6 24 void front_thread(void const *args) {
wschon 2:fcf6f5901ee6 25 while (1) {
wschon 2:fcf6f5901ee6 26 frontDist = infraredF * 3.3f;
wschon 2:fcf6f5901ee6 27 Thread::wait(500); //wait 1/2 second before updating
wschon 2:fcf6f5901ee6 28 }
wschon 2:fcf6f5901ee6 29 }
wschon 0:8e17f11689f2 30
wschon 0:8e17f11689f2 31 int main() {
swilkins8 1:27c32ba9fe93 32 //Test
wschon 2:fcf6f5901ee6 33 Thread left(left_thread);
wschon 2:fcf6f5901ee6 34 Thread right(right_thread);
wschon 2:fcf6f5901ee6 35 Thread front(front_thread);
wschon 2:fcf6f5901ee6 36
wschon 0:8e17f11689f2 37 while(1) {
wschon 2:fcf6f5901ee6 38
wschon 0:8e17f11689f2 39 }
wschon 0:8e17f11689f2 40 }