First release.

Dependencies:   FXOS8700CQ SDFileSystem mbed

Final program

  • Controling a robot by Bluetooth, it is capable of making 90° turns and move pre-defined distances.

Code by:

  • Mayumi Hori
  • Sarahí Morán
  • Gerardo Carmona
Committer:
gerardo_carmona
Date:
Fri Nov 07 05:12:50 2014 +0000
Revision:
5:b384cf06de76
Parent:
3:bd16e43ad7be
Not finished!

Who changed what in which revision?

UserRevisionLine numberNew 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 }