-
Notifications
You must be signed in to change notification settings - Fork 118
NavSat::ToElement() method #1585
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
base: sdf16
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -15,6 +15,8 @@ | |||
| * | ||||
| */ | ||||
| #include "sdf/NavSat.hh" | ||||
| #include "sdf/parser.hh" | ||||
| #include "Utils.hh" | ||||
|
|
||||
| using namespace sdf; | ||||
| using namespace gz; | ||||
|
|
@@ -191,3 +193,52 @@ bool NavSat::operator!=(const NavSat &_navsat) const | |||
| { | ||||
| return !(*this == _navsat); | ||||
| } | ||||
|
|
||||
| ///////////////////////////////////////////////// | ||||
| sdf::ElementPtr NavSat::ToElement() const | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been adding an implementation that takes an Line 265 in dcd3c2d
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Still I'm quite curious how we can get a error status (except invalid tag as a parameter). I mean, when parsing a user's input, error is not something unexpected, but here we are constructing tag from scratch basically.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is possible for there to be errors in the spec (e.g., |
||||
| { | ||||
| 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) | ||||
azeey marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| { | ||||
| 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; | ||||
| } | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,7 @@ constexpr std::array<const std::string_view, 27> kSensorTypeStrs = | |
|
|
||
| class sdf::Sensor::Implementation | ||
| { | ||
| // \brief The sensor type. | ||
| /// \brief The sensor type. | ||
| public: SensorType type = SensorType::NONE; | ||
|
|
||
| /// \brief Name of the sensor. | ||
|
|
@@ -762,82 +762,114 @@ sdf::ElementPtr Sensor::ToElement(sdf::Errors &_errors) 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()); | ||
|
|
||
| elem->GetElement("frame_id")->Set<std::string>(this->FrameId()); | ||
| 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()); | ||
|
|
||
| // 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()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just realized, in this function mix of functions is used. Also |
||
| if (this->dataPtr->airPressure) | ||
| { | ||
| sdf::ElementPtr airPressureElem = elem->GetElement("air_pressure"); | ||
| airPressureElem->Copy( | ||
| this->dataPtr->airPressure->ToElement(_errors), _errors); | ||
| } | ||
| } | ||
| // air speed | ||
| else if (this->Type() == sdf::SensorType::AIR_SPEED && | ||
| this->dataPtr->airSpeed) | ||
| else if (this->Type() == sdf::SensorType::AIR_SPEED) | ||
| { | ||
| sdf::ElementPtr airSpeedElem = elem->GetElement("air_speed"); | ||
| airSpeedElem->Copy(this->dataPtr->airSpeed->ToElement()); | ||
| 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); | ||
| } | ||
| } | ||
| // 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I already touched structure of this function, added |
||
| 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) | ||
| { | ||
| sdf::ElementPtr magnetometerElem = elem->GetElement("magnetometer"); | ||
| magnetometerElem->Copy(this->dataPtr->magnetometer->ToElement()); | ||
| 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) | ||
| { | ||
| if (this->dataPtr->navSat) | ||
| { | ||
| sdf::ElementPtr navSatElem = elem->GetElement("navsat"); | ||
| navSatElem->Copy(this->dataPtr->navSat->ToElement(_errors), _errors); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| std::stringstream ss; | ||
| ss << "Conversion of sensor type: [" << this->TypeStr() << "] from SDF " | ||
| << "DOM to Element is not supported yet." << this->Name(); | ||
| "DOM to Element is not supported yet." << this->Name() << '\n'; | ||
| _errors.push_back({ErrorCode::ELEMENT_INVALID, ss.str()}); | ||
| } | ||
|
|
||
| // Add in the plugins | ||
| for (const Plugin &plugin : this->dataPtr->plugins) | ||
| elem->InsertElement(plugin.ToElement(), true); | ||
| elem->InsertElement(plugin.ToElement(_errors), true); | ||
|
|
||
| return elem; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this text from similar method of other class (at least it consistent)