openrave-yarp-plugins
Loading...
Searching...
No Matches
ForceSensor.h
1/*
2 * ForceSensor.h
3 *
4 * Created on: Jul 29, 2011
5 * Author: Higinio Marti
6 */
7#ifndef FORCESENSOR_H_
8#define FORCESENSOR_H_
9
10#include <openrave/openrave.h>
11#include <openrave/plugin.h>
12#include <boost/bind.hpp>
13#include <boost/circular_buffer.hpp>
14
15using namespace OpenRAVE;
16using namespace std;
17
18enum FilterTypes {None=0,
19 FirstOrderLowpass,
20 MovingAverage
21};
22
23class ForceSensor : public SensorBase
24{
25protected:
26 class ForceSensorXMLReader : public BaseXMLReader
27 {
28 public:
29 ForceSensorXMLReader(boost::shared_ptr<ForceSensor> psensor) : _psensor(psensor) {}
30
31 virtual ProcessElement startElement(const std::string& name, const std::list<std::pair<std::string,std::string> >& atts);
32 virtual bool endElement(const std::string& name);
33 virtual void characters(const std::string& ch);
34
35 protected:
36 BaseXMLReaderPtr _pcurreader;
37 boost::shared_ptr<ForceSensor> _psensor;
38 stringstream ss;
39 };
40
41public:
42
44 class ForceSensorGeomData : public Force6DGeomData
45 {
46 public:
47 virtual SensorType GetType() { return ST_Force6D; }
48 };
49
50 static BaseXMLReaderPtr CreateXMLReader(InterfaceBasePtr ptr, const std::list<std::pair<std::string,std::string> >& atts)
51 {
52 return BaseXMLReaderPtr(new ForceSensorXMLReader(boost::dynamic_pointer_cast<ForceSensor>(ptr)));
53 }
54
55 /************************************************************************/
56 ForceSensor(EnvironmentBasePtr penv);
57 virtual ~ForceSensor(){};
58
59 //Sensor Interface
60 virtual bool Init(const string& args);
61 virtual void Reset(int options);
62 virtual bool SimulationStep(OpenRAVE::dReal fTimeElapsed);
63 virtual SensorGeometryConstPtr GetSensorGeometry(SensorType type);
64 virtual SensorDataPtr CreateSensorData(SensorType type);
65 virtual bool GetSensorData(SensorDataPtr psensordata);
66 virtual void SetTransform(const Transform& trans);
67 virtual const Transform& GetTransform();
68 bool SetHistoryLength(std::ostream& os, std::istream& is);
69 bool SetFilter(std::ostream& os, std::istream& is);
70 bool GetHistory(std::ostream& os, std::istream& is);
71
72 virtual bool Supports(SensorType type) { return type == ST_Force6D; }
73
74 virtual int Configure(ConfigureCommand command, bool blocking)
75 {
76 switch(command) {
77 case CC_PowerOn:
78 _bPower = true;
79 return _bPower;
80 case CC_PowerOff:
81 _bPower = false;
82 //_Reset();
83 return _bPower;
84 case CC_PowerCheck:
85 return _bPower;
86 case CC_RenderDataOn:
87 _bRenderData = true;
88 return _bRenderData;
89 case CC_RenderDataOff: {
90 boost::mutex::scoped_lock lock(_mutexdata);
91 _bRenderData = false;
92 return _bRenderData;
93 }
94 case CC_RenderDataCheck:
95 return _bRenderData;
96 case CC_RenderGeometryOn:
97 _bRenderGeometry = true;
98 return _bRenderData;
99 case CC_RenderGeometryOff: {
100 _bRenderGeometry = false;
101 return _bRenderData;
102 }
103 case CC_RenderGeometryCheck:
104 return _bRenderGeometry;
105 }
106 throw openrave_exception(str(boost::format("SensorBase::Configure: unknown command 0x%x")%command));
107 }
108
109protected:
110 bool _firstStep;
111
112 //Doesn't do anything yet
113 Transform _trans;
114
115 boost::shared_ptr<Force6DSensorData> _data;
116 boost::circular_buffer<Force6DSensorData> _history;
117 boost::circular_buffer<dReal> _timestamps;
118 boost::shared_ptr<ForceSensorGeomData> _geom;
119
120 KinBody::LinkConstPtr _sensorLink;
121 //This doesn't seem to do anything at this point.
122 KinBody::JointConstPtr _sensorJoint;
123
124 mutable boost::mutex _mutexdata;
125 bool _bRenderData, _bRenderGeometry, _bPower;
126 FilterTypes _outfilt;
127 Force6DSensorData _movingsum;
128
129 friend class ForceSensorXMLReader;
130};
131
132class OpenraveYarpForceSensorPlugin : public RavePlugin
133{
134public:
135 OpenRAVE::InterfaceBasePtr CreateInterface(OpenRAVE::InterfaceType type,
136 const std::string & interfacename,
137 std::istream & sinput,
138 OpenRAVE::EnvironmentBasePtr penv) override;
139
140 const InterfaceMap & GetInterfaces() const override;
141 const std::string & GetPluginName() const override;
142};
143
144#endif
permanent properties of the sensor
Definition ForceSensor.h:45
Definition ForceSensor.h:27
Definition ForceSensor.h:24
Definition ForceSensor.h:133