00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "Axis.hpp"
00029 #include "rtt/dev/DigitalInput.hpp"
00030 #include "rtt/dev/DigitalOutput.hpp"
00031 #include "rtt/dev/DriveInterface.hpp"
00032
00033
00034 namespace OCL
00035 {
00036
00037
00038 Axis::Axis( DriveInterface* a )
00039 : _drive_value(0), act( a ), brakeswitch(0),
00040 _is_locked(false), _is_stopped(false), _is_driven(true)
00041 {
00042 stop();
00043 lock();
00044 }
00045
00046 Axis::~Axis()
00047 {
00048 stop();
00049 lock();
00050
00051 delete act;
00052 delete brakeswitch;
00053 for (SensList::iterator it = sens.begin(); it != sens.end(); ++it)
00054 delete it->second;
00055 }
00056
00057
00058 bool Axis::drive( double vel )
00059 {
00060
00061 if ( !act->isEnabled() )
00062 return false;
00063
00064
00065 if ( brakeswitch && brakeswitch->isOn() )
00066 return false;
00067
00068 if (_is_stopped || _is_driven)
00069 {
00070 act->driveSet( vel );
00071 _drive_value = vel;
00072 _is_stopped = false;
00073 _is_driven = true;
00074 return true;
00075 }
00076 else
00077 return false;
00078
00079 }
00080
00081
00082 bool Axis::stop()
00083 {
00084 if (_is_driven){
00085 act->driveSet( 0 );
00086 _drive_value = 0;
00087 _is_driven = false;
00088 _is_stopped = true;
00089 return true;
00090 }
00091 else if (_is_stopped)
00092 return true;
00093 else
00094 return false;
00095 }
00096
00097
00098 bool Axis::lock()
00099 {
00100 if (_is_stopped){
00101 if ( brakeswitch )
00102 brakeswitch->switchOn();
00103 act->disableDrive();
00104 _is_locked = true;
00105 _is_stopped = false;
00106 return true;
00107 }
00108 else if (_is_locked)
00109 return true;
00110 else
00111 return false;
00112 }
00113
00114
00115 bool Axis::unlock()
00116 {
00117 if (_is_locked){
00118 if ( brakeswitch )
00119 brakeswitch->switchOff();
00120 act->enableDrive();
00121 act->driveSet( 0 );
00122 _drive_value = 0;
00123 _is_locked = false;
00124 _is_stopped = true;
00125 return true;
00126 }
00127 else if (_is_stopped)
00128 return true;
00129 else
00130 return false;
00131 }
00132
00133
00134
00135 bool Axis::isLocked() const
00136 {
00137 return _is_locked;
00138 }
00139
00140
00141 bool Axis::isStopped() const
00142 {
00143 return _is_stopped;
00144 }
00145
00146
00147 bool Axis::isDriven() const
00148 {
00149 return _is_driven;
00150 }
00151
00152
00153 void Axis::limitDrive( double lower, double higher, const Event<void(std::string)>& ev)
00154 {
00155 act->limit(lower, higher, ev);
00156 }
00157
00158
00159 void Axis::setSensor(const std::string& name, SensorInterface<double>* _sens)
00160 {
00161 if (sens.count(name) != 0)
00162 return;
00163 sens.insert(make_pair(name, _sens) );
00164 }
00165
00166 SensorInterface<double>* Axis::getSensor(const std::string& name) const
00167 {
00168 if (sens.count(name) == 0)
00169 return 0;
00170 else
00171 return sens.find(name)->second;
00172 }
00173
00174 std::vector<std::string> Axis::sensorList() const
00175 {
00176 std::vector<std::string> result;
00177 for (SensList::const_iterator it = sens.begin(); it != sens.end(); ++it)
00178 result.push_back( it->first );
00179 return result;
00180 }
00181
00182 void Axis::setSwitch(const std::string& name, DigitalInput* _swtch)
00183 {
00184 if (swtch.count(name) != 0)
00185 return;
00186 swtch.insert(make_pair(name, _swtch) );
00187 }
00188
00189 DigitalInput* Axis::getSwitch(const std::string& name) const
00190 {
00191 if (swtch.count(name) == 0)
00192 return 0;
00193 else
00194 return swtch.find(name)->second;
00195 }
00196
00197 std::vector<std::string> Axis::switchList() const
00198 {
00199 std::vector<std::string> result;
00200 for (SwitchList::const_iterator it = swtch.begin(); it != swtch.end(); ++it)
00201 result.push_back( it->first );
00202 return result;
00203 }
00204
00205 void Axis::setCounter(const std::string& name, SensorInterface<int>* _count)
00206 {
00207 if (count.count(name) != 0)
00208 return;
00209 count.insert(make_pair(name, _count) );
00210 }
00211
00212 SensorInterface<int>* Axis::getCounter(const std::string& name) const
00213 {
00214 if (count.count(name) == 0)
00215 return 0;
00216 else
00217 return count.find(name)->second;
00218 }
00219
00220 std::vector<std::string> Axis::counterList() const
00221 {
00222 std::vector<std::string> result;
00223 for (CountList::const_iterator it = count.begin(); it != count.end(); ++it)
00224 result.push_back( it->first );
00225 return result;
00226 }
00227
00228 DriveInterface* Axis::getDrive() const
00229 {
00230 return act;
00231 }
00232
00233 double Axis::getDriveValue() const
00234 {
00235 return _drive_value;
00236 }
00237
00238 void Axis::setDrive(DriveInterface* a)
00239 {
00240 delete act;
00241 act = a;
00242 }
00243
00244 void Axis::setBrake( DigitalOutput* brk )
00245 {
00246 delete brakeswitch;
00247 brakeswitch = brk;
00248 }
00249
00250 DigitalOutput* Axis::getBrake()
00251 { return brakeswitch; }
00252
00253 DigitalOutput* Axis::getEnable()
00254 { return act->getEnable(); }
00255 }