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.
Diff: my_libraries/encoders.cpp
- Revision:
- 3:bd16e43ad7be
diff -r 94059cb643be -r bd16e43ad7be my_libraries/encoders.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/my_libraries/encoders.cpp Fri Oct 17 06:21:52 2014 +0000 @@ -0,0 +1,46 @@ +// ----- Libraries ------------------------------------------------------------------ +#include "mbed.h" +#include "encoders.h" + +// ----- I/O Pins ------------------------------------------------------------------- +InterruptIn interrupt_encoder_der(D2); +InterruptIn interrupt_encoder_izq(D3); + + +int flanco_bajada_rigth; +int flanco_bajada_left; + +// ----- Functions ------------------------------------------------------------------ +void encoders_to_zero(){ + flanco_bajada_rigth = 0; + flanco_bajada_left = 0; +} + +void falling_encoder_rigth(void){ + flanco_bajada_rigth++; +} + +void falling_encoder_left(void){ + flanco_bajada_left++; +} + +void init_encoders(){ + interrupt_encoder_der.fall(&falling_encoder_rigth); + interrupt_encoder_izq.fall(&falling_encoder_left); +} + +float encoder(int sensor_encoder){ + int read_encoder = 0; + float distancia; + + if(sensor_encoder==encoder_rigth){ + read_encoder= flanco_bajada_rigth; + + }else if(sensor_encoder==encoder_left){ + read_encoder= flanco_bajada_left; + + } + distancia= (read_encoder/5)*2.2580; + + return distancia; +} \ No newline at end of file