Sensor example

Updated: April 19, 2023

The Sensor example application demonstrates how to use the Sensor library to retrieve sensor data, record it, and show it on the screen.

The application requires that you configure sensors in the sensor configuration file. These can include live sensors, such as lidar or radar, or prerecorded data files (file data). For information about connecting and configuring sensors, see Connect cameras and sensors and Configure cameras and sensors on the reference image in this chapter.

To run the application, you must run the sensor_example command, which takes these optional parameters:
-b
Sets the number of buffers that can be received from the sensor. The default is 100.
-c
Sets the consumption latency in microseconds (μs). The default is 50 μs.
-d
Prints information from the data callback from each buffer that's received.
-e example_num
Specifies the example you want to run from the menu. If this option isn't specified, the application prompts you for an example to run. You can use the following numbers for different options:
  1. Sensor stream: Runs the example using a stream of data from the sensors specified in the configuration file.
  2. Sensor recorder: Records data from the connected sensors.
  3. Sensor data publisher: Publishes the sensor data.
  4. Sensor data subscriber: Subscribes to the sensor data.
  5. Sensor query: Queries information about the sensors.
  6. Sensor data query: Queries the data from the sensors.
-f
Sets the path to save the recording. If this option isn't specified, the application uses the roll to get a unique filename from the roll directory specified in the Sensor service.
-p
Publishes the latency in microseconds (μs). The default is 33000 μs.
-s
Prints information from the status callback when the status is received.
-u
Sets the sensor unit to use for testing, as an integer value that corresponds to the unit specified in the sensor configuration file. For example, if you want to use SENSOR_UNIT_1, then specify 1. If this option isn't specified, a prompt appears to request the sensor unit.

Run the application

The steps here allow you to run the Sensor example application:
  1. Connect to your board using ssh.
  2. If another example application is running, type slay example_app in your ssh session to stop it; for instance:
    # slay camera_mux
    The application should stop running and you should see a blank display.
  3. Type sensor_example to run the application. After you press Enter, a menu appears:
    # sensor_example
    Select which example you want to run:
            1) Sensor stream
            2) Sensor recorder
            3) Sensor data publisher
            4) Sensor data subscriber
            5) Sensor query
            6) Sensor data query
            x) Exit the example
  4. Type the number of the option you want to run. You should see the results in your console.

Examples

Stream and then record sensor data

The following shows how you stream data from a file to a sensor and then record that data:
# sensor_example
Select which example you want to run: 
    1) Sensor stream
    2) Sensor recorder
    3) Sensor data publisher
    4) Sensor data subscriber streaming
    5) Sensor data subscriber recording
    6) Sensor query
    7) Sensor data query
    x) Exit the example
1
Select which sensor you want to use: 
    1) Unit: 1, Type: Sensor Camera, Name: front
1
Select which example you want to run: 
    1) Sensor stream
    2) Sensor recorder
    3) Sensor data publisher
    4) Sensor data subscriber streaming
    5) Sensor data subscriber recording
    6) Sensor query
    7) Sensor data query
    x) Exit the example
2
Select which sensor you want to use: 
    1) Unit: 1, Type: Sensor Camera, Name: front
1
Recording to /accounts/1000/shared/sensor/SENSOR_19691231_191625_.raw
Select which example you want to run: 
    1) Sensor stream
    2) Sensor recorder
    3) Sensor data publisher
    4) Sensor data subscriber streaming
    5) Sensor data subscriber recording
    6) Sensor query
    7) Sensor data query
    x) Exit the example
#

Get the position of a sensor

The following shows how to get the position of a sensor (which is specified in the configuration file):
# sensor_example
Select which example you want to run: 
    1) Sensor stream
    2) Sensor recorder
    3) Sensor data publisher
    4) Sensor data subscriber streaming
    5) Sensor data subscriber recording
    6) Sensor query
    7) Sensor data query
    x) Exit the example
6
Select which sensor you want to use: 
    1) Unit: 1, Type: Sensor Camera, Name: front
1
Sensor position: (0.0, 0.0, 0.0), yaw: 0.0, pitch 0.0, roll 0.0
Select which example you want to run: 
    1) Sensor stream
    2) Sensor recorder
    3) Sensor data publisher
    4) Sensor data subscriber streaming
    5) Sensor data subscriber recording
    6) Sensor query
    7) Sensor data query
    x) Exit the example
#

Build the Sensor example application

On your host computer, the source code is provided for the Sensor example application. You can build the source code and deploy the resulting binary onto your target.

  1. A ZIP file installed with the QNX SDP 7.1 Sensor Framework Base package is located at installation_directory/source/sf-sensor-examples-version.zip. You must extract it to get the ZIP file for the sensor examples.
  2. In the extraction_directory/source_package_sf_sensor directory, there's a README.txt that you can follow to build the application.
  3. Create a backup of the original sensor_example file on your target. This file is found in the target's /usr/bin/ directory.
  4. Deploy your newly built version of the Sensor example application, by navigating to extraction_directory/source_package_sf_sensor/apps/sensor/sensor_example/nto/aarch64/so.le on your host and transferring the sensor_example file to the /usr/bin/ directory on the target. You can use the QNX Momentics IDE to transfer the file.
  5. Connect to your target through a terminal connection and run the Sensor example application.