Uses 2 HC-SR04 ultrasonic modules to steer the RenBuggy away from obstacles. Renishaw Team page fork.
Dependencies: mbed
Fork of RenBuggy_Ultrasonic by
Diff: main.cpp
- Revision:
- 1:80c2ef16a42f
- Parent:
- 0:fbceffb594b6
--- a/main.cpp Thu Jul 14 12:58:48 2016 +0000 +++ b/main.cpp Mon Jul 18 10:00:29 2016 +0000 @@ -1,39 +1,64 @@ +/* +*RenBuggy_Ultrasonic +* +*A Program that allows the RenBuggy to avoid obstacles using two HC-SR04 +*ultrasonic modules. +* +*Copyright (c) 2016 Elijah Orr + +*Permission is hereby granted, free of charge, to any person obtaining a copy +*of this software and associated documentation files (the "Software"), to deal +*in the Software without restriction, including without limitation the rights +*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +*copies of the Software, and to permit persons to whom the Software is +*furnished to do so, subject to the following conditions: + +*The above copyright notice and this permission notice shall be included in +*all copies or substantial portions of the Software. + +*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +*THE SOFTWARE. +*/ + +//include files - mbed library and our ultrasonic library #include "mbed.h" #include "ultrasonic_buggy.h" -//#include "USBSerial.h" -//USBSerial serial; - - +//The main function is where the program will begin to execute int main(){ + //create two floating point vairables to store distance readings in float left_distance; float right_distance; + //call the stop function to make sure buggy is stationary stop(); + //wait for some setup time wait(5); - //serial.printf("PROGRAM START\n\r"); + //the code in this while loop will always execute and will repeat forever while(1){ - - //wait(1); - + //take a distance reading from each of the sensors left_distance = getDistance_l(); right_distance = getDistance_r(); - //if((left_distance > 0.3) && (right_distance > 0.3)){ - //serial.printf("left distance = %f right distance = %f\n\r", left_distance, right_distance); - /* if(left_distance > right_distance){ - left(0.1); - } - else if(right_distance > left_distance){ - right(0.1); - } + //if there is an object on the left, turn right + if(left_distance < 0.4){ + right(0.1); } - + //else if there is an object on the right, turn left + else if(right_distance < 0.4){ + left(0.1); + } + //else move forwards else{ - right(3); - }*/ - + forward(0.1); + } + //code loops back to start of while loop } }