29 #ifndef HECTOR_GAZEBO_PLUGINS_UPDATE_TIMER_H 30 #define HECTOR_GAZEBO_PLUGINS_UPDATE_TIMER_H 33 #include <gazebo/physics/World.hh> 34 #include <gazebo/physics/PhysicsEngine.hh> 36 #include <gazebo/common/Event.hh> 37 #include <gazebo/common/Events.hh> 52 virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf,
const std::string& _prefix =
"update")
56 if (_sdf->HasElement(_prefix +
"Rate")) {
57 double update_rate = 0.0;
58 _sdf->GetElement(_prefix +
"Rate")->GetValue()->Get(update_rate);
62 if (_sdf->HasElement(_prefix +
"Period")) {
63 #if (GAZEBO_MAJOR_VERSION >= 9) 64 sdf::Time sdf_update_period;
65 _sdf->GetElement(_prefix +
"Period")->GetValue()->Get(sdf_update_period);
69 _sdf->GetElement(_prefix +
"Period")->GetValue()->Get(
update_period_);
73 if (_sdf->HasElement(_prefix +
"Offset")) {
74 #if (GAZEBO_MAJOR_VERSION >= 9) 75 sdf::Time sdf_update_offset;
76 _sdf->GetElement(_prefix +
"Offset")->GetValue()->Get(sdf_update_offset);
80 _sdf->GetElement(_prefix +
"Offset")->GetValue()->Get(
update_offset_);
85 virtual event::ConnectionPtr
Connect(
const boost::function<
void()> &_subscriber,
bool connectToWorldUpdateBegin =
true)
95 virtual void Disconnect(event::ConnectionPtr
const& _c = event::ConnectionPtr())
97 #if (GAZEBO_MAJOR_VERSION >= 8) 104 #if (GAZEBO_MAJOR_VERSION < 8) 121 return (period > 0.0) ? (1.0 / period) : 0.0;
133 if (
last_update_ == common::Time())
return common::Time();
134 #if (GAZEBO_MAJOR_VERSION >= 8) 144 #if (GAZEBO_MAJOR_VERSION >= 8) 145 double step =
world_->Physics()->GetMaxStepSize();
147 double step =
world_->GetPhysicsEngine()->GetMaxStepSize();
149 if (period == 0)
return true;
150 #if (GAZEBO_MAJOR_VERSION >= 8) 153 double fraction = fmod((
world_->GetSimTime() -
update_offset_).Double() + (step / 2.0), period);
155 return (fraction >= 0.0) && (fraction < step);
161 #if (GAZEBO_MAJOR_VERSION >= 8) 187 #if (GAZEBO_MAJOR_VERSION >= 8) 208 #endif // HECTOR_GAZEBO_PLUGINS_UPDATE_TIMER_H double getUpdateRate() const
common::Time update_offset_
virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf, const std::string &_prefix="update")
common::Time const & getLastUpdate() const
event::EventT< void()> update_event_
virtual bool checkUpdate() const
common::Time update_period_
virtual event::ConnectionPtr Connect(const boost::function< void()> &_subscriber, bool connectToWorldUpdateBegin=true)
virtual bool update(double &dt)
event::ConnectionPtr update_connection_
unsigned int connection_count_
common::Time last_update_
common::Time const & getUpdatePeriod() const
virtual void Disconnect(event::ConnectionPtr const &_c=event::ConnectionPtr())
common::Time getTimeSinceLastUpdate() const
void setUpdatePeriod(common::Time const &period)
void setUpdateRate(double rate)