Tripple Controller for the TLE5206 H Bridge motor controller
inc/SimpleTLE5206Profiler.h@5:bfc5c5cc161e, 2011-07-05 (annotated)
- Committer:
- AjK
- Date:
- Tue Jul 05 16:08:38 2011 +0000
- Revision:
- 5:bfc5c5cc161e
- Parent:
- 4:d69f22061c03
0.7 Beta See ChangeLog.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AjK | 3:b7d951c6f551 | 1 | /* |
AjK | 3:b7d951c6f551 | 2 | Copyright (c) 2011 Andy Kirkham |
AjK | 3:b7d951c6f551 | 3 | |
AjK | 3:b7d951c6f551 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
AjK | 3:b7d951c6f551 | 5 | of this software and associated documentation files (the "Software"), to deal |
AjK | 3:b7d951c6f551 | 6 | in the Software without restriction, including without limitation the rights |
AjK | 3:b7d951c6f551 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
AjK | 3:b7d951c6f551 | 8 | copies of the Software, and to permit persons to whom the Software is |
AjK | 3:b7d951c6f551 | 9 | furnished to do so, subject to the following conditions: |
AjK | 3:b7d951c6f551 | 10 | |
AjK | 3:b7d951c6f551 | 11 | The above copyright notice and this permission notice shall be included in |
AjK | 3:b7d951c6f551 | 12 | all copies or substantial portions of the Software. |
AjK | 3:b7d951c6f551 | 13 | |
AjK | 3:b7d951c6f551 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
AjK | 3:b7d951c6f551 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
AjK | 3:b7d951c6f551 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
AjK | 3:b7d951c6f551 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
AjK | 3:b7d951c6f551 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
AjK | 3:b7d951c6f551 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
AjK | 3:b7d951c6f551 | 20 | THE SOFTWARE. |
AjK | 3:b7d951c6f551 | 21 | */ |
AjK | 3:b7d951c6f551 | 22 | |
AjK | 3:b7d951c6f551 | 23 | |
AjK | 3:b7d951c6f551 | 24 | #ifndef AJK_SIMPLETLE5206PROFILER_H |
AjK | 3:b7d951c6f551 | 25 | #define AJK_SIMPLETLE5206PROFILER_H |
AjK | 3:b7d951c6f551 | 26 | |
AjK | 3:b7d951c6f551 | 27 | #include "mbed.h" |
AjK | 3:b7d951c6f551 | 28 | #include "SimpleTLE5206.h" |
AjK | 3:b7d951c6f551 | 29 | |
AjK | 3:b7d951c6f551 | 30 | namespace AjK { |
AjK | 3:b7d951c6f551 | 31 | |
AjK | 3:b7d951c6f551 | 32 | class SimpleTLE5206Profiler : public SimpleTLE5206 { |
AjK | 3:b7d951c6f551 | 33 | |
AjK | 3:b7d951c6f551 | 34 | protected: |
AjK | 3:b7d951c6f551 | 35 | Ticker _poll; |
AjK | 3:b7d951c6f551 | 36 | double _desired_speed; |
AjK | 3:b7d951c6f551 | 37 | double _actual_speed; |
AjK | 3:b7d951c6f551 | 38 | double _accel_rate; |
AjK | 3:b7d951c6f551 | 39 | double _decel_rate; |
AjK | 3:b7d951c6f551 | 40 | int _poll_interval; |
AjK | 3:b7d951c6f551 | 41 | |
AjK | 3:b7d951c6f551 | 42 | void poll(void) |
AjK | 3:b7d951c6f551 | 43 | { |
AjK | 3:b7d951c6f551 | 44 | if (_actual_speed < _desired_speed) { |
AjK | 3:b7d951c6f551 | 45 | _actual_speed += _accel_rate; |
AjK | 3:b7d951c6f551 | 46 | if (_actual_speed > _desired_speed) { |
AjK | 3:b7d951c6f551 | 47 | _actual_speed = _desired_speed; |
AjK | 3:b7d951c6f551 | 48 | } |
AjK | 3:b7d951c6f551 | 49 | SimpleTLE5206::setSpeed(_actual_speed); |
AjK | 3:b7d951c6f551 | 50 | } |
AjK | 3:b7d951c6f551 | 51 | if (_actual_speed > _desired_speed) { |
AjK | 3:b7d951c6f551 | 52 | _actual_speed -= _decel_rate; |
AjK | 3:b7d951c6f551 | 53 | if (_actual_speed < _desired_speed) { |
AjK | 3:b7d951c6f551 | 54 | _actual_speed = _desired_speed; |
AjK | 3:b7d951c6f551 | 55 | } |
AjK | 3:b7d951c6f551 | 56 | SimpleTLE5206::setSpeed(_actual_speed); |
AjK | 3:b7d951c6f551 | 57 | } |
AjK | 3:b7d951c6f551 | 58 | } |
AjK | 3:b7d951c6f551 | 59 | |
AjK | 3:b7d951c6f551 | 60 | public: |
AjK | 3:b7d951c6f551 | 61 | |
AjK | 3:b7d951c6f551 | 62 | friend class Ticker; |
AjK | 3:b7d951c6f551 | 63 | |
AjK | 3:b7d951c6f551 | 64 | SimpleTLE5206Profiler(SimpleTLE5206Output *in1, SimpleTLE5206Output *in2, int duty_cycle_hz) : |
AjK | 3:b7d951c6f551 | 65 | SimpleTLE5206(in1, in2, duty_cycle_hz) |
AjK | 3:b7d951c6f551 | 66 | { |
AjK | 3:b7d951c6f551 | 67 | _desired_speed = 0.0; |
AjK | 3:b7d951c6f551 | 68 | _actual_speed = 0.0; |
AjK | 3:b7d951c6f551 | 69 | _accel_rate = 0.01; |
AjK | 3:b7d951c6f551 | 70 | _decel_rate = 0.01; |
AjK | 3:b7d951c6f551 | 71 | _poll_interval = 10000; // 10ms |
AjK | 3:b7d951c6f551 | 72 | _poll.attach_us(this, &SimpleTLE5206Profiler::poll, _poll_interval); |
AjK | 3:b7d951c6f551 | 73 | } |
AjK | 3:b7d951c6f551 | 74 | |
AjK | 3:b7d951c6f551 | 75 | int getPollInterval(void) { return _poll_interval; } |
AjK | 3:b7d951c6f551 | 76 | void setPollInterval(int i) |
AjK | 3:b7d951c6f551 | 77 | { |
AjK | 3:b7d951c6f551 | 78 | _poll_interval = i; |
AjK | 3:b7d951c6f551 | 79 | _poll.detach(); |
AjK | 3:b7d951c6f551 | 80 | _poll.attach_us(this, &SimpleTLE5206Profiler::poll, _poll_interval); |
AjK | 3:b7d951c6f551 | 81 | } |
AjK | 3:b7d951c6f551 | 82 | |
AjK | 3:b7d951c6f551 | 83 | void setAccelRate(double rate) { _accel_rate = rate; } |
AjK | 3:b7d951c6f551 | 84 | double getAccelRate(void) { return _accel_rate; } |
AjK | 3:b7d951c6f551 | 85 | |
AjK | 3:b7d951c6f551 | 86 | void setDecelRate(double rate) { _decel_rate = rate; } |
AjK | 3:b7d951c6f551 | 87 | double getDecelRate(void) { return _decel_rate; } |
AjK | 3:b7d951c6f551 | 88 | |
AjK | 3:b7d951c6f551 | 89 | void setSpeed(double demand_speed) |
AjK | 3:b7d951c6f551 | 90 | { |
AjK | 3:b7d951c6f551 | 91 | _desired_speed = demand_speed; |
AjK | 3:b7d951c6f551 | 92 | } |
AjK | 3:b7d951c6f551 | 93 | |
AjK | 3:b7d951c6f551 | 94 | double getSpeed(void) { return _actual_speed; } |
AjK | 3:b7d951c6f551 | 95 | |
AjK | 3:b7d951c6f551 | 96 | void eStop(void) |
AjK | 3:b7d951c6f551 | 97 | { |
AjK | 4:d69f22061c03 | 98 | _desired_speed = _actual_speed = 0.0; |
AjK | 3:b7d951c6f551 | 99 | SimpleTLE5206::setSpeed(_desired_speed); |
AjK | 3:b7d951c6f551 | 100 | } |
AjK | 3:b7d951c6f551 | 101 | |
AjK | 3:b7d951c6f551 | 102 | |
AjK | 3:b7d951c6f551 | 103 | }; |
AjK | 3:b7d951c6f551 | 104 | |
AjK | 3:b7d951c6f551 | 105 | }; // namespace AjK ends. |
AjK | 3:b7d951c6f551 | 106 | |
AjK | 3:b7d951c6f551 | 107 | |
AjK | 3:b7d951c6f551 | 108 | #endif |