DriveWorks SDK Reference
5.8.83 Release
For Test and Development only

Sensor Manager Workflow

Workflow

Before we can instantiate Sensor Manager, we need to declare and instantiate NVIDIA® DriveWorks Context , Sensor Abstration Layer and Rig Configuration :

dwContextParameters ctxParams = {};
constexpr size_t POOL_SIZE = 16;
const dwSensorEvent * event = nullptr;
dwStatus ret = DW_SUCCESS;
ret = dwInitialize(&ctx, DW_VERSION, &ctxParams);
checkError(ret);
ret = dwSAL_initialize(&sal, ctx);
checkError(ret);
ret = dwRig_initializeFromFile(&rc, ctx, "rig.json");
checkError(ret);
#define DW_VERSION
DW_API_PUBLIC dwStatus dwInitialize(dwContextHandle_t *const context, dwVersion const headerVersion, dwContextParameters const *const params)
Creates and initializes an SDK context.
struct dwContextObject * dwContextHandle_t
Context handle.
Definition: Context.h:82
A set of parameters that is passed to the SDK to create the context.
Definition: Context.h:92
dwStatus
Status definition.
Definition: Status.h:171
#define DW_NULL_HANDLE
Definition: Types.h:96
struct dwRigObject * dwRigHandle_t
Handle representing the Rig interface.
Definition: Rig.h:70
DW_API_PUBLIC dwStatus dwRig_initializeFromFile(dwRigHandle_t *const obj, dwContextHandle_t const ctx, char8_t const *const configurationFile)
Initializes the Rig Configuration module from a file.
struct dwSensorManagerObject * dwSensorManagerHandle_t
Definition: SensorManager.h:71
Structure for returning data upon any sensor event.
Definition: SensorManager.h:78
struct dwSALObject * dwSALHandle_t
Handle representing the Sensor Abstraction Layer interface.
Definition: Sensors.h:83
DW_API_PUBLIC dwStatus dwSAL_initialize(dwSALHandle_t *const sal, dwContextHandle_t const context)
Creates and initializes a SAL (sensor abstraction layer) module.

Now we can initialize Sensor Manager and start the underlying sensors:

ret = dwSensorManager_initializeFromRig(&sm, rc, POOL_SIZE, sal);
checkError(ret);
checkError(ret);
DW_API_PUBLIC dwStatus dwSensorManager_initializeFromRig(dwSensorManagerHandle_t *sm, dwRigHandle_t rc, size_t poolSize, dwSALHandle_t sal)
Creates and initializes a SensorManager module, adding all sensors in the provided Rig Configuration.
DW_API_PUBLIC dwStatus dwSensorManager_start(dwSensorManagerHandle_t sm)
Starts all sensors.

Once Sensor Manager object initialized and sensors are started, it is possible to read events in a loop:

while (ret == DW_SUCCESS) {
ret = dwSensorManager_acquireNextEvent(&event, 0, sm);
checkError(ret);
switch (event->type) {
case DW_SENSOR_RADAR: /* Process Event */ break;
case DW_SENSOR_LIDAR: /* Process Event */ break;
case DW_SENSOR_CAN: /* Process Event */ break;
case DW_SENSOR_GPS: /* Process Event */ break;
case DW_SENSOR_IMU: /* Process Event */ break;
case DW_SENSOR_CAMERA: /* Process Event */ break;
}
checkError(ret);
}
DW_API_PUBLIC dwStatus dwSensorManager_acquireNextEvent(const dwSensorEvent **ev, dwTime_t timeoutMicroSeconds, dwSensorManagerHandle_t sm)
Called by the application to consume the next available sensor event ready for consumption.
DW_API_PUBLIC dwStatus dwSensorManager_releaseAcquiredEvent(const dwSensorEvent *ev, dwSensorManagerHandle_t sm)
Releases a previously acquired event back to the pool.
@ DW_SENSOR_LIDAR
Definition: Sensors.h:190
@ DW_SENSOR_CAN
Definition: Sensors.h:193
@ DW_SENSOR_IMU
Definition: Sensors.h:192
@ DW_SENSOR_RADAR
Definition: Sensors.h:194
@ DW_SENSOR_CAMERA
Definition: Sensors.h:189
@ DW_SENSOR_GPS
Definition: Sensors.h:191

Clean-up procedure consists of stopping Sensor Manager and releasing the memory:

checkError(ret);
checkError(ret);
DW_API_PUBLIC dwStatus dwSensorManager_stop(dwSensorManagerHandle_t sm)
Stops all sensors.
DW_API_PUBLIC dwStatus dwSensorManager_release(dwSensorManagerHandle_t sm)
Releases the SensorManager module.

Similarly, DriveWorks Context, SAL and Rig Configuration objects must be released at the end.

Sensor Manager is used in multiple samples: