Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 include/sdf/Error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace sdf
/// \sa Errors
enum class ErrorCode
{
// \brief No error
/// \brief No error
NONE = 0,

/// \brief Indicates that reading an SDF file failed.
Expand Down
15 changes: 15 additions & 0 deletions include/sdf/NavSat.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ namespace sdf
/// \return True if 'this' != _navsat.
public: bool operator!=(const NavSat &_navsat) const;

/// \brief Create and return an SDF element filled with data from this
/// NavSat.
/// Note that parameter passing functionality is not captured with this
/// function.
/// \return SDF element pointer with updated sensor values.
public: sdf::ElementPtr ToElement() const;

/// \brief Create and return an SDF element filled with data from this
/// NavSat.
/// Note that parameter passing functionality is not captured with this
/// function.
/// \param[out] _errors Vector of errors.
/// \return SDF element pointer with updated sensor values.
public: sdf::ElementPtr ToElement(sdf::Errors &_errors) const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
2 changes: 1 addition & 1 deletion src/Geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace sdf;
// Private data class
class sdf::Geometry::Implementation
{
// \brief The geometry type.
/// \brief The geometry type.
public: GeometryType type = GeometryType::EMPTY;

/// \brief Optional box.
Expand Down
51 changes: 51 additions & 0 deletions src/NavSat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/
#include "sdf/NavSat.hh"
#include "sdf/parser.hh"
#include "Utils.hh"

using namespace sdf;
using namespace gz;
Expand Down Expand Up @@ -191,3 +193,52 @@ bool NavSat::operator!=(const NavSat &_navsat) const
{
return !(*this == _navsat);
}

/////////////////////////////////////////////////
sdf::ElementPtr NavSat::ToElement() const
{
sdf::Errors errors;
auto result = this->ToElement(errors);
sdf::throwOrPrintErrors(errors);
return result;
}

/////////////////////////////////////////////////
sdf::ElementPtr NavSat::ToElement(sdf::Errors &_errors) const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("navsat.sdf", ParserConfig::GlobalConfig(), elem, _errors);
const auto defaultNoise = sdf::Noise();

if (this->dataPtr->horizontalPositionNoise != defaultNoise)
{
auto el = elem->GetElement("position_sensing", _errors)->
GetElement("horizontal", _errors)->GetElement("noise", _errors);
el->Copy(
this->dataPtr->horizontalPositionNoise.ToElement(_errors), _errors);
}

if (this->dataPtr->verticalPositionNoise != defaultNoise)
{
auto el = elem->GetElement("position_sensing", _errors)->
GetElement("vertical", _errors)->GetElement("noise", _errors);
el->Copy(this->dataPtr->verticalPositionNoise.ToElement(_errors), _errors);
}

if (this->dataPtr->horizontalVelocityNoise != defaultNoise)
{
auto el = elem->GetElement("velocity_sensing", _errors)->
GetElement("horizontal", _errors)->GetElement("noise", _errors);
el->Copy(
this->dataPtr->horizontalVelocityNoise.ToElement(_errors), _errors);
}

if (this->dataPtr->verticalVelocityNoise != defaultNoise)
{
auto el = elem->GetElement("velocity_sensing", _errors)->
GetElement("vertical", _errors)->GetElement("noise", _errors);
el->Copy(this->dataPtr->verticalVelocityNoise.ToElement(_errors), _errors);
}

return elem;
}
40 changes: 40 additions & 0 deletions src/NavSat_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,43 @@ TEST(DOMNavSat, Load)
EXPECT_EQ(sdf::ErrorCode::ELEMENT_INCORRECT_TYPE, errors[0].Code());
EXPECT_NE(nullptr, navSat.Element());
}

/////////////////////////////////////////////////
TEST(DOMNavSat, ToElement)
{
sdf::NavSat navSat;
sdf::Noise noiseHorPos;
noiseHorPos.SetType(sdf::NoiseType::GAUSSIAN);
noiseHorPos.SetMean(1.2);
noiseHorPos.SetStdDev(2.3);
noiseHorPos.SetBiasMean(4.5);
noiseHorPos.SetBiasStdDev(6.7);
noiseHorPos.SetPrecision(8.9);
navSat.SetHorizontalPositionNoise(noiseHorPos);

auto noiseVerPos = noiseHorPos;
noiseVerPos.SetMean(2.2);
navSat.SetVerticalPositionNoise(noiseVerPos);

auto noiseHorVel = noiseHorPos;
noiseHorVel.SetMean(3.2);
navSat.SetHorizontalVelocityNoise(noiseHorVel);

auto noiseVerVel = noiseHorPos;
noiseVerVel.SetMean(4.2);
navSat.SetVerticalVelocityNoise(noiseVerVel);

sdf::ElementPtr navSatElem = navSat.ToElement();
ASSERT_NE(nullptr, navSatElem);
EXPECT_EQ(nullptr, navSat.Element());

// verify values after loading the element back
sdf::NavSat navSat2;
auto errors = navSat2.Load(navSatElem);
ASSERT_TRUE(errors.empty());

EXPECT_EQ(noiseHorPos, navSat2.HorizontalPositionNoise());
EXPECT_EQ(noiseVerPos, navSat2.VerticalPositionNoise());
EXPECT_EQ(noiseHorVel, navSat2.HorizontalVelocityNoise());
EXPECT_EQ(noiseVerVel, navSat2.VerticalVelocityNoise());
}
6 changes: 3 additions & 3 deletions src/ScopedGraph.hh
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ class ScopedGraph
/// \return A new child scope.
public: ScopedGraph<T> ChildModelScope(const std::string &_name) const;

// \brief Get the root scope (the scope without any prefix). This is useful
// for resolving poses relative to the world.
// \return A new scope anchored at the root of the graph
/// \brief Get the root scope (the scope without any prefix). This is useful
/// for resolving poses relative to the world.
/// \return A new scope anchored at the root of the graph
public: ScopedGraph<T> RootScope() const;

/// \brief Checks if the scope points to a valid graph.
Expand Down
116 changes: 86 additions & 30 deletions src/Sensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const std::vector<std::string> sensorTypeStrs =

class sdf::Sensor::Implementation
{
// \brief The sensor type.
/// \brief The sensor type.
public: SensorType type = SensorType::NONE;

/// \brief Name of the sensor.
Expand Down Expand Up @@ -701,72 +701,128 @@ sdf::ElementPtr Sensor::ToElement() const
if (!this->dataPtr->poseRelativeTo.empty())
{
poseElem->GetAttribute("relative_to")->Set<std::string>(
this->dataPtr->poseRelativeTo);
this->dataPtr->poseRelativeTo, _errors);
}
poseElem->Set<gz::math::Pose3d>(this->RawPose());
poseElem->Set<gz::math::Pose3d>(_errors, this->RawPose());

<<<<<<< HEAD
elem->GetElement("topic")->Set<std::string>(this->Topic());
elem->GetElement("update_rate")->Set<double>(this->UpdateRate());
elem->GetElement("enable_metrics")->Set<double>(this->EnableMetrics());
=======
elem->GetElement("frame_id")->Set<std::string>(_errors, this->FrameId());
elem->GetElement("topic")->Set<std::string>(_errors, this->Topic());
elem->GetElement("update_rate")->Set<double>(_errors, this->UpdateRate());
elem->GetElement("enable_metrics")->Set<double>(_errors,
this->EnableMetrics());
>>>>>>> 8ccc60cd (NavSat::ToElement() method (#1585))

// air pressure
if (this->Type() == sdf::SensorType::AIR_PRESSURE &&
this->dataPtr->airPressure)
if (this->Type() == sdf::SensorType::AIR_PRESSURE)
{
sdf::ElementPtr airPressureElem = elem->GetElement("air_pressure");
airPressureElem->Copy(this->dataPtr->airPressure->ToElement());
if (this->dataPtr->airPressure)
{
sdf::ElementPtr airPressureElem = elem->GetElement("air_pressure");
airPressureElem->Copy(
this->dataPtr->airPressure->ToElement(_errors), _errors);
}
}
<<<<<<< HEAD
=======
// air speed
else if (this->Type() == sdf::SensorType::AIR_SPEED)
{
if (this->dataPtr->airSpeed)
{
// TODO(anyone) use ToElement with sdf::Error when it available
sdf::ElementPtr airSpeedElem = elem->GetElement("air_speed");
airSpeedElem->Copy(this->dataPtr->airSpeed->ToElement(), _errors);
}
}
>>>>>>> 8ccc60cd (NavSat::ToElement() method (#1585))
// altimeter
else if (this->Type() == sdf::SensorType::ALTIMETER &&
this->dataPtr->altimeter)
else if (this->Type() == sdf::SensorType::ALTIMETER)
{
sdf::ElementPtr altimeterElem = elem->GetElement("altimeter");
altimeterElem->Copy(this->dataPtr->altimeter->ToElement());
if (this->dataPtr->altimeter)
{
sdf::ElementPtr altimeterElem = elem->GetElement("altimeter");
altimeterElem->Copy(
this->dataPtr->altimeter->ToElement(_errors), _errors);
}
}
// camera, depth, thermal, segmentation
else if (this->CameraSensor())
{
// TODO(anyone) use ToElement with sdf::Error when it available
sdf::ElementPtr cameraElem = elem->GetElement("camera");
cameraElem->Copy(this->dataPtr->camera->ToElement());
cameraElem->Copy(this->dataPtr->camera->ToElement(), _errors);
}
// force torque
else if (this->Type() == sdf::SensorType::FORCE_TORQUE &&
this->dataPtr->forceTorque)
else if (this->Type() == sdf::SensorType::FORCE_TORQUE)
{
sdf::ElementPtr forceTorqueElem = elem->GetElement("force_torque");
forceTorqueElem->Copy(this->dataPtr->forceTorque->ToElement());
if (this->dataPtr->forceTorque)
{
sdf::ElementPtr forceTorqueElem = elem->GetElement("force_torque");
forceTorqueElem->Copy(
this->dataPtr->forceTorque->ToElement(_errors), _errors);
}
}
// imu
else if (this->Type() == sdf::SensorType::IMU && this->dataPtr->imu)
else if (this->Type() == sdf::SensorType::IMU)
{
sdf::ElementPtr imuElem = elem->GetElement("imu");
imuElem->Copy(this->dataPtr->imu->ToElement());
if (this->dataPtr->imu)
{
sdf::ElementPtr imuElem = elem->GetElement("imu");
imuElem->Copy(this->dataPtr->imu->ToElement(_errors), _errors);
}
}
// lidar, gpu_lidar
else if ((this->Type() == sdf::SensorType::GPU_LIDAR ||
this->Type() == sdf::SensorType::LIDAR) &&
this->dataPtr->lidar)
else if (this->Type() == sdf::SensorType::GPU_LIDAR ||
this->Type() == sdf::SensorType::LIDAR)
{
sdf::ElementPtr rayElem = (elem->HasElement("ray")) ?
elem->GetElement("ray") : elem->GetElement("lidar");
rayElem->Copy(this->dataPtr->lidar->ToElement());
if (this->dataPtr->lidar)
{
// TODO(anyone) use ToElement with sdf::Error when it available
sdf::ElementPtr rayElem = (elem->HasElement("ray")) ?
elem->GetElement("ray") : elem->GetElement("lidar");
rayElem->Copy(this->dataPtr->lidar->ToElement(), _errors);
}
}
// magnetometer
else if (this->Type() == sdf::SensorType::MAGNETOMETER &&
this->dataPtr->magnetometer)
else if (this->Type() == sdf::SensorType::MAGNETOMETER)
{
if (this->dataPtr->magnetometer)
{
// TODO(anyone) use ToElement with sdf::Error when it available
sdf::ElementPtr magnetometerElem = elem->GetElement("magnetometer");
magnetometerElem->Copy(
this->dataPtr->magnetometer->ToElement(), _errors);
}
}
else if (this->Type() == sdf::SensorType::NAVSAT)
{
sdf::ElementPtr magnetometerElem = elem->GetElement("magnetometer");
magnetometerElem->Copy(this->dataPtr->magnetometer->ToElement());
if (this->dataPtr->navSat)
{
sdf::ElementPtr navSatElem = elem->GetElement("navsat");
navSatElem->Copy(this->dataPtr->navSat->ToElement(_errors), _errors);
}
}
else
{
<<<<<<< HEAD
std::cout << "Conversion of sensor type: [" << this->TypeStr() << "] from "
<< "SDF DOM to Element is not supported yet." << std::endl;
=======
std::stringstream ss;
ss << "Conversion of sensor type: [" << this->TypeStr() << "] from SDF "
"DOM to Element is not supported yet." << this->Name() << '\n';
_errors.push_back({ErrorCode::ELEMENT_INVALID, ss.str()});
>>>>>>> 8ccc60cd (NavSat::ToElement() method (#1585))
}

// Add in the plugins
for (const Plugin &plugin : this->dataPtr->plugins)
elem->InsertElement(plugin.ToElement(), true);
elem->InsertElement(plugin.ToElement(_errors), true);

return elem;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ using namespace sdf;

class sdf::Contact::Implementation
{
<<<<<<< HEAD
// \brief The bitmask used to filter collisions.
public: uint16_t collideBitmask = 0xff;

=======
/// \brief The collide bitmask used to filter collisions.
public: uint16_t collideBitmask = 0xff;

/// \brief The category bitmask used to filter collisions.
public: std::optional<uint16_t> categoryBitmask;

>>>>>>> 8ccc60cd (NavSat::ToElement() method (#1585))
/// \brief The SDF element pointer used during load.
public: sdf::ElementPtr sdf{nullptr};
};
Expand Down
Loading