6
6
*
7
7
*/
8
8
9
+ #include < Lidar/ROS2Lidar2DSensorComponent.h>
9
10
#include < Lidar/ROS2LidarSensorComponent.h>
10
11
#include < ROS2/Frame/ROS2FrameComponent.h>
11
12
#include < RobotImporter/SDFormat/ROS2SensorHooks.h>
@@ -19,7 +20,7 @@ namespace ROS2::SDFormat
19
20
SensorImporterHook ROS2SensorHooks::ROS2LidarSensor ()
20
21
{
21
22
SensorImporterHook importerHook;
22
- importerHook.m_sensorTypes = AZStd::unordered_set<sdf::SensorType>{ sdf::SensorType::LIDAR };
23
+ importerHook.m_sensorTypes = AZStd::unordered_set<sdf::SensorType>{ sdf::SensorType::LIDAR, sdf::SensorType::GPU_LIDAR };
23
24
importerHook.m_supportedSensorParams = AZStd::unordered_set<AZStd::string>{
24
25
" >update_rate" ,
25
26
" >lidar>scan>horizontal>samples" ,
@@ -51,28 +52,53 @@ namespace ROS2::SDFormat
51
52
return AZ::Failure (AZStd::string (" Failed to read parsed SDFormat data of %s Lidar sensor" , sdfSensor.Name ().c_str ()));
52
53
}
53
54
55
+ const bool is2DLidar = (lidarSensor->VerticalScanSamples () == 1 );
56
+
54
57
SensorConfiguration sensorConfiguration;
55
58
sensorConfiguration.m_frequency = sdfSensor.UpdateRate ();
56
- const AZStd::string messageType = " sensor_msgs::msg::PointCloud2" ;
57
- Utils::AddTopicConfiguration (sensorConfiguration, " pc" , messageType, messageType);
59
+ const AZStd::string messageType = is2DLidar ? " sensor_msgs::msg::LaserScan" : " sensor_msgs::msg::PointCloud2" ;
60
+ const AZStd::string messageTopic = is2DLidar ? " scan" : " pc" ;
61
+ Utils::AddTopicConfiguration (sensorConfiguration, messageTopic, messageType, messageType);
58
62
59
- LidarSensorConfiguration lidarConfiguration;
60
- lidarConfiguration. m_lidarParameters . m_model = LidarTemplate::LidarModel::Custom3DLidar ;
63
+ LidarSensorConfiguration lidarConfiguration{ is2DLidar ? LidarTemplateUtils::Get2DModels ()
64
+ : LidarTemplateUtils::Get3DModels () } ;
61
65
lidarConfiguration.m_lidarParameters .m_name = AZStd::string (sdfSensor.Name ().c_str ());
62
66
lidarConfiguration.m_lidarParameters .m_minHAngle = lidarSensor->HorizontalScanMinAngle ().Degree ();
63
67
lidarConfiguration.m_lidarParameters .m_maxHAngle = lidarSensor->HorizontalScanMaxAngle ().Degree ();
64
68
lidarConfiguration.m_lidarParameters .m_minVAngle = lidarSensor->VerticalScanMinAngle ().Degree ();
65
69
lidarConfiguration.m_lidarParameters .m_maxVAngle = lidarSensor->VerticalScanMaxAngle ().Degree ();
66
- lidarConfiguration.m_lidarParameters .m_layers = lidarSensor->HorizontalScanSamples ();
67
- lidarConfiguration.m_lidarParameters .m_numberOfIncrements = lidarSensor->VerticalScanSamples ();
70
+ lidarConfiguration.m_lidarParameters .m_numberOfIncrements = lidarSensor->HorizontalScanSamples ();
71
+ lidarConfiguration.m_lidarParameters .m_layers = lidarSensor->VerticalScanSamples ();
68
72
lidarConfiguration.m_lidarParameters .m_minRange = lidarSensor->RangeMin ();
69
73
lidarConfiguration.m_lidarParameters .m_maxRange = lidarSensor->RangeMax ();
70
74
75
+ const auto lidarSystems = LidarRegistrarInterface::Get ()->GetRegisteredLidarSystems ();
76
+ if (!lidarSystems.empty ())
77
+ {
78
+ const AZStd::string query = (sdfSensor.Type () == sdf::SensorType::GPU_LIDAR ? " RobotecGPULidar" : LidarSystem::SystemName);
79
+ if (const auto it = AZStd::find (lidarSystems.begin (), lidarSystems.end (), query); it != lidarSystems.end ())
80
+ {
81
+ lidarConfiguration.m_lidarSystem = *it;
82
+ }
83
+ }
84
+
85
+ if (lidarConfiguration.m_lidarSystem .empty ())
86
+ {
87
+ AZ_Warning (" ROS2LidarSensorHook" , false , " Lidar System in imported robot not set." );
88
+ AZ_Warning (
89
+ " ROS2LidarSensorHook" ,
90
+ sdfSensor.Type () != sdf::SensorType::GPU_LIDAR,
91
+ " GPU Lidar requires RGL Gem, see https://github.com/RobotecAI/o3de-rgl-gem for more details.\n " );
92
+ }
93
+
71
94
// Create required components
72
95
Utils::CreateComponent<ROS2FrameComponent>(entity);
73
96
74
97
// Create Lidar component
75
- if (Utils::CreateComponent<ROS2LidarSensorComponent>(entity, sensorConfiguration, lidarConfiguration))
98
+ const auto lidarComponent = is2DLidar
99
+ ? Utils::CreateComponent<ROS2Lidar2DSensorComponent>(entity, sensorConfiguration, lidarConfiguration)
100
+ : Utils::CreateComponent<ROS2LidarSensorComponent>(entity, sensorConfiguration, lidarConfiguration);
101
+ if (lidarComponent)
76
102
{
77
103
return AZ::Success ();
78
104
}
0 commit comments