Tripple Controller for the TLE5206 H Bridge motor controller
Embed:
(wiki syntax)
Show/hide line numbers
SimpleTLE5206Profiler.h
00001 /* 00002 Copyright (c) 2011 Andy Kirkham 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 */ 00022 00023 00024 #ifndef AJK_SIMPLETLE5206PROFILER_H 00025 #define AJK_SIMPLETLE5206PROFILER_H 00026 00027 #include "mbed.h" 00028 #include "SimpleTLE5206.h" 00029 00030 namespace AjK { 00031 00032 class SimpleTLE5206Profiler : public SimpleTLE5206 { 00033 00034 protected: 00035 Ticker _poll; 00036 double _desired_speed; 00037 double _actual_speed; 00038 double _accel_rate; 00039 double _decel_rate; 00040 int _poll_interval; 00041 00042 void poll(void) 00043 { 00044 if (_actual_speed < _desired_speed) { 00045 _actual_speed += _accel_rate; 00046 if (_actual_speed > _desired_speed) { 00047 _actual_speed = _desired_speed; 00048 } 00049 SimpleTLE5206::setSpeed(_actual_speed); 00050 } 00051 if (_actual_speed > _desired_speed) { 00052 _actual_speed -= _decel_rate; 00053 if (_actual_speed < _desired_speed) { 00054 _actual_speed = _desired_speed; 00055 } 00056 SimpleTLE5206::setSpeed(_actual_speed); 00057 } 00058 } 00059 00060 public: 00061 00062 friend class Ticker; 00063 00064 SimpleTLE5206Profiler(SimpleTLE5206Output *in1, SimpleTLE5206Output *in2, int duty_cycle_hz) : 00065 SimpleTLE5206(in1, in2, duty_cycle_hz) 00066 { 00067 _desired_speed = 0.0; 00068 _actual_speed = 0.0; 00069 _accel_rate = 0.01; 00070 _decel_rate = 0.01; 00071 _poll_interval = 10000; // 10ms 00072 _poll.attach_us(this, &SimpleTLE5206Profiler::poll, _poll_interval); 00073 } 00074 00075 int getPollInterval(void) { return _poll_interval; } 00076 void setPollInterval(int i) 00077 { 00078 _poll_interval = i; 00079 _poll.detach(); 00080 _poll.attach_us(this, &SimpleTLE5206Profiler::poll, _poll_interval); 00081 } 00082 00083 void setAccelRate(double rate) { _accel_rate = rate; } 00084 double getAccelRate(void) { return _accel_rate; } 00085 00086 void setDecelRate(double rate) { _decel_rate = rate; } 00087 double getDecelRate(void) { return _decel_rate; } 00088 00089 void setSpeed(double demand_speed) 00090 { 00091 _desired_speed = demand_speed; 00092 } 00093 00094 double getSpeed(void) { return _actual_speed; } 00095 00096 void eStop(void) 00097 { 00098 _desired_speed = _actual_speed = 0.0; 00099 SimpleTLE5206::setSpeed(_desired_speed); 00100 } 00101 00102 00103 }; 00104 00105 }; // namespace AjK ends. 00106 00107 00108 #endif
Generated on Tue Jul 12 2022 21:37:53 by 1.7.2