22 #ifndef ROTORS_GAZEBO_PLUGINS_COMMON_H_ 23 #define ROTORS_GAZEBO_PLUGINS_COMMON_H_ 25 #include <Eigen/Dense> 26 #include <gazebo/gazebo.hh> 71 bool getSdfParam(sdf::ElementPtr sdf,
const std::string& name, T&
param,
const T& default_value,
const bool& verbose =
73 if (sdf->HasElement(name)) {
74 param = sdf->GetElement(name)->Get<T>();
78 param = default_value;
80 gzerr <<
"[rotors_gazebo_plugins] Please specify a value for parameter \"" << name <<
"\".\n";
88 TiXmlElement* e_param =
nullptr;
89 TiXmlElement* e_param_tmp =
nullptr;
90 std::string dbg_param;
92 TiXmlDocument doc(world_name +
".xml");
95 TiXmlHandle h_root(doc.RootElement());
97 TiXmlElement* e_model = h_root.FirstChild(
"model").Element();
99 for( e_model; e_model; e_model=e_model->NextSiblingElement(
"model") )
101 const char* attr_name = e_model->Attribute(
"name");
105 if (model_name.compare(attr_name) == 0)
107 e_param_tmp = e_model->FirstChildElement(param);
110 e_param = e_param_tmp;
119 e_param = e_model->FirstChildElement(param);
120 dbg_param =
"common ";
126 std::istringstream iss(e_param->GetText());
129 gzdbg << model_name <<
" model: " << dbg_param <<
"parameter " << param <<
" = " << param_value <<
" from " << doc.Value() <<
"\n";
147 template <
typename T>
152 timeConstantUp_(timeConstantUp),
153 timeConstantDown_(timeConstantDown),
154 previousState_(initialState) {}
160 if (inputState > previousState_) {
162 double alphaUp =
exp(-samplingTime / timeConstantUp_);
164 outputState = alphaUp * previousState_ + (1 - alphaUp) * inputState;
169 double alphaDown =
exp(-samplingTime / timeConstantDown_);
170 outputState = alphaDown * previousState_ + (1 - alphaDown) * inputState;
172 previousState_ = outputState;
186 template<
class Derived>
188 typedef typename Derived::Scalar Scalar;
189 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived);
190 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
191 const Scalar q_squared = theta.squaredNorm() / 4.0;
194 return Eigen::Quaternion<Scalar>(
sqrt(1 - q_squared), theta[0] * 0.5, theta[1] * 0.5, theta[2] * 0.5);
197 const Scalar w = 1.0 /
sqrt(1 + q_squared);
198 const Scalar
f = w * 0.5;
199 return Eigen::Quaternion<Scalar>(w, theta[0] * f, theta[1] * f, theta[2] * f);
203 template<
class In,
class Out>
static constexpr double kDefaultRotorVelocitySlowdownSim
static const std::string kConnectRosToGazeboSubtopic
static const std::string kDefaultNamespace
FirstOrderFilter(double timeConstantUp, double timeConstantDown, T initialState)
static const bool kPrintOnPluginLoad
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
Eigen::Quaternion< typename Derived::Scalar > QuaternionFromSmallAngle(const Eigen::MatrixBase< Derived > &theta)
Computes a quaternion from the 3-element small angle approximation theta.
void copyPosition(const In &in, Out *out)
static const bool kPrintOnUpdates
T updateFilter(T inputState, double samplingTime)
This method will apply a first order filter on the inputState.
bool getSdfParam(sdf::ElementPtr sdf, const std::string &name, T ¶m, const T &default_value, const bool &verbose=false)
Obtains a parameter from sdf.
static const std::string kConnectGazeboToRosSubtopic
static const std::string kBroadcastTransformSubtopic
Special-case topic for ROS interface plugin to listen to (if present) and broadcast transforms to the...
static const bool kPrintOnMsgCallback
This class can be used to apply a first order filter on a signal. It allows different acceleration an...
void model_param(const std::string &world_name, const std::string &model_name, const std::string ¶m, T ¶m_value)