This program is for an autonomous robot for the competition at the Hochschule Luzern. http://cruisingcrepe.wordpress.com/ We are one of the 32 teams. http://cruisingcrepe.wordpress.com/ The postition control is based on this Documentation: Control of Wheeled Mobile Robots: An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli. For more information see here: http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf

Dependencies:   mbed

Fork of autonomous Robot Android by Christian Burri

Committer:
chrigelburri
Date:
Mon Jun 10 14:40:37 2013 +0000
Revision:
39:a4fd6206da89
Parent:
12:235e318a414f
V1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chrigelburri 3:92ba0254af87 1 #include "Hallsensor.h"
chrigelburri 3:92ba0254af87 2
chrigelburri 3:92ba0254af87 3 Hallsensor::Hallsensor(
chrigelburri 3:92ba0254af87 4 PinName hall1,
chrigelburri 3:92ba0254af87 5 PinName hall2,
chrigelburri 3:92ba0254af87 6 PinName hall3
chrigelburri 3:92ba0254af87 7 )
chrigelburri 3:92ba0254af87 8 : hall1_(hall1),
chrigelburri 3:92ba0254af87 9 hall2_(hall2),
chrigelburri 3:92ba0254af87 10 hall3_(hall3)
chrigelburri 3:92ba0254af87 11 {
chrigelburri 3:92ba0254af87 12 pulses_ = 0;
chrigelburri 3:92ba0254af87 13
chrigelburri 3:92ba0254af87 14 //Workout what the current state is.
chrigelburri 3:92ba0254af87 15 int h1 = hall1_.read();
chrigelburri 3:92ba0254af87 16 int h2 = hall2_.read();
chrigelburri 3:92ba0254af87 17 int h3 = hall3_.read();
chrigelburri 3:92ba0254af87 18
chrigelburri 3:92ba0254af87 19 // Set the PullUp Resistor
chrigelburri 3:92ba0254af87 20 hall1_.mode(PullUp);
chrigelburri 3:92ba0254af87 21 hall2_.mode(PullUp);
chrigelburri 3:92ba0254af87 22 hall3_.mode(PullUp);
chrigelburri 3:92ba0254af87 23
chrigelburri 3:92ba0254af87 24 //set interrupts on only hall 1-3 rise and fall.
chrigelburri 3:92ba0254af87 25 hall1_.rise(this, &Hallsensor::encode);
chrigelburri 3:92ba0254af87 26 hall1_.fall(this, &Hallsensor::encode);
chrigelburri 3:92ba0254af87 27 hall2_.rise(this, &Hallsensor::encode);
chrigelburri 3:92ba0254af87 28 hall2_.fall(this, &Hallsensor::encode);
chrigelburri 3:92ba0254af87 29 hall3_.rise(this, &Hallsensor::encode);
chrigelburri 3:92ba0254af87 30 hall3_.fall(this, &Hallsensor::encode);
chrigelburri 3:92ba0254af87 31 }
chrigelburri 3:92ba0254af87 32
chrigelburri 3:92ba0254af87 33 void Hallsensor::reset(void)
chrigelburri 3:92ba0254af87 34 {
chrigelburri 3:92ba0254af87 35 pulses_ = 0;
chrigelburri 3:92ba0254af87 36 }
chrigelburri 3:92ba0254af87 37
chrigelburri 3:92ba0254af87 38 int Hallsensor::getPulses(void)
chrigelburri 3:92ba0254af87 39 {
chrigelburri 3:92ba0254af87 40 return pulses_;
chrigelburri 3:92ba0254af87 41 }
chrigelburri 3:92ba0254af87 42
chrigelburri 3:92ba0254af87 43
chrigelburri 3:92ba0254af87 44 void Hallsensor::encode(void)
chrigelburri 3:92ba0254af87 45 {
chrigelburri 3:92ba0254af87 46 // read the state
chrigelburri 3:92ba0254af87 47 int h1 = hall1_.read();
chrigelburri 3:92ba0254af87 48 int h2 = hall2_.read();
chrigelburri 3:92ba0254af87 49 int h3 = hall3_.read();
chrigelburri 3:92ba0254af87 50
chrigelburri 3:92ba0254af87 51 //3-bit state.
chrigelburri 3:92ba0254af87 52 currState_ = (h1 << 2) | (h2 << 1) | h3;
chrigelburri 3:92ba0254af87 53
chrigelburri 3:92ba0254af87 54 if ((prevState_ == 0x5) && (currState_ == 0x4)) {
chrigelburri 3:92ba0254af87 55 pulses_++;
chrigelburri 3:92ba0254af87 56 prevState_ = currState_;
chrigelburri 3:92ba0254af87 57 return;
chrigelburri 3:92ba0254af87 58 } else if (prevState_ == 0x5 && currState_ == 0x1) {
chrigelburri 3:92ba0254af87 59 pulses_--;
chrigelburri 3:92ba0254af87 60 prevState_ = currState_;
chrigelburri 3:92ba0254af87 61 return;
chrigelburri 3:92ba0254af87 62 }
chrigelburri 3:92ba0254af87 63
chrigelburri 3:92ba0254af87 64 if ((prevState_ == 0x4) && (currState_ == 0x6)) {
chrigelburri 3:92ba0254af87 65 pulses_++;
chrigelburri 3:92ba0254af87 66 prevState_ = currState_;
chrigelburri 3:92ba0254af87 67 return;
chrigelburri 3:92ba0254af87 68 } else if (prevState_ == 0x4 && currState_ == 0x5) {
chrigelburri 3:92ba0254af87 69 pulses_--;
chrigelburri 3:92ba0254af87 70 prevState_ = currState_;
chrigelburri 3:92ba0254af87 71 return;
chrigelburri 3:92ba0254af87 72 }
chrigelburri 3:92ba0254af87 73
chrigelburri 3:92ba0254af87 74 if ((prevState_ == 0x6) && (currState_ == 0x2)) {
chrigelburri 3:92ba0254af87 75 pulses_++;
chrigelburri 3:92ba0254af87 76 prevState_ = currState_;
chrigelburri 3:92ba0254af87 77 return;
chrigelburri 3:92ba0254af87 78 } else if (prevState_ == 0x6 && currState_ == 0x4) {
chrigelburri 3:92ba0254af87 79 pulses_--;
chrigelburri 3:92ba0254af87 80 prevState_ = currState_;
chrigelburri 3:92ba0254af87 81 return;
chrigelburri 3:92ba0254af87 82 }
chrigelburri 3:92ba0254af87 83
chrigelburri 3:92ba0254af87 84 if ((prevState_ == 0x2) && (currState_ == 0x3)) {
chrigelburri 3:92ba0254af87 85 pulses_++;
chrigelburri 3:92ba0254af87 86 prevState_ = currState_;
chrigelburri 3:92ba0254af87 87 return;
chrigelburri 3:92ba0254af87 88 } else if (prevState_ == 0x2 && currState_ == 0x6) {
chrigelburri 3:92ba0254af87 89 pulses_--;
chrigelburri 3:92ba0254af87 90 prevState_ = currState_;
chrigelburri 3:92ba0254af87 91 return;
chrigelburri 3:92ba0254af87 92 }
chrigelburri 3:92ba0254af87 93
chrigelburri 3:92ba0254af87 94 if ((prevState_ == 0x3) && (currState_ == 0x1)) {
chrigelburri 3:92ba0254af87 95 pulses_++;
chrigelburri 3:92ba0254af87 96 prevState_ = currState_;
chrigelburri 3:92ba0254af87 97 return;
chrigelburri 3:92ba0254af87 98 } else if (prevState_ == 0x3 && currState_ == 0x2) {
chrigelburri 3:92ba0254af87 99 pulses_--;
chrigelburri 3:92ba0254af87 100 prevState_ = currState_;
chrigelburri 3:92ba0254af87 101 return;
chrigelburri 3:92ba0254af87 102 }
chrigelburri 3:92ba0254af87 103
chrigelburri 3:92ba0254af87 104 if ((prevState_ == 0x1) && (currState_ == 0x5)) {
chrigelburri 3:92ba0254af87 105 pulses_++;
chrigelburri 3:92ba0254af87 106 prevState_ = currState_;
chrigelburri 3:92ba0254af87 107 return;
chrigelburri 3:92ba0254af87 108 } else if (prevState_ == 0x1 && currState_ == 0x3) {
chrigelburri 3:92ba0254af87 109 pulses_--;
chrigelburri 3:92ba0254af87 110 prevState_ = currState_;
chrigelburri 3:92ba0254af87 111 return;
chrigelburri 3:92ba0254af87 112 }
chrigelburri 3:92ba0254af87 113 prevState_ = currState_;
chrigelburri 3:92ba0254af87 114
chrigelburri 3:92ba0254af87 115 }