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/encoders.cpp@3:bd16e43ad7be, 2014-10-17 (annotated)
- Committer:
- gerardo_carmona
- Date:
- Fri Oct 17 06:21:52 2014 +0000
- Revision:
- 3:bd16e43ad7be
v1.3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gerardo_carmona | 3:bd16e43ad7be | 1 | // ----- Libraries ------------------------------------------------------------------ |
gerardo_carmona | 3:bd16e43ad7be | 2 | #include "mbed.h" |
gerardo_carmona | 3:bd16e43ad7be | 3 | #include "encoders.h" |
gerardo_carmona | 3:bd16e43ad7be | 4 | |
gerardo_carmona | 3:bd16e43ad7be | 5 | // ----- I/O Pins ------------------------------------------------------------------- |
gerardo_carmona | 3:bd16e43ad7be | 6 | InterruptIn interrupt_encoder_der(D2); |
gerardo_carmona | 3:bd16e43ad7be | 7 | InterruptIn interrupt_encoder_izq(D3); |
gerardo_carmona | 3:bd16e43ad7be | 8 | |
gerardo_carmona | 3:bd16e43ad7be | 9 | |
gerardo_carmona | 3:bd16e43ad7be | 10 | int flanco_bajada_rigth; |
gerardo_carmona | 3:bd16e43ad7be | 11 | int flanco_bajada_left; |
gerardo_carmona | 3:bd16e43ad7be | 12 | |
gerardo_carmona | 3:bd16e43ad7be | 13 | // ----- Functions ------------------------------------------------------------------ |
gerardo_carmona | 3:bd16e43ad7be | 14 | void encoders_to_zero(){ |
gerardo_carmona | 3:bd16e43ad7be | 15 | flanco_bajada_rigth = 0; |
gerardo_carmona | 3:bd16e43ad7be | 16 | flanco_bajada_left = 0; |
gerardo_carmona | 3:bd16e43ad7be | 17 | } |
gerardo_carmona | 3:bd16e43ad7be | 18 | |
gerardo_carmona | 3:bd16e43ad7be | 19 | void falling_encoder_rigth(void){ |
gerardo_carmona | 3:bd16e43ad7be | 20 | flanco_bajada_rigth++; |
gerardo_carmona | 3:bd16e43ad7be | 21 | } |
gerardo_carmona | 3:bd16e43ad7be | 22 | |
gerardo_carmona | 3:bd16e43ad7be | 23 | void falling_encoder_left(void){ |
gerardo_carmona | 3:bd16e43ad7be | 24 | flanco_bajada_left++; |
gerardo_carmona | 3:bd16e43ad7be | 25 | } |
gerardo_carmona | 3:bd16e43ad7be | 26 | |
gerardo_carmona | 3:bd16e43ad7be | 27 | void init_encoders(){ |
gerardo_carmona | 3:bd16e43ad7be | 28 | interrupt_encoder_der.fall(&falling_encoder_rigth); |
gerardo_carmona | 3:bd16e43ad7be | 29 | interrupt_encoder_izq.fall(&falling_encoder_left); |
gerardo_carmona | 3:bd16e43ad7be | 30 | } |
gerardo_carmona | 3:bd16e43ad7be | 31 | |
gerardo_carmona | 3:bd16e43ad7be | 32 | float encoder(int sensor_encoder){ |
gerardo_carmona | 3:bd16e43ad7be | 33 | int read_encoder = 0; |
gerardo_carmona | 3:bd16e43ad7be | 34 | float distancia; |
gerardo_carmona | 3:bd16e43ad7be | 35 | |
gerardo_carmona | 3:bd16e43ad7be | 36 | if(sensor_encoder==encoder_rigth){ |
gerardo_carmona | 3:bd16e43ad7be | 37 | read_encoder= flanco_bajada_rigth; |
gerardo_carmona | 3:bd16e43ad7be | 38 | |
gerardo_carmona | 3:bd16e43ad7be | 39 | }else if(sensor_encoder==encoder_left){ |
gerardo_carmona | 3:bd16e43ad7be | 40 | read_encoder= flanco_bajada_left; |
gerardo_carmona | 3:bd16e43ad7be | 41 | |
gerardo_carmona | 3:bd16e43ad7be | 42 | } |
gerardo_carmona | 3:bd16e43ad7be | 43 | distancia= (read_encoder/5)*2.2580; |
gerardo_carmona | 3:bd16e43ad7be | 44 | |
gerardo_carmona | 3:bd16e43ad7be | 45 | return distancia; |
gerardo_carmona | 3:bd16e43ad7be | 46 | } |