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
Show file tree
Hide file tree
Changes from 13 commits
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
2 changes: 1 addition & 1 deletion examples/save_image/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ int main()
cameraSensor->ConnectImageCallback(&OnImageFrame);

// Force the camera to generate an image
mgr.RunOnce(ignition::common::Time::Zero, true);
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);

return 0;
}
Expand Down
9 changes: 8 additions & 1 deletion include/ignition/sensors/AirPressureSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ namespace ignition
/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool Update(const common::Time &_now) override;
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
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;
chapulina marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Set the reference altitude.
/// \param[in] _ref Verical reference position in meters
Expand Down
9 changes: 8 additions & 1 deletion include/ignition/sensors/AltimeterSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ namespace ignition
/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool Update(const common::Time &_now) override;
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
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;

/// \brief Set the vertical reference position of the altimeter
/// \param[in] _ref Verical reference position in meters
Expand Down
12 changes: 10 additions & 2 deletions include/ignition/sensors/CameraSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@ 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
public: virtual bool Update(const common::Time &_now) override;
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;

/// \brief Set a callback to be called when image frame data is
/// generated.
Expand Down Expand Up @@ -138,7 +145,8 @@ namespace ignition

/// \brief Publish camera info message.
/// \param[in] _now The current time
protected: void PublishInfo(const ignition::common::Time &_now);
protected: void PublishInfo(
const std::chrono::steady_clock::duration &_now);
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Create a camera in a scene
/// \return True on success.
Expand Down
3 changes: 2 additions & 1 deletion include/ignition/sensors/DepthCameraSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ namespace ignition
/// \brief Force the sensor to generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool Update(const common::Time &_now) override;
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Force the sensor to generate data
/// \param[in] _now The current time
Expand Down
3 changes: 2 additions & 1 deletion include/ignition/sensors/GpuLidarSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace ignition
/// \brief Force the sensor to generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool Update(const common::Time &_now) override;
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Initialize values in the sensor
/// \return True on success
Expand Down
9 changes: 8 additions & 1 deletion include/ignition/sensors/ImuSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ namespace ignition
/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool Update(const common::Time &_now) override;
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
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;

/// \brief Set the angular velocity of the imu
/// \param[in] _angularVel Angular velocity of the imu in body frame
Expand Down
12 changes: 10 additions & 2 deletions include/ignition/sensors/Lidar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,23 @@ 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
public: virtual bool Update(const common::Time &_now) override;
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;

/// \brief Publish LaserScan message
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool PublishLidarScan(const common::Time &_now);
public: virtual bool PublishLidarScan(
const std::chrono::steady_clock::duration &_now);
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Load the sensor based on data from an sdf::Sensor object.
/// \param[in] _sdf SDF Sensor parameters.
Expand Down
9 changes: 8 additions & 1 deletion include/ignition/sensors/LogicalCameraSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,17 @@ 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
public: virtual bool Update(const common::Time &_now) override;
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;

/// \brief Get the near distance. This is the distance from the
/// frustum's vertex to the closest plane.
Expand Down
9 changes: 8 additions & 1 deletion include/ignition/sensors/MagnetometerSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ namespace ignition
/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool Update(const common::Time &_now) override;
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
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;

/// \brief Set the world pose of the sensor
/// \param[in] _pose Pose in world frame
Expand Down
2 changes: 1 addition & 1 deletion include/ignition/sensors/Manager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace ignition
/// \param _time: The current simulated time
/// \param _force: If true, all sensors are forced to update. Otherwise
/// a sensor will update based on it's Hz rate.
public: void RunOnce(const ignition::common::Time &_time,
public: void RunOnce(const std::chrono::steady_clock::duration &_time,
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
bool _force = false);

/// \brief Adds colon delimited paths sensor plugins may be
Expand Down
3 changes: 2 additions & 1 deletion include/ignition/sensors/RgbdCameraSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ namespace ignition
/// \brief Force the sensor to generate data
/// \param[in] _now The current time
/// \return true if the update was successful
public: virtual bool Update(const common::Time &_now) override;
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Set the rendering scene.
/// \param[in] _scene Pointer to the scene
Expand Down
47 changes: 43 additions & 4 deletions include/ignition/sensors/Sensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,47 @@ namespace ignition
/// \param[in] _now The current time
/// \return true if the update was successfull
/// \sa SetUpdateRate()
public: virtual bool Update(const common::Time &_now) = 0;
public:
virtual bool IGN_DEPRECATED(3) Update(const common::Time &_now) = 0;
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \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 Update(
const std::chrono::steady_clock::duration &_now) = 0;

/// \brief Return the next time the sensor will generate data
public: common::Time 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)
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
Update(const common::Time &_now, const bool _force);

/// \brief Update the sensor.
///
Expand All @@ -95,11 +132,13 @@ namespace ignition
/// \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(const common::Time &_now) function returned true.
/// 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 Update(const common::Time &_now, const bool _force);
public: bool Update(
const std::chrono::steady_clock::duration &_now, const bool _force);

/// \brief Get the update rate of the sensor.
///
Expand Down
3 changes: 2 additions & 1 deletion include/ignition/sensors/ThermalCameraSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ namespace ignition
/// \brief Force the sensor to generate data
/// \param[in] _now The current time
/// \return true if the update was successfull
public: virtual bool Update(const common::Time &_now) override;
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Force the sensor to generate data
/// \param[in] _now The current time
Expand Down
13 changes: 10 additions & 3 deletions src/AirPressureSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ bool AirPressureSensor::Load(sdf::ElementPtr _sdf)
}

//////////////////////////////////////////////////
bool AirPressureSensor::Update(const ignition::common::Time &_now)
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)
{
IGN_PROFILE("AirPressureSensor::Update");
if (!this->dataPtr->initialized)
Expand All @@ -143,8 +151,7 @@ bool AirPressureSensor::Update(const ignition::common::Time &_now)
}

msgs::FluidPressure msg;
msg.mutable_header()->mutable_stamp()->set_sec(_now.sec);
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
*msg.mutable_header()->mutable_stamp() = msgs::Convert(_now);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
Expand Down
12 changes: 9 additions & 3 deletions src/AltimeterSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ bool AltimeterSensor::Load(sdf::ElementPtr _sdf)
}

//////////////////////////////////////////////////
bool AltimeterSensor::Update(const ignition::common::Time &_now)
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)
{
IGN_PROFILE("AltimeterSensor::Update");
if (!this->dataPtr->initialized)
Expand All @@ -140,8 +147,7 @@ bool AltimeterSensor::Update(const ignition::common::Time &_now)
}

msgs::Altimeter msg;
msg.mutable_header()->mutable_stamp()->set_sec(_now.sec);
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
*msg.mutable_header()->mutable_stamp() = msgs::Convert(_now);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
Expand Down
20 changes: 13 additions & 7 deletions src/CameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,14 @@ void CameraSensor::SetScene(ignition::rendering::ScenePtr _scene)
}

//////////////////////////////////////////////////
bool CameraSensor::Update(const ignition::common::Time &_now)
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)
{
IGN_PROFILE("CameraSensor::Update");
if (!this->dataPtr->initialized)
Expand Down Expand Up @@ -387,8 +394,7 @@ bool CameraSensor::Update(const ignition::common::Time &_now)
msg.set_step(width * rendering::PixelUtil::BytesPerPixel(
this->dataPtr->camera->ImageFormat()));
msg.set_pixel_format_type(msgsPixelFormat);
msg.mutable_header()->mutable_stamp()->set_sec(_now.sec);
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
*msg.mutable_header()->mutable_stamp() = msgs::Convert(_now);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
Expand Down Expand Up @@ -524,11 +530,11 @@ bool CameraSensor::AdvertiseInfo(const std::string &_topic)
}

//////////////////////////////////////////////////
void CameraSensor::PublishInfo(const ignition::common::Time &_now)
void CameraSensor::PublishInfo(
const std::chrono::steady_clock::duration &_now)
{
this->dataPtr->infoMsg.mutable_header()->mutable_stamp()->set_sec(_now.sec);
this->dataPtr->infoMsg.mutable_header()->mutable_stamp()->set_nsec(
_now.nsec);
*this->dataPtr->infoMsg.mutable_header()->mutable_stamp() =
msgs::Convert(_now);
this->dataPtr->infoPub.Publish(this->dataPtr->infoMsg);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Camera_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ TEST(Camera_TEST, CreateCamera)

// however camera is not loaded because a rendering scene is missing so
// updates will not be successful and image size will be 0
EXPECT_FALSE(cam->Update(ignition::common::Time()));
EXPECT_FALSE(cam->Update(std::chrono::steady_clock::duration::zero()));
EXPECT_EQ(0u, cam->ImageWidth());
EXPECT_EQ(0u, cam->ImageHeight());

Expand Down
12 changes: 5 additions & 7 deletions src/DepthCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ void DepthCameraSensor::SetScene(ignition::rendering::ScenePtr _scene)
}

//////////////////////////////////////////////////
bool DepthCameraSensor::Update(const ignition::common::Time &_now)
bool DepthCameraSensor::Update(
const std::chrono::steady_clock::duration &_now)
{
IGN_PROFILE("DepthCameraSensor::Update");
if (!this->dataPtr->initialized)
Expand Down Expand Up @@ -528,8 +529,7 @@ bool DepthCameraSensor::Update(const ignition::common::Time &_now)
msg.set_step(width * rendering::PixelUtil::BytesPerPixel(
rendering::PF_FLOAT32_R));
msg.set_pixel_format_type(msgsFormat);
msg.mutable_header()->mutable_stamp()->set_sec(_now.sec);
msg.mutable_header()->mutable_stamp()->set_nsec(_now.nsec);
*msg.mutable_header()->mutable_stamp() = msgs::Convert(_now);
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
frame->add_value(this->Name());
Expand Down Expand Up @@ -560,10 +560,8 @@ bool DepthCameraSensor::Update(const ignition::common::Time &_now)
this->dataPtr->pointCloudBuffer)
{
// Set the time stamp
this->dataPtr->pointMsg.mutable_header()->mutable_stamp()->set_sec(
_now.sec);
this->dataPtr->pointMsg.mutable_header()->mutable_stamp()->set_nsec(
_now.nsec);
*this->dataPtr->pointMsg.mutable_header()->mutable_stamp() =
msgs::Convert(_now);
this->dataPtr->pointMsg.set_is_dense(true);

if (!this->dataPtr->xyzBuffer)
Expand Down
Loading