Package: um7py
UM7 Python 3 DriverTHIS REPO IS RETIREDUsersl_comm_pyinsteadThe code will be kept as-isWhyrsl_comm_pyrepo? Since we support more thenUM7(UM7,UM8,shearwater),
we unified communication code in one repo.TL;DR:"Swiss army knife"for using
theUM7orientation sensor with Python 3 (Python 3.6+).UM7comes with the"Serial Software Interface"for handling / communicating with the sensor, which is currently available for Windows only.Thepythondriver provided here is designed to keep you up and running
on different platforms (Linux, Windows, Mac).
If you have theUM7board and want to use it on Linux (e.g. Ubuntu, Debian, Raspbian, Yocto, Suse, etc.),
Windows or Mac, this repo provides driver code to send / receive individual packets
and receive broadcasts, as well example code how to create a sensor communication object.In particular, the driver has the following capabilities:read / write singleUM7registers over UART;receive broadcast data from theUM7sensor over UART;register map and interpretation of the sensor registers.Repo structureTo get started, you need to know that communicating with the UM7 over
the UART is coded inum7_serial.pyfile,
where theUM7Serialclass is defined.
Information about UM7 registers comes toum7_serial.pyfrom theum7_registers.pyfile, where
the accessing to the UM7 registers are stored.
Since it is possible to access the UM7 register map over UART and SPI,
the register data (e.g. addresses, fields, and their meaning) is stored in a separate file.
In theexamplesfolder we store the examples how to communicate with the
sensor.The UM7 register description is stored in the SVD fileum7.svdand is parsed by thersl_svd_parser.py.
The parser extracts the information from the XML file and keeps it as python data classes.Below we outline the repo structure:um7py: top-level python package;um7py/examples: package with example code for receiving broadcast / reading / writing UM7 registers;um7py/rsl_xml_svd: package that stores UM7 registers data in SVD (orSystemViewDescription) format and parsing code;um7py/rsl_xml_svd/test:pytesttests for SVD parsing;um7py/rsl_xml_svd/RSL-SVD.xsd: RedShiftLabs SVDXML Schemabased onCMSIS5 SVD Schema;um7py/rsl_xml_svd/rsl_svd_parser.py: parsing code forum7.svdinto dataclasses;um7py/rsl_xml_svd/um7.svd: the UM7 SVD file, which stores register description in xml (in particular SVD format);um7py/templates:jinja2templates used for code generation part;um7py/test:pytesttests for code generation part;um7py/rsl_generate_um7.py: invoke code generation and save generated results;um7py/rsl_generator.py: code generation forum7_registers.pyfrom the SVD file;um7py/serve_um7_autodetect.py: copies theum7_autodetect.pyscript to the desired location;um7py/um7_autodetect.py: UM7 script for saving configuration for connection to theUSB Expansion Board;um7py/um7_broadcast_packets.py:dataclassesfor UM7 broadcast messages;um7py/um7_registers.py: UM7 register description file;um7py/um7_serial.py: UM7 UART driver;HW PrerequisitesUM7 provides serial (UART) and SPI interfaces, hence the two main ways to access the sensor data
are UART (serial) or SPI. The differences in short: UART provides broadcast functionality, i.e.
when packets can transmitted by the board with a specified frequency (transmission frequencies are set up in
configuration registers), and it is possible to issue sensor commands (i.e. accessing command registers).
SPI access the sensor register on demand (i.e. no broadcast functionality), and only
configuration and data registers can be accessed. Accessing commands is only supported
over UART.Serial connection (UART)When using UM7 over serial, it is possible to connect to the target system (i.e. user's target):to the serial port directly (e.g. when serial pins are wired out as on theRaspberry PI,NVIDIA Jetson Nano,
or other board computers with GPIO and UART pins wired out);to the USB port using theUSB Expansion Board,
which performs USB to serial conversion.SPI connectionWhen using the UM7 over SPI, there are also a couple of possibilities:to the SPI pins directly (e.g. Raspberry PI, NVIDIA Jetson Nano), i.e.
the pins are wired to theSoCdirectly;to the USB port using USB to SPI converter, e.g.USB-ISS.The difference between the two, that in the first case SoC pins support the SPI
directly (on the hardware level, which also mirrors in the OS level), then the OS is likely to have the SPI device
driver built-in (e.g. Raspberry PI). In the second case, using external converter (e.g. USB-ISS),
the device will be shown as a so-calledcdc_acm(communication device class),
and low-level SPI communication will be done by the converter, yet to the OS the
converter will be shown as Abstract Control Model (ACM) USB Device.Installationpipinstallum7pyPython dependenciesTL;DR:install
(i)pyserial,
(ii)pyudev(for Linux),
(iii)dataclasses(included in standard library sincepython3.7, needs to be installed for3.6).If you want to use SPI: if using on Linux and use SPI bus directly, installspidev,
otherwise if using USB-ISS installusb_isspython package.Quick startCreateUM7serial communication object, UM7 connected to a port/dev/ttyUSB0,
and read the firmware version:fromum7pyimportUM7Serialum7_serial=UM7Serial(port_name='/dev/ttyUSB0')print(f"um7 firmware revision:{um7_serial.get_fw_revision}")Readingall typesof broadcast packets fromUM7, 1000 packets in total:fromum7pyimportUM7Serialum7_serial=UM7Serial(port_name='/dev/ttyUSB0')forpacketinum7_serial.recv_broadcast(num_packets=1000):print(f"packet:{packet}")Reading theraw sensor databroadcast packets fromUM7, not limiting number of packets:fromum7pyimportUM7Serialum7_serial=UM7Serial(port_name='/dev/ttyUSB0')forpacketinum7_serial.recv_all_raw_broadcast():print(f"packet:{packet}")Reading 100processed sensor databroadcast packets fromUM7:fromum7pyimportUM7Serialum7_serial=UM7Serial(port_name='/dev/ttyUSB0')forpacketinum7_serial.recv_all_proc_broadcast(num_packets=100):print(f"packet:{packet}")Reading theEuler anglesbroadcast packets fromUM7:fromum7pyimportUM7Serialum7_serial=UM7Serial(port_name='/dev/ttyUSB0')forpacketinum7_serial.recv_euler_broadcast():print(f"packet:{packet}")Reading theCREG_COM_SETTINGSconfiguration register fromUM7:fromum7pyimportUM7Serialum7_serial=UM7Serial(port_name='/dev/ttyUSB0')print(f"received value:{um7_serial.creg_com_settings}")Writing 40 (changingALL_RAW_RATEto 40 Hz) to theCREG_COM_RATES2register:fromum7pyimportUM7Serialum7_serial=UM7Serial(port_name='/dev/ttyUSB0')um7_serial.creg_com_rates2=40Slow startTake a look at the availableexamples.In order to use thepythondriver functionality one first needs to
create a communication object (in our caseUM7SerialorUM7SPI).The construction of the UART communication object can be done
either by specifying aport_namedirectly (e.g./dev/ttyS0), or
by specifying thedevicefile that storesUSB2Serialconfig
(e.g.um7_A500CNP8.json). Thedeviceargument shall
only be used, when UM7 is connected via theUSB Expansion Board,
thedevicestores properties of the expansion board. Why?
The issue to keep in mind that when the sensor is re-plugged,
it might appear to the OS as different serial connection,
i.e. when first plugged in the OS detects the device as/dev/ttyS0, then after re-plugging exactly the same
sensor might appear by different port name, e.g./dev/ttyS1, which
means the user code needs to be changed.
If using thedevice, we store properties of theUSB Expansion Boardin a JSON file (e.g. converter chip ID)
and search connection which match with the properties, and
in this case connecting to the sensor, even if is shown as a
different serial connection by the OS.So the communication object can either be created with specifying theport_name:fromum7pyimportUM7Serialum7_serial=UM7Serial(port_name='/dev/ttyUSB0')Or with specifying thedevice:fromum7pyimportUM7Serialum7=UM7Serial(device='um7_A500CNP8.json')The two options are exclusive, i.e. specifying bothport_nameanddevicewill not work.Accessing to the individual registers is done via pythonproperties.
Properties for register names are all lower-case, split by_.For example, reading theCREG_COM_RATES1:fromum7pyimportUM7Serialum7=UM7Serial(device='um7_A500CNP8.json')um7.creg_com_rates1Note, that reading single register is quite a slow operation,
since one first constructs and sends a packet, and then parses
output for response.
Reading single registers is not recommended for reading sensor data,
since it might happen, that data from different sensor registers come from different measurements.
We strongly advice to use broadcast messages for reading sensor and fusion data.UM7 Data PacketsUM7sends different types of broadcast messages over the UART.
These messages are e.g. HEALTH packet (i.e. theDREG_HEALTHregister),
raw sensor data (raw gyro, accelerometer, and magnetometer, and temperature),
processed sensor data (processed gyro, accelerometer, and magnetometer),
Euler angles, quaternions.These data packets are stored in the repo asdataclassesin the fileum7_broadcast_packets.py.
Note, that only payload stored in the dataclasses, and all the
checks (e.g. checksum, data length) is done during broadcast reception.For example, the raw data broadcast message has the following payload:fromdataclassesimportdataclass@dataclassclassUM7AllRawPacket:gyro_raw_x:intgyro_raw_y:intgyro_raw_z:intgyro_raw_time:floataccel_raw_x:intaccel_raw_y:intaccel_raw_z:intaccel_raw_time:floatmag_raw_x:intmag_raw_y:intmag_raw_z:intmag_raw_time:floattemperature:floattemperature_time:floatAcknowledgementWe are so grateful for the open source community for creating
open source UM7 driver versions and sharing it with a world!
We are inspired by your work, and at the same time
want to improve:
provide UART and SPI communication, in detail documentation
and explanations to facilitate the start for new users.The acknowledgments go to:Daniel Kurekand hisum7repository,
for implementing the first driver for interfacing with UM7;Till Buschand hisum7fork of Daniel's Kurek repo, for extending on the Daniel's work and
adding new functionality.MaintainerDr. Konstantin Selyunin,
for suggestions / questions / comments
please contact selyunin [dot] k [dot] v [at] gmail [dot] com.