Not finished. This is my first attemp to make an autonomous vehicle for the Sparkfun Autonomous Competition (https://avc.sparkfun.com/) of June 2015.
Dependencies: FXOS8700CQ SDFileSystem mbed
Fork of AVC_Robot_Controled_Navigation by
- For my autonomous robot I will use a GPS, magnometer, accelerometer, and encoders.
- I control my robot with a remote control to save the GPS points (detect turns) using a xBee radio and save them to a file in a SD card.
my_libraries/ultrasonic.cpp@5:b384cf06de76, 2014-11-07 (annotated)
- Committer:
- gerardo_carmona
- Date:
- Fri Nov 07 05:12:50 2014 +0000
- Revision:
- 5:b384cf06de76
- Parent:
- 4:c60636c95b80
Not finished!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gerardo_carmona | 2:94059cb643be | 1 | // ----- Libraries ------------------------------------------------------------------ |
gerardo_carmona | 2:94059cb643be | 2 | #include "mbed.h" |
gerardo_carmona | 2:94059cb643be | 3 | #include "ultrasonic.h" |
gerardo_carmona | 2:94059cb643be | 4 | |
gerardo_carmona | 2:94059cb643be | 5 | // ----- Constants ------------------------------------------------------------------ |
gerardo_carmona | 3:bd16e43ad7be | 6 | |
gerardo_carmona | 2:94059cb643be | 7 | |
gerardo_carmona | 2:94059cb643be | 8 | // ----- I/O Pins ------------------------------------------------------------------- |
gerardo_carmona | 2:94059cb643be | 9 | AnalogIn ultra_lef(A2); |
gerardo_carmona | 2:94059cb643be | 10 | AnalogIn ultra_rig(A3); |
gerardo_carmona | 2:94059cb643be | 11 | |
gerardo_carmona | 2:94059cb643be | 12 | // ----- Others --------------------------------------------------------------------- |
gerardo_carmona | 2:94059cb643be | 13 | |
gerardo_carmona | 2:94059cb643be | 14 | |
gerardo_carmona | 2:94059cb643be | 15 | // ----- Variables ------------------------------------------------------------------ |
gerardo_carmona | 2:94059cb643be | 16 | double read_sensor, cm; |
gerardo_carmona | 2:94059cb643be | 17 | |
gerardo_carmona | 2:94059cb643be | 18 | // ----- Functions ------------------------------------------------------------------ |
gerardo_carmona | 2:94059cb643be | 19 | float ultrasonicos(int sensor){ |
gerardo_carmona | 4:c60636c95b80 | 20 | double inch, volts; |
gerardo_carmona | 2:94059cb643be | 21 | if (sensor == ULTRA_R) { |
gerardo_carmona | 2:94059cb643be | 22 | read_sensor = ultra_rig; // read analog as a float |
gerardo_carmona | 2:94059cb643be | 23 | }else if (sensor == ULTRA_L) { |
gerardo_carmona | 2:94059cb643be | 24 | read_sensor = ultra_lef; // read analog as a float |
gerardo_carmona | 2:94059cb643be | 25 | } |
gerardo_carmona | 2:94059cb643be | 26 | // read_sensor * 3300mv / 6.4 mV/in * 2.54 in/cms |
gerardo_carmona | 4:c60636c95b80 | 27 | volts = read_sensor * 3300; |
gerardo_carmona | 4:c60636c95b80 | 28 | inch = volts / 6.4; |
gerardo_carmona | 4:c60636c95b80 | 29 | cm = inch * 2.54; |
gerardo_carmona | 2:94059cb643be | 30 | return cm; |
gerardo_carmona | 2:94059cb643be | 31 | } |