00001 #ifndef PERFORMERMK2_NAXES_VELOCITY_CONTROLLER_HPP
00002 #define PERFORMERMK2_NAXES_VELOCITY_CONTROLLER_HPP
00003
00004 #include <vector>
00005 #include <deque>
00006 #include <rtt/RTT.hpp>
00007
00008 #include <rtt/TaskContext.hpp>
00009 #include <rtt/Ports.hpp>
00010 #include <rtt/Event.hpp>
00011 #include <rtt/Properties.hpp>
00012 #include <rtt/Command.hpp>
00013
00014 #if defined (OROPKG_OS_LXRT)
00015 #include <rtt/dev/AnalogOutput.hpp>
00016 #include <rtt/dev/DigitalOutput.hpp>
00017 #include <rtt/dev/DigitalInput.hpp>
00018
00019 #include "dev/ComediDevice.hpp"
00020 #include "dev/ComediSubDeviceAOut.hpp"
00021 #include "dev/ComediSubDeviceDOut.hpp"
00022 #include "dev/ComediSubDeviceDIn.hpp"
00023 #include "dev/ComediEncoder.hpp"
00024
00025 #include "dev/IncrementalEncoderSensor.hpp"
00026 #include "dev/AnalogDrive.hpp"
00027 #include "dev/Axis.hpp"
00028
00029 #include <termios.h>
00030
00031 #endif
00032 #include "dev/SimulationAxis.hpp"
00033 #include <rtt/dev/AxisInterface.hpp>
00034
00035 #include <ocl/OCL.hpp>
00036
00037 #include <kdl/chain.hpp>
00038
00039 namespace OCL
00040 {
00051 class PerformerMK2nAxesVelocityController : public TaskContext
00052 {
00053 public:
00062 PerformerMK2nAxesVelocityController(std::string name,std::string propertyfilename="cpf/PerformerMK2nAxesVelocityController.cpf");
00063 virtual ~PerformerMK2nAxesVelocityController();
00064
00065 protected:
00066
00067
00068 Method<bool(int)> resetController_mtd;
00083 Method<bool(void)> startAllAxes_mtd;
00084
00095 Method<bool(void)> stopAllAxes_mtd;
00096
00104 Method<bool(void)> unlockAllAxes_mtd;
00105
00114 Method<bool(void)> lockAllAxes_mtd;
00115
00126 Command<bool(void)> prepareForUse_cmd;
00127
00132 Command<bool(void)> prepareForShutdown_cmd;
00133
00143 Method<bool(std::vector<double>)> addDriveOffset_mtd;
00144
00155 Method<bool(int)> _initPosition;
00156
00162 DataPort<std::vector<double> > driveValues_port;
00163 DataPort<std::vector<double> > servoValues_port;
00164
00171 DataPort<std::vector<double> > positionValues_port;
00172 DataPort<std::vector<double> > velocityValues_port;
00173 DataPort<std::vector<double> > jValues_port;
00174 DataPort<std::vector<double> > homingSwitchValues_port;
00175 DataPort< double > deltaTime_port;
00176
00182 Property<std::vector <double> > driveLimits_prop;
00183
00187 Property<std::vector <double> > lowerPositionLimits_prop;
00188
00192 Property<std::vector <double> > upperPositionLimits_prop;
00193
00197 Property<std::vector <double> > velocityLimits_prop;
00198
00203 Property<std::vector <double> > initialPosition_prop;
00204
00209 Property<std::vector <double> > driveOffset_prop;
00210
00214 Property<bool > simulation_prop;
00215 bool simulation;
00216
00217 Property<std::vector<double> > servoIntegrationFactor_prop;
00218 Property<std::vector<double> > servoGain_prop;
00219 Property<std::vector<double> > servoFFScale_prop;
00220 Property<std::vector<double> > PIDkp_prop;
00221 Property<std::vector<double> > PIDTi_prop;
00222 Property<std::vector<double> > PIDTd_prop;
00223
00227 Constant<unsigned int> num_axes_attr;
00228
00232 Attribute<KDL::Chain> chain_attr;
00233 KDL::Chain kinematics;
00234
00240 Event< void(std::string) > driveOutOfRange_evt;
00241
00248 Event< void(std::string) > positionOutOfRange_evt;
00249 Event< void(std::string) > velocityOutOfRange_evt;
00250
00251 private:
00252
00253 virtual bool resetController(const int& axis_id);
00254 virtual bool startAllAxes();
00255 virtual bool stopAllAxes();
00256 virtual bool lockAllAxes();
00257 virtual bool unlockAllAxes();
00258 virtual bool addDriveOffset(const std::vector<double>& offset);
00259 virtual bool initPosition(int axis);
00260 virtual bool initPositionCompleted(int axis) const;
00261 virtual bool prepareForUse();
00262 virtual bool prepareForUseCompleted() const;
00263 virtual bool prepareForShutdown();
00264 virtual bool prepareForShutdownCompleted() const;
00265
00270 const std::string propertyfile;
00271
00275 bool activated;
00276
00282 std::vector<double> positionConvertFactor;
00283
00284
00290 std::vector<double> driveConvertFactor;
00291
00292
00294 std::vector<double> positionValues, driveValues, velocityValues, jValues;
00295 std::deque<double> positionDeque_axis1, positionDeque_axis2, positionDeque_axis3, positionDeque_axis4, positionDeque_axis5, timeDeque;
00296 std::vector<double> homingSwitchValues;
00298 std::vector<double> servoIntError,outputvel;
00299 std::vector<double> servoIntegrationFactor,servoGain,servoFFScale, PIDkp, PIDTi, PIDTd;
00300 std::vector<double> outputvel_kmin1,outputvel_kmin2,velocity_error_k,velocity_error_kmin1,velocity_error_kmin2,position_error_k,position_desired_k;
00301 bool servoInitialized;
00302 RTT::TimeService::ticks previousTime;
00303
00304 public:
00305
00306 virtual bool configureHook();
00307 virtual bool startHook();
00308 virtual void updateHook();
00309 virtual void stopHook();
00310 virtual void cleanupHook();
00311
00312 KDL::Chain getKinematics(){
00313 return kinematics;
00314 };
00315
00316 private:
00317
00318
00319
00320
00321 #if (defined (OROPKG_OS_LXRT))
00322 std::vector<Axis*> axes_hardware;
00323
00324 ComediDevice* NI6713;
00325 ComediDevice* NI6602;
00326
00327 ComediSubDeviceAOut* SubAOut_NI6713;
00328 ComediSubDeviceDIn* SubDIn_NI6713;
00329 ComediSubDeviceDOut* SubDOut_NI6602;
00330
00331 std::vector<EncoderInterface*> encoderInterface;
00332 std::vector<IncrementalEncoderSensor*> encoder;
00333 std::vector<AnalogOutput*> vref;
00334 std::vector<DigitalOutput*> enable;
00335 std::vector<AnalogDrive*> drive;
00336 DigitalOutput* brakeAxis2;
00337 DigitalOutput* brakeAxis3;
00338 DigitalInput* armPowerOn;
00339 DigitalOutput* armPowerEnable;
00340 std::vector<DigitalInput*> homingSwitch;
00341
00342 #endif
00343 std::vector<AxisInterface*> axes;
00344 TimeService::ticks previous_time, initial_time;
00345 TimeService::Seconds delta_time, total_time;
00346
00347 };
00348 }
00349 #endif // PERFORMERNAXESVELOCITYCONTROLLER