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

sdf -> usd: Added sensor #830

Merged
merged 32 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9dfc9f2
sdf -> usd Parse links
ahcorde Jan 25, 2022
ffaf2f4
sdf -> usd: Added Visual and geometries
ahcorde Jan 26, 2022
80d530e
sdf -> usd: Added sensor
ahcorde Jan 26, 2022
0a5a9a7
Fixed test
ahcorde Jan 26, 2022
04dc57d
Merge remote-tracking branch 'origin/ahcorde/sdf_to_usd_visuals' into…
ahcorde Jan 26, 2022
89daa0d
review feedback
adlarkin Jan 27, 2022
f48b35b
dont segfault when mesh failed to load
Jan 31, 2022
d932e90
fix error reporting
Jan 31, 2022
54b35e9
Merge branch 'sdf12' into ahcorde/sdf_to_usd_links
ahcorde Feb 1, 2022
f0331ca
Fixed scale and submesh name
ahcorde Feb 10, 2022
8339c09
Fixed laser pose and imu box size
ahcorde Feb 10, 2022
6497f8e
Fixed test
ahcorde Feb 10, 2022
e85f60c
Merge remote-tracking branch 'origin/sdf12' into ahcorde/sdf_to_usd_l…
ahcorde Feb 14, 2022
a02a6e1
Use UsdError
ahcorde Feb 14, 2022
f898d26
codecheck, use USD component's visibility macro, properly construct w…
adlarkin Feb 14, 2022
258606c
Merge branch 'ahcorde/sdf_to_usd_links' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 15, 2022
c43ba24
usd UsdErrors and USD component visibility
adlarkin Feb 15, 2022
f816dd4
Merge branch 'sdf12' into ahcorde/sdf_to_usd_links
adlarkin Feb 15, 2022
6f3490e
Merge branch 'ahcorde/sdf_to_usd_links' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 15, 2022
379defd
review feedback
adlarkin Feb 17, 2022
0f4075f
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 18, 2022
a98d481
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 18, 2022
0cb1cc0
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
ahcorde Feb 18, 2022
00a55c5
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
ahcorde Feb 21, 2022
7e085b5
Merge branch 'ahcorde/sdf_to_usd_visuals' into ahcorde/sdf_to_usd_sen…
ahcorde Feb 21, 2022
69d2099
udpate code
ahcorde Feb 21, 2022
3fc8eb2
Merge branch 'sdf12' into ahcorde/sdf_to_usd_sensors
ahcorde Feb 24, 2022
1693b08
Merge branch 'sdf12' into ahcorde/sdf_to_usd_sensors
adlarkin Feb 25, 2022
10d7da1
review feedback
adlarkin Feb 25, 2022
8903f48
Removed todo
ahcorde Feb 25, 2022
9a7527f
Merge branch 'sdf12' into ahcorde/sdf_to_usd_sensors
scpeters Feb 25, 2022
48ad6a5
Added feedback
ahcorde Feb 25, 2022
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
144 changes: 144 additions & 0 deletions test/sdf/usd_sensors.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" ?>
<sdf version="1.6">
<world name="sensors">
<model name="model_with_imu">
<pose>4 0 3.0 0 0.0 3.14</pose>
<link name="link">
<pose>0.05 0.05 0.05 0 0 0</pose>
<inertial>
<mass>0.1</mass>
<inertia>
<ixx>0.000166667</ixx>
<iyy>0.000166667</iyy>
<izz>0.000166667</izz>
</inertia>
</inertial>
<collision name="collision">
<geometry>
<box>
<size>0.1 0.1 0.1</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>0.1 0.1 0.1</size>
</box>
</geometry>
</visual>
<sensor name="imu" type="imu">
<always_on>1</always_on>
<update_rate>100</update_rate>
<visualize>true</visualize>
<topic>imu</topic>
<enable_metrics>true</enable_metrics>
</sensor>
</link>
</model>

<model name="model_with_camera">
<pose>4 0 1.0 0 0.0 3.14</pose>
<link name="link">
<pose>0.05 0.05 0.05 0 0 0</pose>
<inertial>
<mass>0.1</mass>
<inertia>
<ixx>0.000166667</ixx>
<iyy>0.000166667</iyy>
<izz>0.000166667</izz>
</inertia>
</inertial>
<collision name="collision">
<geometry>
<box>
<size>0.1 0.1 0.1</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>0.1 0.1 0.1</size>
</box>
</geometry>
</visual>
<sensor name="camera" type="camera">
<camera>
<horizontal_fov>1.047</horizontal_fov>
<image>
<width>320</width>
<height>240</height>
</image>
<clip>
<near>0.1</near>
<far>100</far>
</clip>
</camera>
<always_on>1</always_on>
<update_rate>30</update_rate>
<visualize>true</visualize>
<topic>camera</topic>
</sensor>
</link>
</model>

<model name="model_with_lidar">
<static>true</static>
<pose>4 0 0.5 0 0.0 3.14</pose>
<link name="link">
<pose>0.05 0.05 0.05 0 0 0</pose>
<inertial>
<mass>0.1</mass>
<inertia>
<ixx>0.000166667</ixx>
<iyy>0.000166667</iyy>
<izz>0.000166667</izz>
</inertia>
</inertial>
<collision name="collision">
<geometry>
<box>
<size>0.1 0.1 0.1</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>0.1 0.1 0.1</size>
</box>
</geometry>
</visual>

<sensor name='gpu_lidar' type='gpu_lidar'>
<topic>lidar</topic>
<update_rate>10</update_rate>
<lidar>
<scan>
<horizontal>
<samples>640</samples>
<resolution>1</resolution>
<min_angle>-1.396263</min_angle>
<max_angle>1.396263</max_angle>
</horizontal>
<vertical>
<samples>16</samples>
<resolution>1</resolution>
<min_angle>-0.261799</min_angle>
<max_angle>0.261799</max_angle>
</vertical>
</scan>
<range>
<min>0.08</min>
<max>10.0</max>
<resolution>0.01</resolution>
</range>
</lidar>
<alwaysOn>1</alwaysOn>
<visualize>true</visualize>
</sensor>
</link>
</model>
</world>
</sdf>
60 changes: 60 additions & 0 deletions usd/include/sdf/usd/sdf_parser/Sensor.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef SDF_USD_SDF_PARSER_SENSOR_HH_
#define SDF_USD_SDF_PARSER_SENSOR_HH_

#include <string>

// TODO(ahcorde) this is to remove deprecated "warnings" in usd, these warnings
// are reported using #pragma message so normal diagnostic flags cannot remove
// them. This workaround requires this block to be used whenever usd is
// included.
#pragma push_macro ("__DEPRECATED")
#undef __DEPRECATED
#include <pxr/usd/usd/stage.h>
#pragma pop_macro ("__DEPRECATED")

#include "sdf/Sensor.hh"
#include "sdf/usd/Export.hh"
#include "sdf/usd/UsdError.hh"
#include "sdf/sdf_config.h"

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
//
namespace usd
{
/// \brief Parse an SDF sensor into a USD stage.
/// \param[in] _sensor The SDF sensor to parse.
/// \param[in] _stage The stage that should contain the USD representation
/// of _sensor.
/// \param[in] _path The USD path of the parsed sensor in _stage, which must
/// be a valid USD path.
/// \return UsdErrors, which is a vector of UsdError objects. Each UsdError
/// includes an error code and message. An empty vector indicates no error.
UsdErrors IGNITION_SDFORMAT_USD_VISIBLE ParseSdfSensor(
const sdf::Sensor &_sensor,
pxr::UsdStageRefPtr &_stage,
const std::string &_path);
}
}
}

#endif
2 changes: 2 additions & 0 deletions usd/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(sources
sdf_parser/Light.cc
sdf_parser/Link.cc
sdf_parser/Model.cc
sdf_parser/Sensor.cc
sdf_parser/Visual.cc
sdf_parser/World.cc
)
Expand All @@ -31,6 +32,7 @@ set(gtest_sources
sdf_parser/Link_Sdf2Usd_TEST.cc
# TODO(adlarkin) add a test for SDF -> USD models once model parsing
# functionality is complete
sdf_parser/Sensors_Sdf2Usd_TEST.cc
sdf_parser/Visual_Sdf2Usd_TEST.cc
sdf_parser/World_Sdf2Usd_TEST.cc
UsdError_TEST.cc
Expand Down
17 changes: 17 additions & 0 deletions usd/src/sdf_parser/Link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "sdf/Link.hh"
#include "sdf/usd/sdf_parser/Light.hh"
#include "sdf/usd/sdf_parser/Sensor.hh"
#include "sdf/usd/sdf_parser/Visual.hh"
#include "../UsdUtils.hh"

Expand Down Expand Up @@ -140,6 +141,22 @@ namespace usd
}
}

// convert the link's sensors
for (uint64_t i = 0; i < _link.SensorCount(); ++i)
{
const auto sensor = *(_link.SensorByIndex(i));
const auto sensorPath = std::string(_path + "/" + sensor.Name());
UsdErrors errorsSensor = ParseSdfSensor(sensor, _stage, sensorPath);
if (!errorsSensor.empty())
{
errors.push_back(
UsdError(sdf::usd::UsdErrorCode::SDF_TO_USD_PARSING_ERROR,
"Error parsing sensor [" + sensor.Name() + "]"));
errors.insert(errors.end(), errorsSensor.begin(), errorsSensor.end());
return errors;
}
}

// links can have lights attached to them
for (uint64_t i = 0; i < _link.LightCount(); ++i)
{
Expand Down
Loading