Skip to content

Commit

Permalink
Add support for adis16550 and adis16550w
Browse files Browse the repository at this point in the history
Signed-off-by: rbudai <[email protected]>
  • Loading branch information
rbudai98 committed Oct 21, 2024
1 parent 3bce801 commit 9b91d17
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 31 deletions.
39 changes: 13 additions & 26 deletions adi/adis16550.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,33 @@ class adis16550(rx, context_manager, ABC):
"accel_y",
"accel_z",
"temp0",
"deltaangl_x",
"deltaangl_y",
"deltaangl_z",
"deltavelocity_x",
"deltavelocity_y",
"deltavelocity_z",
]

_device_name = ""

"""Disable mapping of trigger to RX device."""
disable_trigger = False

# @property
@abstractmethod
def compatible_parts(self):
raise NotImplementedError

def __init__(self, uri="", device_name=None, trigger_name=None):
context_manager.__init__(self, uri, self._device_name)

compatible_parts = ["adis16550", "adis16550w"]

if not device_name:
device_name = self.compatible_parts[0]
device_name = compatible_parts[0]

if device_name not in self.compatible_parts:
if device_name not in compatible_parts:
raise Exception(
"Not a compatible device:"
+ str(device_name)
+ ".Please select from:"
+ str(self.compatible_parts)
+ str(compatible_parts)
)
else:
self._ctrl = self._ctx.find_device(device_name)
Expand All @@ -58,11 +61,11 @@ def __init__(self, uri="", device_name=None, trigger_name=None):
+ device_name
+ ". Searching for a device found in the compatible list."
)
for i in self.compatible_parts:
for i in compatible_parts:
self._ctrl = self._ctx.find_device(i)
self._rxadc = self._ctx.find_device(i)
if self._ctrl is not None:
print("Fond device = " + i + ". Will use this device instead.")
print("Found device = " + i + ". Will use this device instead.")
break
if self._ctrl is None:
raise Exception("No compatible device found")
Expand Down Expand Up @@ -446,19 +449,3 @@ class _delta_channels(_simple_channel):
def __init__(self, ctrl, channel_name):
self.name = channel_name
self._ctrl = ctrl


class adis16550(adis16550):
"""ADIS1655X Six Degrees of Freedom Inertial Sensor
This class is compatible with the following parts:
- ADIS16550
- ADIS16550W
Args:
uri: URI of IIO context with ADIS16550 device
device_name: Name of the device in the IIO context. Default is adis16550
trigger_name: Name of the trigger in the IIO context. Default is adis16550-dev0
"""

compatible_parts = ["adis16550", "adis16550w"]
8 changes: 8 additions & 0 deletions doc/source/devices/adi.adis16550.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
adis16550
====================

.. autoclass:: adi.adis16550
:members:
:undoc-members:
:show-inheritance:
:inherited-members:
1 change: 1 addition & 0 deletions doc/source/devices/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Supported Devices
adi.adis16507
adi.adis16545
adi.adis16547
adi.adis16550
adi.adl5240
adi.adl5960
adi.admv8818
Expand Down
6 changes: 1 addition & 5 deletions examples/adis16550_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@

dev.rx_output_type = "raw"
dev.rx_enabled_channels = [0, 1, 2, 3, 4, 5]
# dev.rx_enabled_delta_channels = [7, 8, 9, 10, 11, 12]
dev.sample_rate = 10
dev.rx_buffer_size = 10

print("Product id: " + str(dev.product_id))
print("Serial number: " + dev.serial_number)
print("Firmware revision: " + dev.firmware_revision)
print("Firmware date: " + dev.firmware_date)

print("\nX acceleration: " + str(dev.accel_x_conv) + " m/s^2")
print("Y acceleration: " + str(dev.accel_y_conv) + " m/s^2")
print("Z acceleration: " + str(dev.accel_z_conv) + " m/s^2")
Expand Down
2 changes: 2 additions & 0 deletions supported_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
- ADIS16507
- ADIS16545
- ADIS16547
- ADIS16550
- ADIS16550W
- ADL5240
- ADL5960
- ADMV8818
Expand Down
149 changes: 149 additions & 0 deletions test/emu/devices/adis16550.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE context [
<!ELEMENT context (device|context-attribute)*>
<!ELEMENT context-attribute EMPTY>
<!ELEMENT device (channel|attribute|debug-attribute|buffer-attribute)*>
<!ELEMENT channel (scan-element?,attribute*)>
<!ELEMENT attribute EMPTY>
<!ELEMENT scan-element EMPTY>
<!ELEMENT debug-attribute EMPTY>
<!ELEMENT buffer-attribute EMPTY>
<!ATTLIST context name CDATA #REQUIRED>
<!ATTLIST context description CDATA #IMPLIED>
<!ATTLIST context-attribute name CDATA #REQUIRED>
<!ATTLIST context-attribute value CDATA #REQUIRED>
<!ATTLIST device id CDATA #REQUIRED>
<!ATTLIST device name CDATA #IMPLIED>
<!ATTLIST channel id CDATA #REQUIRED>
<!ATTLIST channel type (input|output) #REQUIRED>
<!ATTLIST channel name CDATA #IMPLIED>
<!ATTLIST scan-element index CDATA #REQUIRED>
<!ATTLIST scan-element format CDATA #REQUIRED>
<!ATTLIST scan-element scale CDATA #IMPLIED>
<!ATTLIST attribute name CDATA #REQUIRED>
<!ATTLIST attribute filename CDATA #IMPLIED>
<!ATTLIST attribute value CDATA #IMPLIED>
<!ATTLIST debug-attribute name CDATA #REQUIRED>
<!ATTLIST debug-attribute value CDATA #IMPLIED>
<!ATTLIST buffer-attribute name CDATA #REQUIRED>
<!ATTLIST buffer-attribute value CDATA #IMPLIED>
]>
<context name="network" description="10.42.0.83 Linux analog 6.1.54-v7l+ #8 SMP Mon Sep 30 11:56:09 BST 2024 armv7l">
<context-attribute name="hw_carrier" value="Raspberry Pi 4 Model B Rev 1.2" />
<context-attribute name="dtoverlay" value="vc4-kms-v3d,adis16550" />
<context-attribute name="local,kernel" value="6.1.54-v7l+" />
<context-attribute name="uri" value="ip:10.42.0.83" />
<context-attribute name="ip,ip-addr" value="10.42.0.83" />
<device id="hwmon0" name="cpu_thermal">
<channel id="temp1" type="input">
<attribute name="crit" filename="temp1_crit" value="110000" />
<attribute name="input" filename="temp1_input" value="65731" />
</channel>
</device>
<device id="hwmon1" name="rpi_volt">
<channel id="in0" type="input">
<attribute name="lcrit_alarm" filename="in0_lcrit_alarm" value="0" />
</channel>
</device>
<device id="iio:device0" name="adis16550w">
<channel id="anglvel_x" type="input">
<scan-element index="0" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="calibbias" filename="in_anglvel_x_calibbias" value="100" />
<attribute name="calibscale" filename="in_anglvel_x_calibscale" value="0" />
<attribute name="filter_low_pass_3db_frequency" filename="in_anglvel_filter_low_pass_3db_frequency" value="0" />
<attribute name="raw" filename="in_anglvel_x_raw" value="294318" />
<attribute name="scale" filename="in_anglvel_scale" value="0.000000003" />
</channel>
<channel id="anglvel_y" type="input">
<scan-element index="1" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="calibbias" filename="in_anglvel_y_calibbias" value="0" />
<attribute name="calibscale" filename="in_anglvel_y_calibscale" value="30" />
<attribute name="filter_low_pass_3db_frequency" filename="in_anglvel_filter_low_pass_3db_frequency" value="0" />
<attribute name="raw" filename="in_anglvel_y_raw" value="-656865" />
<attribute name="scale" filename="in_anglvel_scale" value="0.000000003" />
</channel>
<channel id="anglvel_z" type="input">
<scan-element index="2" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="calibbias" filename="in_anglvel_z_calibbias" value="0" />
<attribute name="calibscale" filename="in_anglvel_z_calibscale" value="0" />
<attribute name="filter_low_pass_3db_frequency" filename="in_anglvel_filter_low_pass_3db_frequency" value="0" />
<attribute name="raw" filename="in_anglvel_z_raw" value="431669" />
<attribute name="scale" filename="in_anglvel_scale" value="0.000000003" />
</channel>
<channel id="accel_x" type="input">
<scan-element index="3" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="calibbias" filename="in_accel_x_calibbias" value="0" />
<attribute name="calibscale" filename="in_accel_x_calibscale" value="0" />
<attribute name="filter_low_pass_3db_frequency" filename="in_accel_filter_low_pass_3db_frequency" value="0" />
<attribute name="raw" filename="in_accel_x_raw" value="-210881" />
<attribute name="scale" filename="in_accel_scale" value="0.000000095" />
</channel>
<channel id="accel_y" type="input">
<scan-element index="4" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="calibbias" filename="in_accel_y_calibbias" value="0" />
<attribute name="calibscale" filename="in_accel_y_calibscale" value="0" />
<attribute name="filter_low_pass_3db_frequency" filename="in_accel_filter_low_pass_3db_frequency" value="0" />
<attribute name="raw" filename="in_accel_y_raw" value="1598455" />
<attribute name="scale" filename="in_accel_scale" value="0.000000095" />
</channel>
<channel id="accel_z" type="input">
<scan-element index="5" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="calibbias" filename="in_accel_z_calibbias" value="0" />
<attribute name="calibscale" filename="in_accel_z_calibscale" value="0" />
<attribute name="filter_low_pass_3db_frequency" filename="in_accel_filter_low_pass_3db_frequency" value="0" />
<attribute name="raw" filename="in_accel_z_raw" value="103145573" />
<attribute name="scale" filename="in_accel_scale" value="0.000000095" />
</channel>
<channel id="temp0" type="input">
<scan-element index="6" format="be:s16/32&gt;&gt;0" scale="4.000000" />
<attribute name="offset" filename="in_temp0_offset" value="6250" />
<attribute name="raw" filename="in_temp0_raw" value="4369" />
<attribute name="scale" filename="in_temp0_scale" value="4" />
</channel>
<channel id="deltaangl_x" type="input">
<scan-element index="7" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="raw" filename="in_deltaangl_x_raw" value="-86" />
<attribute name="scale" filename="in_deltaangl_scale" value="0.000000006" />
</channel>
<channel id="deltaangl_y" type="input">
<scan-element index="8" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="raw" filename="in_deltaangl_y_raw" value="-162" />
<attribute name="scale" filename="in_deltaangl_scale" value="0.000000006" />
</channel>
<channel id="deltaangl_z" type="input">
<scan-element index="9" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="raw" filename="in_deltaangl_z_raw" value="169" />
<attribute name="scale" filename="in_deltaangl_scale" value="0.000000006" />
</channel>
<channel id="deltavelocity_x" type="input">
<scan-element index="10" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="raw" filename="in_deltavelocity_x_raw" value="246" />
<attribute name="scale" filename="in_deltavelocity_scale" value="0.000000058" />
</channel>
<channel id="deltavelocity_y" type="input">
<scan-element index="11" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="raw" filename="in_deltavelocity_y_raw" value="-75" />
<attribute name="scale" filename="in_deltavelocity_scale" value="0.000000058" />
</channel>
<channel id="deltavelocity_z" type="input">
<scan-element index="12" format="be:S32/32&gt;&gt;0" scale="0.000000" />
<attribute name="raw" filename="in_deltavelocity_z_raw" value="84684" />
<attribute name="scale" filename="in_deltavelocity_scale" value="0.000000058" />
</channel>
<channel id="timestamp" type="input">
<scan-element index="13" format="le:S64/64&gt;&gt;0" />
</channel>
<attribute name="current_timestamp_clock" value="realtime " />
<attribute name="sampling_frequency" value="2000.000000" />
<attribute name="waiting_for_supplier" value="0" />
<buffer-attribute name="data_available" value="64" />
<buffer-attribute name="direction" value="in" />
<debug-attribute name="flash_count" value="13" />
<debug-attribute name="firmware_date" value="28-04-2021" />
<debug-attribute name="firmware_revision" value="1.5" />
<debug-attribute name="product_id" value="16550" />
<debug-attribute name="serial_number" value="0x000000b6" />
<debug-attribute name="direct_reg_access" value="0x0" />
</device>
<device id="trigger0" name="adis16550w-dev0" />
</context>
9 changes: 9 additions & 0 deletions test/emu/hardware_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,15 @@ adis16480:
- pyadi_iio_class_support:
- adis16480

adis16550:
- adis16550
- emulate:
- filename: adis16550.xml
- data_devices:
- iio:device0
- pyadi_iio_class_support:
- adis16550

ad7124-8:
- ad7124
- pyadi_iio_class_support:
Expand Down
93 changes: 93 additions & 0 deletions test/test_adis16550.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import adi
import pytest

hardware = "adis16550"
classname = "adi.adis16550"
device_name = "adis16550"

########################################
@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize("channel", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
def test_adis16550_rx_data(test_dma_rx, iio_uri, classname, channel):
test_dma_rx(iio_uri, classname, channel, buffer_size=16)


#########################################
@pytest.mark.iio_hardware(hardware, True)
def test_adis16550_conv_data(iio_uri):
adis16550 = adi.adis16550(uri=iio_uri)

assert adis16550.accel_x_conv != 0.0
assert adis16550.accel_y_conv != 0.0
assert adis16550.accel_z_conv != 0.0
assert adis16550.anglvel_x_conv != 0.0
assert adis16550.anglvel_y_conv != 0.0
assert adis16550.anglvel_z_conv != 0.0
assert adis16550.temp_conv != 0.0


#########################################
@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, start, stop, step, tol",
[
("anglvel_x_calibbias", -2147483648, 2147483647, 1, 0),
("anglvel_y_calibbias", -2147483648, 2147483647, 1, 0),
("anglvel_z_calibbias", -2147483648, 2147483647, 1, 0),
("accel_x_calibbias", -2147483648, 2147483647, 1, 0),
("accel_y_calibbias", -2147483648, 2147483647, 1, 0),
("accel_z_calibbias", -2147483648, 2147483647, 1, 0),
("anglvel_x_calibscale", -32134, 32134, 1, 0),
("anglvel_y_calibscale", -32134, 32134, 1, 0),
("anglvel_z_calibscale", -32134, 32134, 1, 0),
("accel_x_calibscale", -32134, 32134, 1, 0),
("accel_y_calibscale", -32134, 32134, 1, 0),
("accel_z_calibscale", -32134, 32134, 1, 0),
],
)
def test_adis16550_attr(
test_attribute_single_value, iio_uri, classname, attr, start, stop, step, tol
):
test_attribute_single_value(iio_uri, classname, attr, start, stop, step, tol)


#########################################
@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, values, tol, repeats",
[
("sample_rate", [5, 10, 246, 1230, 2460], 0.5, 2),
("anglvel_x_filter_low_pass_3db_frequency", [0, 55, 275, 310], 0.5, 2),
("anglvel_y_filter_low_pass_3db_frequency", [0, 55, 275, 310], 0.5, 2),
("anglvel_z_filter_low_pass_3db_frequency", [0, 55, 275, 310], 0.5, 2),
("accel_x_filter_low_pass_3db_frequency", [0, 55, 275, 310], 0.5, 2),
("accel_y_filter_low_pass_3db_frequency", [0, 55, 275, 310], 0.5, 2),
("accel_z_filter_low_pass_3db_frequency", [0, 55, 275, 310], 0.5, 2),
],
)
def test_adis16550_attr_multiple_val(
test_attribute_multiple_values, iio_uri, classname, attr, values, tol, repeats,
):
test_attribute_multiple_values(iio_uri, classname, attr, values, tol, repeats)

@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize(
"classname",
[
"adi.adis16550",
"adi.adis16550w",
],
)
def test_adis16XXX_create(iio_uri, classname):
# This test is a little hack to just enumerate all the classes even though
# we don't have the exact hardware
emulation_hw = "adis16550"
imu = eval(classname)
imu.compatible_parts = [emulation_hw]
imu.disable_trigger = True

# Try to create the object
imu = imu(uri=iio_uri)

0 comments on commit 9b91d17

Please sign in to comment.