00001 #ifndef STAUBLIRX130_NAXES_VELOCITY_CONTROLLER_HPP
00002 #define STAUBLIRX130_NAXES_VELOCITY_CONTROLLER_HPP
00003
00004 #include <vector>
00005 #include <rtt/RTT.hpp>
00006
00007 #include <rtt/TaskContext.hpp>
00008 #include <rtt/Ports.hpp>
00009 #include <rtt/Event.hpp>
00010 #include <rtt/Properties.hpp>
00011 #include <rtt/Command.hpp>
00012
00013 #if defined (OROPKG_OS_LXRT)
00014 #include <rtt/dev/AnalogOutput.hpp>
00015 #include <rtt/dev/DigitalOutput.hpp>
00016 #include <rtt/dev/DigitalInput.hpp>
00017
00018 #include "dev/ComediDevice.hpp"
00019 #include "dev/ComediSubDeviceAOut.hpp"
00020 #include "dev/ComediSubDeviceDOut.hpp"
00021 #include "dev/ComediSubDeviceDIn.hpp"
00022 #include "dev/ComediEncoder.hpp"
00023
00024 #include "dev/IncrementalEncoderSensor.hpp"
00025 #include "dev/AnalogDrive.hpp"
00026 #include "dev/Axis.hpp"
00027
00028 #include <termios.h>
00029
00030 #endif
00031 #include "dev/SimulationAxis.hpp"
00032 #include <rtt/dev/AxisInterface.hpp>
00033
00034 #include <ocl/OCL.hpp>
00035 #include <ocl/VectorTemplateComposition.hpp>
00036
00037 #include <kdl/chain.hpp>
00038
00039 namespace OCL
00040 {
00051 class StaubliRX130nAxesVelocityController : public TaskContext
00052 {
00053 public:
00062 StaubliRX130nAxesVelocityController(std::string name);
00063 virtual ~StaubliRX130nAxesVelocityController();
00064
00065 protected:
00075 Method<bool(void)> startAllAxes_mtd;
00076
00087 Method<bool(void)> stopAllAxes_mtd;
00088
00096 Method<bool(void)> unlockAllAxes_mtd;
00097
00106 Method<bool(void)> lockAllAxes_mtd;
00107
00118 Command<bool(void)> prepareForUse_cmd;
00119
00124 Command<bool(void)> prepareForShutdown_cmd;
00125
00135 Method<bool(std::vector<double>)> addDriveOffset_mtd;
00136
00142 DataPort<std::vector<double> > driveValues_port;
00143 DataPort<std::vector<double> > servoValues_port;
00144
00151 DataPort<std::vector<double> > positionValues_port;
00152 DataPort<std::vector<double> > velocityValues_port;
00153 DataPort< double > deltaTime_port;
00154
00160 Property<std::vector <double> > driveLimits_prop;
00161
00165 Property<std::vector <double> > lowerPositionLimits_prop;
00166
00170 Property<std::vector <double> > upperPositionLimits_prop;
00171
00175 Property<std::vector <double> > velocityLimits_prop;
00176
00181 Property<std::vector <double> > initialPosition_prop;
00182
00187 Property<std::vector <double> > driveOffset_prop;
00188
00192 Property<bool > simulation_prop;
00193 bool simulation;
00194
00195
00199 Constant<unsigned int> num_axes_attr;
00200
00204 Attribute<KDL::Chain> chain_attr;
00205 KDL::Chain kinematics;
00206
00212 Event< void(std::string) > driveOutOfRange_evt;
00213
00220 Event< void(std::string) > positionOutOfRange_evt;
00221 Event< void(std::string) > velocityOutOfRange_evt;
00222
00223 Property<std::vector<double> > servoIntegrationFactor_prop;
00224 Property<std::vector<double> > servoGain_prop;
00225 Property<std::vector<double> > servoFFScale_prop;
00226
00230 Property<std::vector<std::string> > EmergencyEvents_prop;
00231
00232
00233
00234 private:
00235 bool readAbsolutePosition(std::vector<double>& initPos);
00236
00237 virtual bool startAllAxes();
00238 virtual bool stopAllAxes();
00239 virtual bool lockAllAxes();
00240 virtual bool unlockAllAxes();
00241 virtual bool addDriveOffset(const std::vector<double>& offset);
00242 virtual bool prepareForUse();
00243 virtual bool prepareForUseCompleted() const;
00244 virtual bool prepareForShutdown();
00245 virtual bool prepareForShutdownCompleted() const;
00246
00247 void EmergencyStop(std::string message)
00248 {
00249 log(Error) << "---------------------------------------------" << endlog();
00250 log(Error) << "--------- EMERGENCY STOP --------------------" << endlog();
00251 log(Error) << "---------------------------------------------" << endlog();
00252 log(Error) << message << endlog();
00253 this->fatal();
00254 };
00255 std::vector<RTT::Handle> EmergencyEventHandlers;
00256
00260 bool activated;
00261
00267 std::vector<double> positionConvertFactor;
00268
00269
00275 std::vector<double> driveConvertFactor;
00276
00277
00279 std::vector<double> positionValues, driveValues, velocityValues;
00281 std::vector<double> servoIntError,outputvel;
00282 std::vector<double> servoIntegrationFactor,servoGain,servoFFScale;
00283
00284 bool servoInitialized;
00285 RTT::TimeService::ticks previousTime;
00286
00287 public:
00288
00289 virtual bool configureHook();
00290 virtual bool startHook();
00291 virtual void updateHook();
00292 virtual void stopHook();
00293 virtual void cleanupHook();
00294
00295 KDL::Chain getKinematics(){
00296 return kinematics;
00297 };
00298
00299 private:
00300
00301
00302
00303
00304 #if (defined (OROPKG_OS_LXRT))
00305 std::vector<Axis*> axes_hardware;
00306
00307 ComediDevice* AOut;
00308 ComediDevice* DInOut;
00309 ComediDevice* Encoder;
00310
00311 AnalogOutInterface* SubAOut;
00312 DigitalInInterface* SubDIn;
00313 DigitalOutInterface* SubDOut;
00314
00315 std::vector<EncoderInterface*> encoderInterface;
00316 std::vector<IncrementalEncoderSensor*> encoder;
00317 std::vector<AnalogOutput*> vref;
00318 std::vector<DigitalOutput*> enable;
00319 std::vector<AnalogDrive*> drive;
00320 DigitalOutput* brakeOff;
00321 DigitalOutput* highPowerEnable;
00322 DigitalInput* eStop;
00323 std::vector<DigitalInput*> driveFailure;
00324 DigitalInput* armPowerOn;
00325
00326 const char* port;
00327 struct termios tio;
00328 int fd;
00329
00330 #endif
00331 std::vector<AxisInterface*> axes;
00332 std::vector<TimeService::ticks> _previous_time;
00333 TimeService::Seconds _delta_time;
00334 std::vector<double> init_pos;
00335 };
00336 }
00337 #endif // STAUBLIRX130NAXESVELOCITYCONTROLLER