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 9 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
3 changes: 2 additions & 1 deletion include/ignition/sensors/AirPressureSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ 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 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
3 changes: 2 additions & 1 deletion include/ignition/sensors/AltimeterSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ 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 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
6 changes: 4 additions & 2 deletions include/ignition/sensors/CameraSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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;

/// \brief Set a callback to be called when image frame data is
/// generated.
Expand Down Expand Up @@ -138,7 +139,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
3 changes: 2 additions & 1 deletion include/ignition/sensors/ImuSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ 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 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
6 changes: 4 additions & 2 deletions include/ignition/sensors/Lidar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ 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;

/// \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
3 changes: 2 additions & 1 deletion include/ignition/sensors/LogicalCameraSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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;

/// \brief Get the near distance. This is the distance from the
/// frustum's vertex to the closest plane.
Expand Down
3 changes: 2 additions & 1 deletion include/ignition/sensors/MagnetometerSensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ 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 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
11 changes: 7 additions & 4 deletions include/ignition/sensors/Sensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ 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 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: std::chrono::steady_clock::duration NextUpdateTime() const;

/// \brief Update the sensor.
///
Expand All @@ -95,11 +96,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
6 changes: 3 additions & 3 deletions src/AirPressureSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ bool AirPressureSensor::Load(sdf::ElementPtr _sdf)
}

//////////////////////////////////////////////////
bool AirPressureSensor::Update(const ignition::common::Time &_now)
bool AirPressureSensor::Update(
const std::chrono::steady_clock::duration &_now)
{
IGN_PROFILE("AirPressureSensor::Update");
if (!this->dataPtr->initialized)
Expand All @@ -143,8 +144,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
5 changes: 2 additions & 3 deletions src/AltimeterSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool AltimeterSensor::Load(sdf::ElementPtr _sdf)
}

//////////////////////////////////////////////////
bool AltimeterSensor::Update(const ignition::common::Time &_now)
bool AltimeterSensor::Update(const std::chrono::steady_clock::duration &_now)
{
IGN_PROFILE("AltimeterSensor::Update");
if (!this->dataPtr->initialized)
Expand All @@ -140,8 +140,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
13 changes: 6 additions & 7 deletions src/CameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void CameraSensor::SetScene(ignition::rendering::ScenePtr _scene)
}

//////////////////////////////////////////////////
bool CameraSensor::Update(const ignition::common::Time &_now)
bool CameraSensor::Update(const std::chrono::steady_clock::duration &_now)
{
IGN_PROFILE("CameraSensor::Update");
if (!this->dataPtr->initialized)
Expand Down Expand Up @@ -387,8 +387,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 +523,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
9 changes: 3 additions & 6 deletions src/GpuLidarSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ bool GpuLidarSensor::CreateLidar()
}

//////////////////////////////////////////////////
bool GpuLidarSensor::Update(const ignition::common::Time &_now)
bool GpuLidarSensor::Update(const std::chrono::steady_clock::duration &_now)
{
IGN_PROFILE("GpuLidarSensor::Update");
if (!this->initialized)
Expand Down Expand Up @@ -237,11 +237,8 @@ bool GpuLidarSensor::Update(const ignition::common::Time &_now)
if (this->dataPtr->pointPub.HasConnections())
{
// 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);

this->dataPtr->FillPointCloudMsg();
Expand Down
12 changes: 7 additions & 5 deletions src/ImuSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class ignition::sensors::ImuSensorPrivate
public: bool timeInitialized = false;

/// \brief Previous update time step.
public: ignition::common::Time prevStep { ignition::common::Time::Zero };
public: std::chrono::steady_clock::duration prevStep
{std::chrono::steady_clock::duration::zero()};

/// \brief Noise added to sensor data
public: std::map<SensorNoiseType, NoisePtr> noises;
Expand Down Expand Up @@ -146,7 +147,7 @@ bool ImuSensor::Load(sdf::ElementPtr _sdf)
}

//////////////////////////////////////////////////
bool ImuSensor::Update(const ignition::common::Time &_now)
bool ImuSensor::Update(const std::chrono::steady_clock::duration &_now)
{
IGN_PROFILE("ImuSensor::Update");
if (!this->dataPtr->initialized)
Expand All @@ -165,7 +166,9 @@ bool ImuSensor::Update(const ignition::common::Time &_now)
double dt;
if (this->dataPtr->timeInitialized)
{
dt = (_now - this->dataPtr->prevStep).Double();
auto delay = std::chrono::duration_cast<std::chrono::duration<float>>(
_now - this->dataPtr->prevStep);
dt = delay.count();
}
else
{
Expand Down Expand Up @@ -200,8 +203,7 @@ bool ImuSensor::Update(const ignition::common::Time &_now)
this->dataPtr->worldPose.Rot();

msgs::IMU 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);
msg.set_entity_name(this->Name());
auto frame = msg.mutable_header()->add_data();
frame->set_key("frame_id");
Expand Down
12 changes: 8 additions & 4 deletions src/ImuSensor_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ TEST(ImuSensor_TEST, ComputeNoise)
// Note no gravity.
sensor_truth->SetGravity(math::Vector3d::Zero);

sensor->Update(common::Time(0, 10000000));
sensor_truth->Update(common::Time(0, 10000000));
sensor->Update(std::chrono::steady_clock::duration(
std::chrono::nanoseconds(10000000)));
sensor_truth->Update(std::chrono::steady_clock::duration(
std::chrono::nanoseconds(10000000)));

// Since this IMU has no noise, measurements should equal the inputs.
EXPECT_DOUBLE_EQ(sensor_truth->AngularVelocity().X(), 0.0);
Expand All @@ -275,8 +277,10 @@ TEST(ImuSensor_TEST, ComputeNoise)
EXPECT_GT(sensor->AngularVelocity().SquaredLength(), 0.0);
EXPECT_GT(sensor->LinearAcceleration().SquaredLength(), 0.0);

sensor->Update(common::Time(0, 20000000));
sensor_truth->Update(common::Time(0, 20000000));
sensor->Update(std::chrono::steady_clock::duration(
std::chrono::nanoseconds(20000000)));
sensor_truth->Update(std::chrono::steady_clock::duration(
std::chrono::nanoseconds(20000000)));

// Since this IMU has no noise, measurements should equal the inputs.
EXPECT_DOUBLE_EQ(sensor_truth->AngularVelocity().X(), 0.0);
Expand Down
Loading