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
Fork of autonomous Robot Android by
Actuators/MaxonESCON.cpp@3:92ba0254af87, 2013-03-07 (annotated)
- Committer:
- chrigelburri
- Date:
- Thu Mar 07 09:47:07 2013 +0000
- Revision:
- 3:92ba0254af87
- Parent:
- Actuators/MaxonESCON/MaxonESCON.cpp@2:d8e1613dc38b
- Child:
- 6:48eeb41188dd
bitte kommentare korriegieren;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chrigelburri | 0:31f7be68e52d | 1 | #include "MaxonESCON.h" |
chrigelburri | 0:31f7be68e52d | 2 | |
chrigelburri | 0:31f7be68e52d | 3 | using namespace std; |
chrigelburri | 0:31f7be68e52d | 4 | |
chrigelburri | 0:31f7be68e52d | 5 | MaxonESCON::MaxonESCON( |
chrigelburri | 0:31f7be68e52d | 6 | PinName enb, |
chrigelburri | 0:31f7be68e52d | 7 | PinName isenb, |
chrigelburri | 0:31f7be68e52d | 8 | PinName pwm, |
chrigelburri | 0:31f7be68e52d | 9 | PinName actualSpeed, |
chrigelburri | 0:31f7be68e52d | 10 | Hallsensor *hall |
chrigelburri | 0:31f7be68e52d | 11 | ) |
chrigelburri | 0:31f7be68e52d | 12 | : |
chrigelburri | 0:31f7be68e52d | 13 | _enb(enb), |
chrigelburri | 0:31f7be68e52d | 14 | _isenb(isenb), |
chrigelburri | 0:31f7be68e52d | 15 | _pwm(pwm), |
chrigelburri | 0:31f7be68e52d | 16 | _actualSpeed(actualSpeed), |
chrigelburri | 0:31f7be68e52d | 17 | _hall(hall) |
chrigelburri | 0:31f7be68e52d | 18 | { |
chrigelburri | 0:31f7be68e52d | 19 | |
chrigelburri | 0:31f7be68e52d | 20 | _pwm = 0; |
chrigelburri | 0:31f7be68e52d | 21 | |
chrigelburri | 0:31f7be68e52d | 22 | // Initial condition of output enables |
chrigelburri | 0:31f7be68e52d | 23 | _enb = 0; |
chrigelburri | 0:31f7be68e52d | 24 | |
chrigelburri | 0:31f7be68e52d | 25 | // Set initial condition of PWM 2kHz |
chrigelburri | 0:31f7be68e52d | 26 | period(0.0005); |
chrigelburri | 0:31f7be68e52d | 27 | |
chrigelburri | 0:31f7be68e52d | 28 | // Set the pulses to zero |
chrigelburri | 0:31f7be68e52d | 29 | _pulses = 0; |
chrigelburri | 2:d8e1613dc38b | 30 | |
chrigelburri | 0:31f7be68e52d | 31 | // Set the Pull Up Resistor |
chrigelburri | 0:31f7be68e52d | 32 | _isenb.mode(PullUp); |
chrigelburri | 0:31f7be68e52d | 33 | } |
chrigelburri | 0:31f7be68e52d | 34 | |
chrigelburri | 0:31f7be68e52d | 35 | void MaxonESCON::setVelocity(float speed) |
chrigelburri | 0:31f7be68e52d | 36 | { |
chrigelburri | 0:31f7be68e52d | 37 | speed = speed / ESCON_SET_FACTOR * 60.0f; |
chrigelburri | 0:31f7be68e52d | 38 | if(speed > 1 ) { |
chrigelburri | 0:31f7be68e52d | 39 | _pwm = 0.9f; |
chrigelburri | 0:31f7be68e52d | 40 | } else if(speed < -1) { |
chrigelburri | 0:31f7be68e52d | 41 | _pwm = 0.1f; |
chrigelburri | 0:31f7be68e52d | 42 | } else { |
chrigelburri | 0:31f7be68e52d | 43 | _pwm = 0.4f*speed + 0.5f; |
chrigelburri | 0:31f7be68e52d | 44 | } |
chrigelburri | 0:31f7be68e52d | 45 | } |
chrigelburri | 0:31f7be68e52d | 46 | |
chrigelburri | 0:31f7be68e52d | 47 | float MaxonESCON::getActualSpeed(void) |
chrigelburri | 0:31f7be68e52d | 48 | { |
chrigelburri | 0:31f7be68e52d | 49 | return (_actualSpeed.read()* 2.0f - 1.0f) * ESCON_GET_FACTOR / 60.0f; |
chrigelburri | 0:31f7be68e52d | 50 | } |
chrigelburri | 0:31f7be68e52d | 51 | |
chrigelburri | 0:31f7be68e52d | 52 | void MaxonESCON::period(float period) |
chrigelburri | 0:31f7be68e52d | 53 | { |
chrigelburri | 0:31f7be68e52d | 54 | _pwm.period(period); |
chrigelburri | 0:31f7be68e52d | 55 | } |
chrigelburri | 0:31f7be68e52d | 56 | |
chrigelburri | 0:31f7be68e52d | 57 | void MaxonESCON::enable(bool enb) |
chrigelburri | 0:31f7be68e52d | 58 | { |
chrigelburri | 0:31f7be68e52d | 59 | if(enb == false) { |
chrigelburri | 1:6cd533a712c6 | 60 | _enb = 1; |
chrigelburri | 0:31f7be68e52d | 61 | } else { |
chrigelburri | 1:6cd533a712c6 | 62 | _enb = 0; |
chrigelburri | 0:31f7be68e52d | 63 | } |
chrigelburri | 0:31f7be68e52d | 64 | } |
chrigelburri | 0:31f7be68e52d | 65 | |
chrigelburri | 0:31f7be68e52d | 66 | bool MaxonESCON::isEnabled() |
chrigelburri | 0:31f7be68e52d | 67 | { |
chrigelburri | 0:31f7be68e52d | 68 | if(_isenb.read() == 1) { |
chrigelburri | 2:d8e1613dc38b | 69 | return true; |
chrigelburri | 2:d8e1613dc38b | 70 | } else { |
chrigelburri | 2:d8e1613dc38b | 71 | return false; |
chrigelburri | 2:d8e1613dc38b | 72 | } |
chrigelburri | 0:31f7be68e52d | 73 | } |
chrigelburri | 0:31f7be68e52d | 74 | |
chrigelburri | 0:31f7be68e52d | 75 | int MaxonESCON::getPulses(void) |
chrigelburri | 0:31f7be68e52d | 76 | { |
chrigelburri | 0:31f7be68e52d | 77 | _pulses = _hall->getPulses(); |
chrigelburri | 0:31f7be68e52d | 78 | return _pulses; |
chrigelburri | 0:31f7be68e52d | 79 | } |
chrigelburri | 0:31f7be68e52d | 80 | |
chrigelburri | 0:31f7be68e52d | 81 | int MaxonESCON::setPulses(int setPos) |
chrigelburri | 0:31f7be68e52d | 82 | { |
chrigelburri | 0:31f7be68e52d | 83 | _hall->reset(); |
chrigelburri | 0:31f7be68e52d | 84 | _pulses = _hall->getPulses(); |
chrigelburri | 0:31f7be68e52d | 85 | return _pulses; |
chrigelburri | 0:31f7be68e52d | 86 | } |