ThrusterConversionFcn.hh
Go to the documentation of this file.
1 // Copyright (c) 2016 The UUV Simulator Authors.
2 // All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
18 
19 #ifndef __UUV_GAZEBO_PLUGINS_CONVERSION_FUNCTION_HH__
20 #define __UUV_GAZEBO_PLUGINS_CONVERSION_FUNCTION_HH__
21 
22 #include <map>
23 #include <string>
24 #include <vector>
25 
26 #include <sdf/sdf.hh>
27 
28 namespace gazebo
29 {
32 {
34  protected: ConversionFunction() {}
35 
37  public: virtual ~ConversionFunction() {}
38 
40  public: virtual std::string GetType() = 0;
41 
43  public: virtual bool GetParam(std::string _tag,
44  double& _output) = 0;
45 
47  public: virtual std::map<double, double> GetTable()
48  { return std::map<double, double>(); };
49 
51  public: virtual double convert(double _cmd) = 0;
52 };
53 
55 typedef ConversionFunction* (*ConversionFunctionCreator)(sdf::ElementPtr);
56 
59 {
61  public: ConversionFunction* CreateConversionFunction(sdf::ElementPtr _sdf);
62 
64  public: static ConversionFunctionFactory& GetInstance();
65 
67  public: bool RegisterCreator(const std::string& _identifier,
68  ConversionFunctionCreator _creator);
69 
72 
74  private: std::map<std::string, ConversionFunctionCreator> creators_;
75 };
76 
78 #define REGISTER_CONVERSIONFUNCTION(type) \
79  static const bool registeredWithFactory
80 
82 #define REGISTER_CONVERSIONFUNCTION_CREATOR(type, creator) \
83  const bool type::registeredWithFactory = \
84  ConversionFunctionFactory::GetInstance().RegisterCreator( \
85  type::IDENTIFIER, creator);
86 
87 
93 {
95  public: static ConversionFunction* create(sdf::ElementPtr _sdf);
96 
98  public: virtual std::string GetType() { return IDENTIFIER; }
99 
101  public: virtual bool GetParam(std::string _tag, double& _output);
102 
104  public: virtual double convert(double _cmd);
105 
108 
110  private: static const std::string IDENTIFIER;
111 
113  private: ConversionFunctionBasic(double _rotorConstant);
114  private: double rotorConstant;
115 };
116 
122 {
124  public: static ConversionFunction* create(sdf::ElementPtr _sdf);
125 
127  public: virtual std::string GetType() { return IDENTIFIER; }
128 
130  public: virtual bool GetParam(std::string _tag, double& _output);
131 
133  public: virtual double convert(double _cmd);
134 
137 
139  private: static const std::string IDENTIFIER;
140 
142  private: ConversionFunctionBessa(double _rotorConstantL,
143  double _rotorConstantR,
144  double _deltaL, double _deltaR);
145 
147  private: double rotorConstantL;
148 
150  private: double rotorConstantR;
151 
153  private: double deltaL;
154 
156  private: double deltaR;
157 };
158 
161 {
163  public: static ConversionFunction* create(sdf::ElementPtr _sdf);
164 
166  public: virtual std::string GetType() { return IDENTIFIER; }
167 
169  public: virtual bool GetParam(std::string _tag, double& _output);
170 
172  public: virtual std::map<double, double> GetTable();
173 
175  public: virtual double convert(double _cmd);
176 
179 
181  private: static const std::string IDENTIFIER;
182 
184  private: ConversionFunctionLinearInterp(const std::vector<double> &_input,
185  const std::vector<double> &_output);
186 
188  private: std::map<double, double> lookupTable;
189 };
190 }
191 
192 #endif
#define REGISTER_CONVERSIONFUNCTION(type)
Use the following macro within a ThrusterDynamics declaration:
std::map< double, double > lookupTable
Lookup table maps input values -> output values.
std::map< std::string, ConversionFunctionCreator > creators_
Map of each registered identifiers to its corresponding creator.
virtual double convert(double _cmd)=0
Convert thruster state (e.g. angular velocity) to thrust force.
ConversionFunction *(* ConversionFunctionCreator)(sdf::ElementPtr)
Function pointer to create a certain conversion function.
static const std::string IDENTIFIER
The unique identifier of this conversion function.
virtual ~ConversionFunction()
Destructor.
virtual bool GetParam(std::string _tag, double &_output)=0
Return paramater in vector form for the given tag.
virtual std::string GetType()
Return (derived) type of conversion function.
virtual std::map< double, double > GetTable()
Return input and output vectors of the lookup table.
Asymmetric conversion function with dead-zone nonlinearity. This corresponds to what is called Model ...
Factory singleton class that creates a ConversionFunction from sdf.
static const std::string IDENTIFIER
The unique identifier of this conversion function.
Abstact base class for a thruster conversion function.
ConversionFunction()
Protected constructor: Use the factory instead.
virtual std::string GetType()
Return (derived) type of conversion function.
The most basic conversion function: Thrust = const.*w*abs(w) This corresponds to what is attrributed ...
double deltaR
Dead-zone for omega > 0.
double rotorConstantR
Rotor constant for omega > 0.
virtual std::string GetType()=0
Return (derived) type of conversion function.
double rotorConstantL
Rotor constant for omega < 0.
ConversionFunctionFactory()
Constructor is private since this is a singleton.
virtual std::string GetType()
Return (derived) type of conversion function.
static const std::string IDENTIFIER
The unique identifier of this conversion function.
double deltaL
Dead-zone for omega < 0.
Conversion using linear interpolation between given data points.


uuv_gazebo_plugins
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Thu Jun 18 2020 03:28:24