mrpt.hwdrivers

mrpt.hwdrivers: sensor drivers.

Any driver can be created by class name and configured from an .ini section, the same way rawlog-grabber does it:

import mrpt.config, mrpt.hwdrivers as hw
sensor = hw.CGenericSensor.createSensor("CGPSInterface")
sensor.loadConfig(mrpt.config.CConfigFile("sensors.ini"), "GPS")
sensor.initialize()
while True:
    sensor.doProcess()
    for timestamp, obs in sensor.getObservations():
        print(obs)

A few drivers also have setters to be configured without a config file: CTaoboticsIMU, CGPSInterface, CHokuyoURG, CRoboPeakLidar, CVelodyneScanner. CJoystick reads joysticks and gamepads.

Package Contents

class mrpt.hwdrivers.CGPSInterface

C++ API: class mrpt::hwdrivers::CGPSInterface

Bases: CGenericSensor

Reads GPS/GNSS receiver data from a serial port or any input stream and parses it into CObservationGPS observations.

getSerialPortName() → str

Returns the currently configured serial port device name.

setSerialPortName(COM_port: str) → None

Sets the serial port device name (e.g. “COM1”, “ttyUSB0”).

setSetupCommands(cmds: list[str]) → None

Sets the commands sent to the receiver after opening the port.

setSetupCommandsDelay(delay_secs: float) → None

Sets the delay between setup commands, in seconds.

setShutdownCommands(cmds: list[str]) → None

Sets the commands sent to the receiver before closing the port.

class mrpt.hwdrivers.CGenericSensor

C++ API: class mrpt::hwdrivers::CGenericSensor

A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabber.

class TSensorState(value: int)

Members:

ssInitializing

ssWorking

ssError

ssUninitialized

property name: str
property value: int
ssError: ClassVar[CGenericSensor]
ssInitializing: ClassVar[CGenericSensor]
ssUninitialized: ClassVar[CGenericSensor]
ssWorking: ClassVar[CGenericSensor]
ssError: ClassVar[CGenericSensor]
ssInitializing: ClassVar[CGenericSensor]
ssUninitialized: ClassVar[CGenericSensor]
ssWorking: ClassVar[CGenericSensor]
static createSensor(className: str) → CGenericSensor

Creates a sensor driver by its class name (e.g. ‘CGPSInterface’), or returns None if the class is unknown. Configure it with loadConfig().

doProcess() → None

Reads from the device. Call it periodically, e.g. at getProcessRate() Hz.

enableVerbose(enabled: bool = True) → None

Enables or disables extra debug output.

getClassName() → str

Returns the name of the driver class.

getObservations() → list[tuple[datetime.timedelta, mrpt.serialization.CSerializable]]

Returns (and removes) the observations gathered so far, as a list of (timestamp, observation) tuples

getProcessRate() → float

Suggested doProcess() rate (Hz)

getSensorLabel() → str

Returns the sensor label, copied into each observation.

getState() → CGenericSensor

The current state of the sensor.

initialize() → None

Opens the device and prepares it for capturing (call after configuring)

loadConfig(configSource: mrpt.config.CConfigFileBase, section: str) → None

Loads the sensor parameters from a config file section

setPathForExternalImages(directory: str) → None

For camera sensors: directory where to save images as external files

setSensorLabel(sensorLabel: str) → None

Sets the sensor label, copied into each observation.

class mrpt.hwdrivers.CHokuyoURG

C++ API: class mrpt::hwdrivers::CHokuyoURG

Bases: CGenericSensor

Driver for Hokuyo URG/UTM/UXM/UST 2-D laser range-finders via the SCIP-2.0 protocol over USB serial or Ethernet.

setIPandPort(ip: str, port: int) → None

Configures the IP address and TCP port for Ethernet connection.

setReducedFOV(fov: float) → None

Restricts the angular field of view of the scanner.

setScanInterval(skipScanCount: int) → None

Sets the scan decimation factor.

setSerialPort(port_name: str) → None

Configures the serial port device name for USB/serial connection.

class mrpt.hwdrivers.CJoystick

C++ API: class mrpt::hwdrivers::CJoystick

Reads axis positions and button states from joysticks and gamepads.

class State

Joystick state: button states and axis positions.

property axes: list[float]

Normalized axis positions

property axes_raw: list[int]

Raw axis positions

buttons: list[bool]
getJoystickPosition(nJoy: int = 0) → CJoystick | None

Reads the state of joystick nJoy, or None on error

static getJoysticksCount() → int

Returns the number of joystick/gamepad devices currently connected to the system.

setLimits(minPerAxis: list[int], maxPerAxis: list[int]) → None

Sets the raw range of each axis, used to normalize positions

class mrpt.hwdrivers.CRoboPeakLidar

C++ API: class mrpt::hwdrivers::CRoboPeakLidar

Bases: CGenericSensor

Interfaces a Robo Peak LIDAR laser scanner.

setSerialPort(port_name: str) → None

Sets the serial port device of the scanner.

class mrpt.hwdrivers.CTaoboticsIMU

C++ API: class mrpt::hwdrivers::CTaoboticsIMU

Bases: CGenericSensor

A driver for Taobotics IMU.

setSerialBaudRate(rate: int) → None

Sets the serial port baud rate (default: 921600). Call before initialize().

setSerialPort(serialPort: str) → None

Sets the serial port device (default: /dev/ttyUSB0). Call before initialize().

class mrpt.hwdrivers.CVelodyneScanner

C++ API: class mrpt::hwdrivers::CVelodyneScanner

Bases: CGenericSensor

Driver for Velodyne lidars (HDL-64, HDL-32, VLP-16, …).

class model_t(value: int)

Members:

VLP16

HDL32

HDL64

property name: str
property value: int
HDL32: ClassVar[CVelodyneScanner]
HDL64: ClassVar[CVelodyneScanner]
VLP16: ClassVar[CVelodyneScanner]
HDL32: ClassVar[CVelodyneScanner]
HDL64: ClassVar[CVelodyneScanner]
VLP16: ClassVar[CVelodyneScanner]
setDeviceIP(ip: str) → None

Only accepts UDP packets from this IP address (empty: any address).

setModelName(model: CVelodyneScanner) → None

Sets the scanner model (e.g. VLP16, HDL32, HDL64).

setPCAPInputFile(pcap_file: str) → None

Replays packets from a PCAP file instead of reading from the network