The VehicleIO Plugin back-end enables writing fully customized drive-by-wire abstraction that will be represented as a VehicleIO interface for the rest of the software stack.
A VehicleIO plugin in DriveWorks requires implementing a set of pre-defined functions. The declarations of these functions are located in dw/control/vehicleio/plugins/VehicleIODriver.h
.
In this tutorial, we are going to implement a simple drive-by-wire system that is responsible for steering wheel angle. See VehicleIO Plugin Sample for the corresponding sample code.
In essence, our plugin is a dynamically loaded shared library, and the core VehicleIO module will first call _dwVehicleIODriver_initialize()
function of this library, which should prepare all objects and state that is needed for the plugin to function:
Above, dwCANInterpreter_buildFromDBC()
function initializes an interpreter object that will be useful to work with our DBC file. See CAN Message Interpreter Sample for more information about CAN interpreter usage.
When using the plugin with, for example, VehicleIO Sample, in order for VehicleIO core to load the plugin, Rig file should specify "custom" VehicleIO node:
Full example of Rig file is available in data/samples/vehicleio/rig-plugin.json
, and exact commands how to run the VehicleIO sample with the plugin is available at VehicleIO Plugin Sample.
When plugin is no longer needed, VehicleIO core will call _dwVehicleIODriver_release()
method, which is an opportunity for the module to cleanup any created objects and state:
CAN messages represent the input to the module, which plugin must parse and update its state, if needed. VehicleIO core will call plugin's _dwVehicleIODriver_consume()
function when there is a new message to consume:
In the example above, we simply parse current steering angle report using our CAN/DBC interpreter:
CAN messages are also the output of the module, thus when VehicleIO is requested to send a command, the core module will relay the request to the plugin, issuing two calls: _dwVehicleIODriver_sendCommand()
and _dwVehicleIODriver_sendMiscCommand()
. Each of the function should encode command arguments into CAN messages and send via a provided sensor handle:
If certain type of commands are not relevant, the plugin is permitted to return DW_NOT_IMPLEMENTED
status, as was shown in _dwVehicleIODriver_sendMiscCommand()
above.
And as in previous section, we use CAN interpreter to encode commands into CAN messages:
The plugin code must be compiled into a dynamic library.
Firstly, we should create a folder under samples
called vehicleio_plugin
and create a CMakeLists.txt
under this folder:
Run cmake
and the preferred build system to compile the library. This will generate a libsample_vehicleio_plugin.so
.
See VehicleIO Plugin Sample for more details.