00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _TORQUE_SIM_AXIS_HPP
00020 #define _TORQUE_SIM_AXIS_HPP
00021
00022 #include <ocl/OCL.hpp>
00023 #include <rtt/dev/AxisInterface.hpp>
00024 #include <rtt/dev/DigitalOutput.hpp>
00025 #include <rtt/TimeService.hpp>
00026
00027 namespace OCL
00028 {
00033 class TorqueSimulationEncoder: public SensorInterface<double>
00034 {
00035 public:
00036 TorqueSimulationEncoder(double initial=0, double min=-10, double max=10);
00037 virtual ~TorqueSimulationEncoder() {};
00038
00039 virtual double readSensor() const;
00040 virtual int readSensor(double& data) const;
00041 virtual double maxMeasurement() const {return _max; };
00042 virtual double minMeasurement() const {return _min; };
00043 virtual double zeroMeasurement() const {return 0.0;};
00044
00045 void update(double position, double velocity, TimeService::ticks previous_time);
00046 void stop();
00047
00048 private:
00049 double _position, _velocity, _min, _max;
00050 TimeService::ticks _previous_time;
00051 TimeService::Seconds _delta_time;
00052 bool _first_drive;
00053
00054 };
00055
00059 class TorqueSimulationVelocitySensor : public SensorInterface<double>
00060 {
00061 public:
00062 TorqueSimulationVelocitySensor(double maxvel);
00063
00064 virtual ~TorqueSimulationVelocitySensor() {}
00065
00066 virtual int readSensor( double& vel ) const;
00067 virtual double readSensor() const;
00068 virtual double maxMeasurement() const { return _maxvel; }
00069 virtual double minMeasurement() const { return - _maxvel; }
00070 virtual double zeroMeasurement() const { return 0; }
00071
00072 void update(double velocity, double acceleration, TimeService::ticks previous_time);
00073 void stop();
00074
00075 private:
00076 double _velocity, _acceleration, _maxvel;
00077 TimeService::ticks _previous_time;
00078 TimeService::Seconds _delta_time;
00079 bool _first_drive;
00080
00081 };
00082
00083
00084
00085 class TorqueSimulationCurrentSensor;
00086
00090 class TorqueSimulationAxis: public AxisInterface
00091 {
00092 public:
00093 TorqueSimulationAxis(double initial=0, double min=-10, double max=10, double velLim=2);
00094 virtual ~TorqueSimulationAxis();
00095
00096 virtual bool stop();
00097 virtual bool lock();
00098 virtual bool unlock();
00099 virtual bool drive( double cur );
00100 virtual bool isLocked() const;
00101 virtual bool isStopped() const;
00102 virtual bool isDriven() const;
00103 virtual SensorInterface<double>* getSensor(const std::string& name) const;
00104 virtual std::vector<std::string> sensorList() const;
00105 virtual SensorInterface<int>* getCounter(const std::string& name) const { return 0;}
00106 virtual std::vector<std::string> counterList() const { return std::vector<std::string>();}
00107 virtual DigitalInput* getSwitch(const std::string& name) const { return 0; }
00108 virtual std::vector<std::string> switchList() const { return std::vector<std::string>();}
00109
00110 double getDriveValue() const;
00111 void setMaxDriveValue( double cur_max ) { _max_drive_value = cur_max; }
00112
00113 DigitalOutput* getBrake();
00114 DigitalOutput* getEnable();
00115
00116 private:
00117 double _drive_value;
00118 DigitalOutput _enable;
00119 DigitalOutput _brake;
00120 double _max_drive_value;
00121 TorqueSimulationEncoder* _encoder;
00122 TorqueSimulationVelocitySensor* _velSensor;
00123 TorqueSimulationCurrentSensor* _curSensor;
00124 bool _is_locked, _is_stopped, _is_driven;
00125
00126
00127 };
00128
00129
00133 class TorqueSimulationCurrentSensor : public SensorInterface<double>
00134 {
00135 public:
00136 TorqueSimulationCurrentSensor(TorqueSimulationAxis* axis, double maxcur) : _axis(axis), _maxcur(maxcur)
00137 {};
00138
00139 virtual ~TorqueSimulationCurrentSensor() {}
00140
00141 virtual int readSensor( double& cur ) const { cur = _axis->getDriveValue(); return 0; }
00142
00143 virtual double readSensor() const { return _axis->getDriveValue(); }
00144
00145 virtual double maxMeasurement() const { return _maxcur; }
00146
00147 virtual double minMeasurement() const { return - _maxcur; }
00148
00149 virtual double zeroMeasurement() const { return 0; }
00150
00151 private:
00152 TorqueSimulationAxis* _axis;
00153 double _maxcur;
00154 };
00155
00156 }
00157
00158 #endif //_TORQUE_SIM_AXIS_HPP
00159
00160
00161