Utilities.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Rhys Mainwaring
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  *
16 */
17 
18 #include <algorithm>
19 #include <iostream>
20 #include <string>
21 
22 #include <gazebo/gazebo.hh>
23 #include <gazebo/common/common.hh>
24 
25 #include <ignition/math/Vector2.hh>
26 #include <ignition/math/Vector3.hh>
27 
28 #include <sdf/sdf.hh>
29 
31 
32 namespace asv
33 {
35  // Templates
36 
37  // This code adapted vmrc/usv_gazebo_plugins/usv_gazebo_dynamics_plugin.cc
38  template <typename T>T
39  SdfParam(sdf::Element& _sdf, const std::string &_paramName, \
40  const T &_defaultVal)
41  {
42  if (!_sdf.HasElement(_paramName))
43  {
44  gzmsg << "Parameter <" << _paramName << "> not found: "
45  << "Using default value of <" << _defaultVal << ">." << std::endl;
46  return _defaultVal;
47  }
48 
49  T val = _sdf.Get<T>(_paramName);
50  gzmsg << "Parameter found - setting <" << _paramName
51  << "> to <" << val << ">." << std::endl;
52  return val;
53  }
54 
56  // Utilities
57  bool Utilities::SdfParamBool(sdf::Element& _sdf,
58  const std::string& _paramName, const bool _defaultVal)
59  {
60  return SdfParam<bool>(_sdf, _paramName, _defaultVal);
61  }
62 
63  size_t Utilities::SdfParamSizeT(sdf::Element& _sdf,
64  const std::string& _paramName, const size_t _defaultVal)
65  {
66  return SdfParam<double>(_sdf, _paramName, _defaultVal);
67  }
68 
69  double Utilities::SdfParamDouble(sdf::Element& _sdf,
70  const std::string& _paramName, const double _defaultVal)
71  {
72  return SdfParam<double>(_sdf, _paramName, _defaultVal);
73  }
74 
75  std::string Utilities::SdfParamString(sdf::Element& _sdf,
76  const std::string& _paramName, const std::string &_defaultVal)
77  {
78  return SdfParam<std::string>(_sdf, _paramName, _defaultVal);
79  }
80 
81  ignition::math::Vector2d Utilities::SdfParamVector2(sdf::Element& _sdf,
82  const std::string& _paramName, const ignition::math::Vector2d _defaultVal)
83  {
84  return SdfParam<ignition::math::Vector2d>(_sdf, _paramName, _defaultVal);
85  }
86 
87  ignition::math::Vector3d Utilities::SdfParamVector3(sdf::Element& _sdf,
88  const std::string& _paramName, const ignition::math::Vector3d _defaultVal)
89  {
90  return SdfParam<ignition::math::Vector3d>(_sdf, _paramName, _defaultVal);
91  }
92 }
T SdfParam(sdf::Element &_sdf, const std::string &_paramName, const T &_defaultVal)
Definition: Utilities.cc:39
This file defines utilities for extracting parameters from SDF.
static ignition::math::Vector2d SdfParamVector2(sdf::Element &_sdf, const std::string &_paramName, const ignition::math::Vector2d _defaultVal)
Extract a named Vector2 parameter from an SDF element.
Definition: Utilities.cc:81
static std::string SdfParamString(sdf::Element &_sdf, const std::string &_paramName, const std::string &_defaultVal)
Extract a named string parameter from an SDF element.
Definition: Utilities.cc:75
static bool SdfParamBool(sdf::Element &_sdf, const std::string &_paramName, const bool _defaultVal)
Extract a named bool parameter from an SDF element.
Definition: Utilities.cc:57
static double SdfParamDouble(sdf::Element &_sdf, const std::string &_paramName, const double _defaultVal)
Extract a named double parameter from an SDF element.
Definition: Utilities.cc:69
Definition: Geometry.hh:28
static ignition::math::Vector3d SdfParamVector3(sdf::Element &_sdf, const std::string &_paramName, const ignition::math::Vector3d _defaultVal)
Extract a named Vector3 parameter from an SDF element.
Definition: Utilities.cc:87
static size_t SdfParamSizeT(sdf::Element &_sdf, const std::string &_paramName, const size_t _defaultVal)
Extract a named size_t parameter from an SDF element.
Definition: Utilities.cc:63


wave_gazebo_plugins
Author(s): Rhys Mainwaring
autogenerated on Thu May 7 2020 03:54:44