Skip to content

Commit

Permalink
Tick-tock ignition:type
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <[email protected]>
  • Loading branch information
methylDragon committed Jun 7, 2022
1 parent f998e4f commit 27f1f57
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ release will remove the deprecated code.
1. The `ignition` namespace is deprecated and will be removed in future versions. Use `gz` instead.

1. Header files under `ignition/...` are deprecated and will be removed in future versions.
Use `gz/...` instead.
Use `gz/...` instead.

1. The `ignition:type` SDF attribute is deprecated and will be removed.
Please use `gz:type` instead.

## Gazebo Sensors 6.0.1 to 6.1.0

Expand Down
2 changes: 1 addition & 1 deletion examples/loop_sensor/sensors.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</vertical_velocity>
</altimeter>
</sensor>
<sensor name="custom_odometer" type="custom" ignition:type="odometer">
<sensor name="custom_odometer" type="custom" gz:type="odometer">
<always_on>1</always_on>
<update_rate>30</update_rate>
<topic>odometer</topic>
Expand Down
8 changes: 4 additions & 4 deletions include/gz/sensors/Util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ inline namespace GZ_SENSORS_VERSION_NAMESPACE {
///
/// Given an SDF tag as follows:
///
/// <sensor name="sensor_name" type="custom" ignition:type="sensor_type">
/// <sensor name="sensor_name" type="custom" gz:type="sensor_type">
///
/// This function returns `sensor_type`.
///
/// It will return an empty string if the element is malformed. For example,
/// if it misses the `ignition:type` attribute or is not of `type="custom"`.
/// if it misses the `gz:type` attribute or is not of `type="custom"`.
///
/// \param[in] _sdf Sensor SDF object.
/// \return _sensorType Name of sensor type.
Expand All @@ -51,12 +51,12 @@ std::string GZ_SENSORS_VISIBLE customType(const sdf::Sensor &_sdf); // NOLINT
///
/// Given an SDF tag as follows:
///
/// <sensor name="sensor_name" type="custom" ignition:type="sensor_type">
/// <sensor name="sensor_name" type="custom" gz:type="sensor_type">
///
/// This function returns `sensor_type`.
///
/// It will return an empty string if the element is malformed. For example,
/// if it misses the `ignition:type` attribute or is not of `type="custom"`.
/// if it misses the `gz:type` attribute or is not of `type="custom"`.
///
/// \param[in] _sdf Sensor SDF object.
/// \return _sensorType Name of sensor type.
Expand Down
19 changes: 15 additions & 4 deletions src/Util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,22 @@ std::string gz::sensors::customType(sdf::ElementPtr _sdf)
return std::string();
}

if (!_sdf->HasAttribute("ignition:type"))
if (!_sdf->HasAttribute("gz:type"))
{
gzerr << "Custom sensor missing `ignition:type` attribute." << std::endl;
return std::string();
// TODO(CH3): Deprecated. Remove on tock.
// Try deprecated ignition:type attribute if gz:type attribute is missing
if (_sdf->HasAttribute("ignition:type"))
{
gzwarn << "The `ignition:type` attribute is deprecated. Please use "
<< "`gz:type` instead." << std::endl;
return _sdf->Get<std::string>("ignition:type");
}
else
{
gzerr << "Custom sensor missing `gz:type` attribute." << std::endl;
return std::string();
}
}

return _sdf->Get<std::string>("ignition:type");
return _sdf->Get<std::string>("gz:type");
}
4 changes: 2 additions & 2 deletions test/sdf/custom_sensors.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<world name="my_world">
<model name="my_model">
<link name="my_link">
<sensor name="complete" type="custom" ignition:type="sensor_type">
<sensor name="complete" type="custom" gz:type="sensor_type">
<ignition:sensor_type/>
</sensor>
<sensor name="wrong_type" type="imu" ignition:type="sensor_type">
<sensor name="wrong_type" type="imu" gz:type="sensor_type">
<ignition:sensor_type/>
</sensor>
<sensor name="missing_ignition_type" type="custom">
Expand Down
4 changes: 2 additions & 2 deletions tutorials/custom_sensors.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ type. Seismometer? Breathalyzer? Just adapt the logic to your needs.
Custom sensors follow these rules to be loaded from SDFormat:

* Use `type="custom"` inside the `<sensor>` tag
* Add an extra `ignition:type="odometer"` attribute, where `odometer`
* Add an extra `gz:type="odometer"` attribute, where `odometer`
is a string that uniquely identifies the sensor type.
* Optionally, add an `<ignition:odometer/>` element with configuration
specific to that sensor.

With that in mind, here's what the sensor tag would look like:

```xml
<sensor name="the_odometer" type="custom" ignition:type="odometer">
<sensor name="the_odometer" type="custom" gz:type="odometer">
<always_on>1</always_on>
<update_rate>30</update_rate>
<topic>odom</topic>
Expand Down

0 comments on commit 27f1f57

Please sign in to comment.