![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
stop cart
Dependencies: mbed ContinuousServo
Revision 1:cf9ba941d8c2, committed 2019-04-17
- Comitter:
- m211002
- Date:
- Wed Apr 17 20:10:31 2019 +0000
- Parent:
- 0:9952fdc226ac
- Commit message:
- Sonar Subsystem stops car 4/17/19 2.0
Changed in this revision
ContinuousServo.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ContinuousServo.lib Wed Apr 17 20:10:31 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/Weston-and-Ivan/code/ContinuousServo/#f1fc02b6744f
--- a/main.cpp Wed Apr 17 15:40:42 2019 +0000 +++ b/main.cpp Wed Apr 17 20:10:31 2019 +0000 @@ -1,31 +1,40 @@ #include "mbed.h" +#include "ContinuousServo.h" +#include "Tach.h" Serial pc(USBTX,USBRX); + //sonar sensor AnalogIn sonar(p19); //range sensor 9.8mV/inch - +//servo +ContinuousServo left(p23); +ContinuousServo right(p26); +//encoders +Tach tLeft(p17,64); +Tach tRight(p13,64); int main() { while(1) { - float distance,x; - int num_iterations,i; - pc.scanf("%d",&num_iterations);//reads in values from the Matlab + float distance; + float stop_val; + int stop_dist; + int num_iterations; + int i; + + pc.scanf("%d,%d",&num_iterations,&stop_dist);//reads in values from the Matlab for(i=1; i<=num_iterations; i++) { //will go until it meets the number of iterations - x = sonar.read();//takes the sensor redings and converts them to x - distance=x; - //if distance is == to desired distance than stop left and right wheels - stopvalue = .033 - if(x>stopvalue){ - + + distance = sonar.read(); //takes the sensor redings and converts them to "distance" variable + stop_val=.00275*stop_dist; //takes the input desired stop distance and multiplies it by a constant to achieve a stop value + + if(distance>stop_val) { //if distance is greater than desired stopping, then keep driving forward left.speed(.5); right.speed(.5); - - }else{ - left.stop(); - right.stop(); - } - + } else { //else stop left and right wheels + left.stop(); + right.stop(); + } wait(0.1); - pc.printf("%f\n",x);//mbed send out float values for Matlab + pc.printf("%f\n",distance);//mbed send out float values for Matlab } } } \ No newline at end of file