00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _SIM_AXIS_HPP
00020 #define _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 SimulationEncoder: public SensorInterface<double>
00034 {
00035 public:
00036 SimulationEncoder(double initial=0, double min=-10, double max=10);
00037 virtual ~SimulationEncoder() {};
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 setDrive(double velocity);
00046
00047 private:
00048 double _position, _velocity, _min, _max;
00049 TimeService::ticks _previous_time;
00050 TimeService::Seconds _delta_time;
00054 bool _first_drive;
00055
00056 };
00057
00058
00059
00060
00061 class SimulationVelocitySensor;
00062
00066 class SimulationAxis: public AxisInterface
00067 {
00068 public:
00069 SimulationAxis(double initial=0, double min=-10, double max=10);
00070 virtual ~SimulationAxis();
00071
00072 virtual bool stop();
00073 virtual bool lock();
00074 virtual bool unlock();
00075 virtual bool drive( double v );
00076 virtual bool isLocked() const;
00077 virtual bool isStopped() const;
00078 virtual bool isDriven() const;
00079 virtual SensorInterface<double>* getSensor(const std::string& name) const;
00080 virtual std::vector<std::string> sensorList() const;
00081 virtual SensorInterface<int>* getCounter(const std::string& name) const { return 0;}
00082 virtual std::vector<std::string> counterList() const { return std::vector<std::string>();}
00083 virtual DigitalInput* getSwitch(const std::string& name) const { return 0; }
00084 virtual std::vector<std::string> switchList() const { return std::vector<std::string>();}
00085
00086 double getDriveValue() const;
00087 void setMaxDriveValue( double v_max ) { _max_drive_value = v_max; }
00088
00089 DigitalOutput* getBrake();
00090 DigitalOutput* getEnable();
00091
00092 private:
00093 double _drive_value;
00094 DigitalOutput _enable;
00095 DigitalOutput _brake;
00096 double _velocity;
00097 double _max_drive_value;
00098 SimulationEncoder* _encoder;
00099 SimulationVelocitySensor* _velSensor;
00100 bool _is_locked, _is_stopped, _is_driven;
00101
00102
00103 };
00104
00108 class SimulationVelocitySensor : public SensorInterface<double>
00109 {
00110 public:
00111 SimulationVelocitySensor(SimulationAxis* axis, double maxvel) : _axis(axis), _maxvel(maxvel)
00112 {};
00113
00114 virtual ~SimulationVelocitySensor() {}
00115
00116 virtual int readSensor( double& vel ) const { vel = _axis->getDriveValue(); return 0; }
00117
00118 virtual double readSensor() const { return _axis->getDriveValue(); }
00119
00120 virtual double maxMeasurement() const { return _maxvel; }
00121
00122 virtual double minMeasurement() const { return - _maxvel; }
00123
00124 virtual double zeroMeasurement() const { return 0; }
00125
00126 private:
00127 SimulationAxis* _axis;
00128 double _maxvel;
00129 };
00130
00131
00132 }
00133
00134 #endif //_SIM_AXIS_HPP
00135
00136
00137