DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

sensors/sensormanager/docs/usecase1.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
2 
3 @page sensormanager_usecase1 Sensor Manager Workflow
4 
5 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
6 
7 ## Workflow
8 
9 Before we can instantiate Sensor Manager, we need to declare and instantiate
10 NVIDIA<sup>&reg;</sup> DriveWorks @ref core_usecase5 , Sensor Abstration Layer and @ref rig_mainsection :
11 
12 ```{.cpp}
13 dwContextHandle_t ctx = DW_NULL_HANDLE;
14 dwSALHandle_t sal = DW_NULL_HANDLE;
15 dwRigHandle_t rc = DW_NULL_HANDLE;
16 dwSensorManagerHandle_t sm = DW_NULL_HANDLE;
17 
18 dwContextParameters ctxParams = {};
19 constexpr size_t poolSize = 16;
20 const dwSensorEvent * event = nullptr;
21 dwStatus ret = DW_SUCCESS;
22 
23 ret = dwInitialize(&ctx, DW_VERSION, &ctxParams);
24 checkError(ret);
25 
26 ret = dwSAL_initialize(&sal, ctx);
27 checkError(ret);
28 
29 ret = dwRig_initializeFromFile(&rc, ctx, "rig.json");
30 checkError(ret);
31 ```
32 
33 Now we can initialize Sensor Manager and start the underlying sensors:
34 
35 ```{.cpp}
36 ret = dwSensorManager_initializeFromRig(&sm, rc, poolSize, sal);
37 checkError(ret);
38 
39 ret = dwSensorManager_start(sm);
40 checkError(ret);
41 ```
42 
43 Once Sensor Manager object initialized and sensors are started, it is possible
44 to read events in a loop:
45 
46 ```{.cpp}
47 while (ret == DW_SUCCESS) {
48  ret = dwSensorManager_acquireNextEvent(&event, 0, sm);
49  checkError(ret);
50 
51  switch (event->type) {
52  case DW_SENSOR_RADAR: /* Process Event */ break;
53  case DW_SENSOR_LIDAR: /* Process Event */ break;
54  case DW_SENSOR_CAN: /* Process Event */ break;
55  case DW_SENSOR_GPS: /* Process Event */ break;
56  case DW_SENSOR_IMU: /* Process Event */ break;
57  case DW_SENSOR_CAMERA: /* Process Event */ break;
58  }
59 
60  ret = dwSensorManager_releaseAcquiredEvent(event, sm);
61  checkError(ret);
62 }
63 ```
64 
65 Clean-up procedure consists of stopping Sensor Manager and releasing the memory:
66 
67 ```{.cpp}
68 ret = dwSensorManager_stop(sm);
69 checkError(ret);
70 
71 ret = dwSensorManager_release(&sm);
72 checkError(ret);
73 ```
74 
75 Similarly, DriveWorks @ref core_usecase5, SAL and @ref rig_mainsection objects must be
76 released at the end.
77 
78 Sensor Manager is used in multiple samples:
79 - @ref dwx_camera_calibration_sample
80 - @ref dwx_imu_calibration_sample
81 - @ref dwx_lidar_calibration_sample
82 - @ref dwx_struct_from_motion_sample