|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 Open Source Robotics Foundation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | +*/ |
| 17 | + |
| 18 | +#include <gtest/gtest.h> |
| 19 | + |
| 20 | +#include <string> |
| 21 | + |
| 22 | +// TODO(ahcorde) this is to remove deprecated "warnings" in usd, these warnings |
| 23 | +// are reported using #pragma message so normal diagnostic flags cannot remove |
| 24 | +// them. This workaround requires this block to be used whenever usd is |
| 25 | +// included. |
| 26 | +#pragma push_macro ("__DEPRECATED") |
| 27 | +#undef __DEPRECATED |
| 28 | +#include <pxr/usd/usd/stage.h> |
| 29 | +#pragma pop_macro ("__DEPRECATED") |
| 30 | + |
| 31 | +#include <ignition/math/Pose3.hh> |
| 32 | + |
| 33 | +#include "test_config.h" |
| 34 | +#include "test_utils.hh" |
| 35 | + |
| 36 | +#include "USDSensors.hh" |
| 37 | + |
| 38 | +#include "sdf/Sensor.hh" |
| 39 | +#include "sdf/Camera.hh" |
| 40 | +#include "sdf/Lidar.hh" |
| 41 | +#include "sdf/usd/usd_parser/USDData.hh" |
| 42 | + |
| 43 | +///////////////////////////////////////////////// |
| 44 | +TEST(USDJointTest, JointTest) |
| 45 | +{ |
| 46 | + const std::string filename = |
| 47 | + sdf::testing::TestFile("usd", "sensors.usda"); |
| 48 | + const auto stage = pxr::UsdStage::Open(filename); |
| 49 | + ASSERT_TRUE(stage); |
| 50 | + |
| 51 | + sdf::usd::USDData usdData(filename); |
| 52 | + usdData.Init(); |
| 53 | + |
| 54 | + const auto cameraPrim = stage->GetPrimAtPath(pxr::SdfPath( |
| 55 | + "/camera")); |
| 56 | + ASSERT_TRUE(cameraPrim); |
| 57 | + |
| 58 | + sdf::Sensor sensorCamera = sdf::usd::ParseSensors( |
| 59 | + cameraPrim, usdData); |
| 60 | + |
| 61 | + EXPECT_EQ(sdf::SensorType::CAMERA, sensorCamera.Type()); |
| 62 | + EXPECT_EQ(ignition::math::Pose3d(-1.83617, 0, 0.773532, 0, 0.267035, -0), |
| 63 | + sensorCamera.RawPose()); |
| 64 | + auto cameraSDF = sensorCamera.CameraSensor(); |
| 65 | + ASSERT_TRUE(cameraSDF); |
| 66 | + EXPECT_EQ(640u, cameraSDF->ImageWidth()); |
| 67 | + EXPECT_EQ(480u, cameraSDF->ImageHeight()); |
| 68 | + EXPECT_EQ(sdf::PixelFormatType::RGB_INT8, cameraSDF->PixelFormat()); |
| 69 | + EXPECT_DOUBLE_EQ(1000000, cameraSDF->FarClip()); |
| 70 | + EXPECT_DOUBLE_EQ(1, cameraSDF->NearClip()); |
| 71 | + EXPECT_DOUBLE_EQ(20.955, cameraSDF->HorizontalFov().Radian()); |
| 72 | + EXPECT_DOUBLE_EQ(24.0, cameraSDF->LensFocalLength()); |
| 73 | + |
| 74 | + const auto lidarPrim = stage->GetPrimAtPath(pxr::SdfPath( |
| 75 | + "/lidar")); |
| 76 | + ASSERT_TRUE(lidarPrim); |
| 77 | + |
| 78 | + sdf::Sensor sensorLidar = sdf::usd::ParseSensors( |
| 79 | + lidarPrim, usdData); |
| 80 | + |
| 81 | + EXPECT_EQ(sdf::SensorType::GPU_LIDAR, sensorLidar.Type()); |
| 82 | + auto lidarSDF = sensorLidar.LidarSensor(); |
| 83 | + ASSERT_TRUE(lidarSDF); |
| 84 | + EXPECT_DOUBLE_EQ(-180.00000500895632, |
| 85 | + lidarSDF->HorizontalScanMinAngle().Degree()); |
| 86 | + EXPECT_DOUBLE_EQ(180.00000500895632, |
| 87 | + lidarSDF->HorizontalScanMaxAngle().Degree()); |
| 88 | + EXPECT_DOUBLE_EQ(1, lidarSDF->HorizontalScanResolution()); |
| 89 | + EXPECT_DOUBLE_EQ(900, lidarSDF->HorizontalScanSamples()); |
| 90 | + |
| 91 | + EXPECT_DOUBLE_EQ(-15.000000417413029, |
| 92 | + lidarSDF->VerticalScanMinAngle().Degree()); |
| 93 | + EXPECT_DOUBLE_EQ(15.000000417413029, |
| 94 | + lidarSDF->VerticalScanMaxAngle().Degree()); |
| 95 | + EXPECT_DOUBLE_EQ(1, lidarSDF->VerticalScanResolution()); |
| 96 | + EXPECT_DOUBLE_EQ(7, lidarSDF->VerticalScanSamples()); |
| 97 | + |
| 98 | + EXPECT_DOUBLE_EQ(0.40000000596046448, lidarSDF->RangeMin()); |
| 99 | + EXPECT_DOUBLE_EQ(100, lidarSDF->RangeMax()); |
| 100 | + EXPECT_DOUBLE_EQ(0.1, lidarSDF->RangeResolution()); |
| 101 | + EXPECT_DOUBLE_EQ(20, sensorLidar.UpdateRate()); |
| 102 | +} |
0 commit comments