Skip to content

Custom input device

The Incar Skill System provides some inputs out of the box: XR devices, Spacemouse, Gamepads, and Keyboard. However, in case you need a custom input device, such as for a puppeteering setup, it is possible to create an extension for a custom input device.

source ~/incar/bin/activate
incar create_pkg --name [package_name] --input [path]

Ensure that the package name is unique to avoid conflicts with other extensions. path is the location where the extension will be created.

Creating the Input Device

Success

prior to starting, ensure that you are able to connect to and read the input device using a hello world example from the device supplier.

After creating the package, open the template file and fill in the missing functions:

[package_name]_input/inputs.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from incar.extensions.inputs import InputDevice
from dataclasses import dataclass

import numpy as np

@InputDevice.register_subclass("my_custom_device")
@dataclass
class MyCustomInputDevice(InputDevice):
    def add_input_features(self, feature_dict: Dict[str, np.ndarray]):
        # Here, we can add custom input features under a key that we determine.
        feature_dict["right.commands.arm.ee.velocity"] = np.zeros(6, dtype=float)
        feature_dict["custom.command.key"] = np.zeros(18, dtype=float)
        # Ensure that this function is non-blocking. Use the enable/disable functions to instantiate a polling thread if you have to

    def enable_input(self):
        # Here, you can implement the logic to enable the input device

    def disable_input(self)
        # Here, you can implement the logic to disable the input device

Using the custom input device

Ensure that your extension is installed to the incar venv using pip install -e . in the extension root folder. (-e ensures you can hot-reload the extension). Restart the Incar Skill System if it was still running.

You can now select the extension from the Teleoperation Input dropdown.