Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced common::Time for std::chrono #41

Merged
merged 19 commits into from
Sep 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tick-tock cycle to Update common::Time methods
Signed-off-by: ahcorde <[email protected]>
ahcorde committed Sep 18, 2020
commit e3acbac85d4a097abbfa6e199ca17168c077ff1a
6 changes: 6 additions & 0 deletions include/ignition/sensors/AirPressureSensor.hh
Original file line number Diff line number Diff line change
@@ -64,6 +64,12 @@ namespace ignition
/// \return True on success
public: virtual bool Init() override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool IGN_DEPRECATED(4) Update(
const ignition::common::Time &_now) override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
6 changes: 6 additions & 0 deletions include/ignition/sensors/AltimeterSensor.hh
Original file line number Diff line number Diff line change
@@ -64,6 +64,12 @@ namespace ignition
/// \return True on success
public: virtual bool Init() override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool IGN_DEPRECATED(4) Update(
const ignition::common::Time &_now) override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
6 changes: 6 additions & 0 deletions include/ignition/sensors/CameraSensor.hh
Original file line number Diff line number Diff line change
@@ -73,6 +73,12 @@ namespace ignition
/// \return True on success
public: virtual bool Init() override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool IGN_DEPRECATED(4) Update(
const ignition::common::Time &_now) override;

/// \brief Force the sensor to generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
6 changes: 6 additions & 0 deletions include/ignition/sensors/ImuSensor.hh
Original file line number Diff line number Diff line change
@@ -65,6 +65,12 @@ namespace ignition
/// \return True on success
public: virtual bool Init() override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool IGN_DEPRECATED(4) Update(
const ignition::common::Time &_now) override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
6 changes: 6 additions & 0 deletions include/ignition/sensors/Lidar.hh
Original file line number Diff line number Diff line change
@@ -53,6 +53,12 @@ namespace ignition
/// \brief destructor
public: virtual ~Lidar();

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool IGN_DEPRECATED(4) Update(
const ignition::common::Time &_now) override;

/// \brief Force the sensor to generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
6 changes: 6 additions & 0 deletions include/ignition/sensors/LogicalCameraSensor.hh
Original file line number Diff line number Diff line change
@@ -68,6 +68,12 @@ namespace ignition
/// \return True on success
public: virtual bool Init() override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool IGN_DEPRECATED(4) Update(
const ignition::common::Time &_now) override;

/// \brief Force the sensor to generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
6 changes: 6 additions & 0 deletions include/ignition/sensors/MagnetometerSensor.hh
Original file line number Diff line number Diff line change
@@ -65,6 +65,12 @@ namespace ignition
/// \return True on success
public: virtual bool Init() override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool IGN_DEPRECATED(4) Update(
const ignition::common::Time &_now) override;

/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
36 changes: 35 additions & 1 deletion include/ignition/sensors/Sensor.hh
Original file line number Diff line number Diff line change
@@ -68,6 +68,21 @@ namespace ignition
/// \brief Initialize values in the sensor
public: virtual bool Init();

/// \brief Force the sensor to generate data
///
/// This method must be overridden by sensors. Subclasses should not
/// not make a decision about whether or not they need to update. The
/// Sensor class will make sure Update() is called at the correct time.
///
/// If a subclass wants to have a variable update rate it should call
/// SetUpdateRate().
///
/// A subclass should return false if there was an error while updating
/// \param[in] _now The current time
/// \return true if the update was successfull
/// \sa SetUpdateRate()
public: virtual bool IGN_DEPRECATED(3) Update(const common::Time &_now) = 0;

/// \brief Force the sensor to generate data
///
/// This method must be overridden by sensors. Subclasses should not
@@ -85,7 +100,26 @@ namespace ignition
const std::chrono::steady_clock::duration &_now) = 0;

/// \brief Return the next time the sensor will generate data
public: std::chrono::steady_clock::duration NextUpdateTime() const;
public: ignition::common::Time IGN_DEPRECATED(3) NextUpdateTime() const;
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Return the next time the sensor will generate data
public: std::chrono::steady_clock::duration NextDataUpdateTime() const;

/// \brief Update the sensor.
///
/// This is called by the manager, and is responsible for determining
/// if this sensor needs to generate data at this time. If so, the
/// subclasses' Update() method will be called.
/// \param[in] _now The current time
/// \param[in] _force Force the update to happen even if it's not time
/// \return True if the update was triggered (_force was true or _now
/// >= next_update_time) and the sensor's
/// bool Sensor::Update(std::chrono::steady_clock::time_point)
/// function returned true.
/// False otherwise.
/// \remarks If forced the NextUpdateTime() will be unchanged.
/// \sa virtual bool Update(const common::Time &_name) = 0
public: bool IGN_DEPRECATED(3) Update(const common::Time &_now, const bool _force);

/// \brief Update the sensor.
///
7 changes: 7 additions & 0 deletions src/AirPressureSensor.cc
Original file line number Diff line number Diff line change
@@ -132,6 +132,13 @@ bool AirPressureSensor::Load(sdf::ElementPtr _sdf)
return this->Load(sdfSensor);
}

//////////////////////////////////////////////////
bool AirPressureSensor::Update(
const ignition::common::Time &_now)
{
return this->Update(math::secNsecToDuration(_now.sec, _now.nsec));
}

//////////////////////////////////////////////////
bool AirPressureSensor::Update(
const std::chrono::steady_clock::duration &_now)
7 changes: 7 additions & 0 deletions src/AltimeterSensor.cc
Original file line number Diff line number Diff line change
@@ -130,6 +130,13 @@ bool AltimeterSensor::Load(sdf::ElementPtr _sdf)
return this->Load(sdfSensor);
}

//////////////////////////////////////////////////
bool AltimeterSensor::Update(
const ignition::common::Time &_now)
{
return this->Update(math::secNsecToDuration(_now.sec, _now.nsec));
}

//////////////////////////////////////////////////
bool AltimeterSensor::Update(const std::chrono::steady_clock::duration &_now)
{
7 changes: 7 additions & 0 deletions src/CameraSensor.cc
Original file line number Diff line number Diff line change
@@ -299,6 +299,13 @@ void CameraSensor::SetScene(ignition::rendering::ScenePtr _scene)
}
}

//////////////////////////////////////////////////
bool CameraSensor::Update(
const ignition::common::Time &_now)
{
return this->Update(math::secNsecToDuration(_now.sec, _now.nsec));
}

//////////////////////////////////////////////////
bool CameraSensor::Update(const std::chrono::steady_clock::duration &_now)
{
7 changes: 7 additions & 0 deletions src/ImuSensor.cc
Original file line number Diff line number Diff line change
@@ -147,6 +147,13 @@ bool ImuSensor::Load(sdf::ElementPtr _sdf)
return this->Load(sdfSensor);
}

//////////////////////////////////////////////////
bool ImuSensor::Update(
const ignition::common::Time &_now)
{
return this->Update(math::secNsecToDuration(_now.sec, _now.nsec));
}

//////////////////////////////////////////////////
bool ImuSensor::Update(const std::chrono::steady_clock::duration &_now)
{
7 changes: 7 additions & 0 deletions src/Lidar.cc
Original file line number Diff line number Diff line change
@@ -182,6 +182,13 @@ ignition::common::ConnectionPtr Lidar::ConnectNewLidarFrame(
return nullptr;
}

//////////////////////////////////////////////////
bool Lidar::Update(
const ignition::common::Time &_now)
{
return this->Update(math::secNsecToDuration(_now.sec, _now.nsec));
}

//////////////////////////////////////////////////
bool Lidar::Update(const std::chrono::steady_clock::duration &/*_now*/)
{
7 changes: 7 additions & 0 deletions src/LogicalCameraSensor.cc
Original file line number Diff line number Diff line change
@@ -128,6 +128,13 @@ void LogicalCameraSensor::SetModelPoses(
this->dataPtr->models = std::move(_models);
}

//////////////////////////////////////////////////
bool LogicalCameraSensor::Update(
const ignition::common::Time &_now)
{
return this->Update(math::secNsecToDuration(_now.sec, _now.nsec));
}

//////////////////////////////////////////////////
bool LogicalCameraSensor::Update(
const std::chrono::steady_clock::duration &_now)
7 changes: 7 additions & 0 deletions src/MagnetometerSensor.cc
Original file line number Diff line number Diff line change
@@ -136,6 +136,13 @@ bool MagnetometerSensor::Load(sdf::ElementPtr _sdf)
return this->Load(sdfSensor);
}

//////////////////////////////////////////////////
bool MagnetometerSensor::Update(
const ignition::common::Time &_now)
{
return this->Update(math::secNsecToDuration(_now.sec, _now.nsec));
}

//////////////////////////////////////////////////
bool MagnetometerSensor::Update(
const std::chrono::steady_clock::duration &_now)
16 changes: 15 additions & 1 deletion src/Sensor.cc
Original file line number Diff line number Diff line change
@@ -238,11 +238,25 @@ bool Sensor::Update(const std::chrono::steady_clock::duration &_now,
}

//////////////////////////////////////////////////
std::chrono::steady_clock::duration Sensor::NextUpdateTime() const
bool Sensor::Update(const common::Time &_now, const bool _force)
{
return Update(math::secNsecToDuration(_now.sec, _now.nsec), _force);
chapulina marked this conversation as resolved.
Show resolved Hide resolved
}

//////////////////////////////////////////////////
std::chrono::steady_clock::duration Sensor::NextDataUpdateTime() const
{
return this->dataPtr->nextUpdateTime;
}

//////////////////////////////////////////////////
ignition::common::Time Sensor::NextUpdateTime() const
{
std::pair<uint64_t, uint64_t> secNsec =
math::durationToSecNsec(this->dataPtr->nextUpdateTime);
return common::Time(secNsec.first, secNsec.second);
}

/////////////////////////////////////////////////
void Sensor::AddSequence(ignition::msgs::Header *_msg,
const std::string &_seqKey)
5 changes: 5 additions & 0 deletions src/Sensor_TEST.cc
Original file line number Diff line number Diff line change
@@ -30,6 +30,11 @@ class TestSensor : public Sensor
return true;
}

public: bool IGN_DEPRECATED(4) Update(const common::Time &) override
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
{
return false;
}

public: unsigned int updateCount{0};
};