Skip to content

Commit

Permalink
Merge pull request #517 from analogdevicesinc/dev/adis16475_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tfcollins authored Feb 15, 2024
2 parents 09674ca + 5a23b85 commit a5eb253
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 5 deletions.
15 changes: 15 additions & 0 deletions adi/adis16475.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ def __init__(self, uri="", device_name="adis16505-2"):
self._ctrl = self._ctx.find_device(device_name)
self._rxadc = self._ctx.find_device(device_name)

if self._ctrl is None:
print(
"No device found with device_name = "
+ device_name
+ ". Searching for a device found in the compatible list."
)
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.")
break
if self._ctrl is None:
raise Exception("No compatible device found")

self.anglvel_x = self._channel_with_offset(self._ctrl, "anglvel_x")
self.anglvel_y = self._channel_with_offset(self._ctrl, "anglvel_y")
self.anglvel_z = self._channel_with_offset(self._ctrl, "anglvel_z")
Expand Down
125 changes: 123 additions & 2 deletions test/emu/devices/adis16475.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,123 @@
<?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 description CDATA #IMPLIED><!ATTLIST context-attribute name CDATA #REQUIRED value CDATA #REQUIRED><!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED><!ATTLIST channel id CDATA #REQUIRED type (input|output) #REQUIRED name CDATA #IMPLIED><!ATTLIST scan-element index CDATA #REQUIRED format CDATA #REQUIRED scale CDATA #IMPLIED><!ATTLIST attribute name CDATA #REQUIRED filename CDATA #IMPLIED value CDATA #IMPLIED><!ATTLIST debug-attribute name CDATA #REQUIRED value CDATA #IMPLIED><!ATTLIST buffer-attribute name CDATA #REQUIRED value CDATA #IMPLIED>]><context name="network" description="192.168.0.2 Linux analog 5.15.92-v7l+ #585 SMP Wed Aug 9 14:34:30 EEST 2023 armv7l" ><context-attribute name="hw_carrier" value="Raspberry Pi 4 Model B Rev 1.4" /><context-attribute name="dtoverlay" value="vc4-kms-v3d,adis16475" /><context-attribute name="hw_model" value="0x0001 on Raspberry Pi 4 Model B Rev 1.4" /><context-attribute name="local,kernel" value="5.15.92-v7l+" /><context-attribute name="uri" value="ip:192.168.0.2" /><context-attribute name="ip,ip-addr" value="192.168.0.2" /><device id="iio:device0" name="adis16505-2" ><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="0" /><attribute name="raw" filename="in_anglvel_x_raw" value="-1200216" /><attribute name="scale" filename="in_anglvel_scale" value="0.000000006" /></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="raw" filename="in_anglvel_y_raw" value="1855130" /><attribute name="scale" filename="in_anglvel_scale" value="0.000000006" /></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="raw" filename="in_anglvel_z_raw" value="239786" /><attribute name="scale" filename="in_anglvel_scale" value="0.000000006" /></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="raw" filename="in_accel_x_raw" value="-55120502" /><attribute name="scale" filename="in_accel_scale" value="0.000000037" /></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="raw" filename="in_accel_y_raw" value="-2194857" /><attribute name="scale" filename="in_accel_scale" value="0.000000037" /></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="raw" filename="in_accel_z_raw" value="-253497856" /><attribute name="scale" filename="in_accel_scale" value="0.000000037" /></channel><channel id="temp0" type="input" ><scan-element index="6" format="be:S16/16&gt;&gt;0" scale="100.000000" /><attribute name="raw" filename="in_temp0_raw" value="286" /><attribute name="scale" filename="in_temp0_scale" value="100" /></channel><channel id="timestamp" type="input" ><scan-element index="7" format="le:S64/64&gt;&gt;0" /></channel><attribute name="current_timestamp_clock" value="realtime
" /><attribute name="filter_low_pass_3db_frequency" value="720" /><attribute name="sampling_frequency" value="2000.000000" /><buffer-attribute name="data_available" value="0" /><debug-attribute name="firmware_date" value="06-27-2019" /><debug-attribute name="firmware_revision" value="1.6" /><debug-attribute name="flash_count" value="69" /><debug-attribute name="product_id" value="16505" /><debug-attribute name="serial_number" value="0x04b5" /><debug-attribute name="direct_reg_access" value="0x0" /></device><device id="iio_sysfs_trigger" ><attribute name="add_trigger" value="ERROR" /><attribute name="remove_trigger" value="ERROR" /></device><device id="trigger0" name="adis16505-2-dev0" ></device></context>
<?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 #IMPLIED version-minor CDATA #IMPLIED description CDATA #IMPLIED version-major CDATA #IMPLIED version-git CDATA #IMPLIED>
<!ATTLIST context-attribute name CDATA #REQUIRED value CDATA #REQUIRED>
<!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED>
<!ATTLIST channel id CDATA #REQUIRED type (input|output) #REQUIRED name CDATA #IMPLIED>
<!ATTLIST scan-element index CDATA #REQUIRED format CDATA #REQUIRED scale CDATA #IMPLIED>
<!ATTLIST attribute name CDATA #REQUIRED filename CDATA #IMPLIED value CDATA #IMPLIED>
<!ATTLIST debug-attribute name CDATA #REQUIRED value CDATA #IMPLIED>
<!ATTLIST buffer-attribute name CDATA #REQUIRED value CDATA #IMPLIED>
]>
<context name="xml" version-major="0" version-minor="25" version-git="b6028fd" description="Linux analog 6.1.54-v7l+ #155 SMP Mon Jan 22 15:09:37 EET 2024 armv7l">
<context-attribute name="hw_carrier" value="Raspberry Pi 4 Model B Rev 1.2"/>
<context-attribute name="dtoverlay" value="vc4-kms-v3d,adis16475"/>
<context-attribute name="hw_model" value="0x0001 on Raspberry Pi 4 Model B Rev 1.2"/>
<context-attribute name="hw_mezzanine" value="0x0001"/>
<context-attribute name="hw_name" value="PMD-RPI-INTZ"/>
<context-attribute name="hw_vendor" value="Analog Devices, Inc."/>
<context-attribute name="hw_serial" value="bfc337a9-ebe6-48bb-afe4-c75456ab366c"/>
<context-attribute name="local,kernel" value="6.1.54-v7l+"/>
<context-attribute name="uri" value="local:"/>
<device id="hwmon0" 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="adis16505-2">
<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="0"/>
<attribute name="raw" filename="in_anglvel_x_raw" value="-24546"/>
<attribute name="scale" filename="in_anglvel_scale" value="0.000000006"/>
</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="raw" filename="in_anglvel_y_raw" value="1790855"/>
<attribute name="scale" filename="in_anglvel_scale" value="0.000000006"/>
</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="raw" filename="in_anglvel_z_raw" value="-638514"/>
<attribute name="scale" filename="in_anglvel_scale" value="0.000000006"/>
</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="raw" filename="in_accel_x_raw" value="-1503047"/>
<attribute name="scale" filename="in_accel_scale" value="0.000000037"/>
</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="raw" filename="in_accel_y_raw" value="2133818"/>
<attribute name="scale" filename="in_accel_scale" value="0.000000037"/>
</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="raw" filename="in_accel_z_raw" value="262959468"/>
<attribute name="scale" filename="in_accel_scale" value="0.000000037"/>
</channel>
<channel id="temp0" type="input">
<scan-element index="6" format="be:S16/16&gt;&gt;0" scale="100.000000"/>
<attribute name="raw" filename="in_temp0_raw" value="268"/>
<attribute name="scale" filename="in_temp0_scale" value="100"/>
</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="-241"/>
<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="1025"/>
<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="-250"/>
<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="-687"/>
<attribute name="scale" filename="in_deltavelocity_scale" value="0.000000046"/>
</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="811"/>
<attribute name="scale" filename="in_deltavelocity_scale" value="0.000000046"/>
</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="105743"/>
<attribute name="scale" filename="in_deltavelocity_scale" value="0.000000046"/>
</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&#10;"/>
<attribute name="filter_low_pass_3db_frequency" value="720"/>
<attribute name="sampling_frequency" value="2000.000000"/>
<attribute name="waiting_for_supplier" value="0"/>
<buffer-attribute name="data_available" value="10"/>
<buffer-attribute name="direction" value="in"/>
<debug-attribute name="firmware_date" value="06-27-2019"/>
<debug-attribute name="firmware_revision" value="1.6"/>
<debug-attribute name="flash_count" value="57"/>
<debug-attribute name="product_id" value="16505"/>
<debug-attribute name="serial_number" value="0x05c9"/>
<debug-attribute name="direct_reg_access" value="0x0"/>
</device>
<device id="trigger0" name="adis16505-2-dev0"/>
</context>
101 changes: 98 additions & 3 deletions test/test_adis16475_p.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,110 @@
import adi
import pytest

hardware = "adis16475"
classname = "adi.adis16475"


@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize("channel", [0])
def test_adis16475_rx_data(test_dma_rx, iio_uri, classname, channel):
test_dma_rx(iio_uri, classname, channel, buffer_size=16)


@pytest.mark.iio_hardware(hardware)
def test_adis16475_filter_low_pass_3db_frequency(iio_uri):
adis16475 = adi.adis16475(uri=iio_uri)

for i in [10, 20, 40, 80, 164, 360, 720]:
adis16475.filter_low_pass_3db_frequency = i
assert adis16475.filter_low_pass_3db_frequency == i

for i in range(0, 10):
adis16475.filter_low_pass_3db_frequency = i
assert adis16475.filter_low_pass_3db_frequency <= 10

for i in range(11, 20):
adis16475.filter_low_pass_3db_frequency = i
assert adis16475.filter_low_pass_3db_frequency <= 20

for i in range(21, 40):
adis16475.filter_low_pass_3db_frequency = i
assert adis16475.filter_low_pass_3db_frequency <= 40

for i in range(41, 80):
adis16475.filter_low_pass_3db_frequency = i
assert adis16475.filter_low_pass_3db_frequency <= 80

for i in range(81, 164):
adis16475.filter_low_pass_3db_frequency = i
assert adis16475.filter_low_pass_3db_frequency <= 164

for i in range(165, 360):
adis16475.filter_low_pass_3db_frequency = i
assert adis16475.filter_low_pass_3db_frequency <= 360

for i in range(361, 720):
adis16475.filter_low_pass_3db_frequency = i
assert adis16475.filter_low_pass_3db_frequency <= 720


@pytest.mark.iio_hardware(hardware)
def test_adis16475_firmware_date(iio_uri):
adis16475 = adi.adis16475(uri=iio_uri)

assert adis16475.firmware_date != "00-00-0000"


@pytest.mark.iio_hardware(hardware)
def test_adis16475_firmware_revision(iio_uri):
adis16475 = adi.adis16475(uri=iio_uri)

assert adis16475.firmware_revision != "0.0"


@pytest.mark.iio_hardware(hardware)
def test_adis16475_product_id(iio_uri):
adis16475 = adi.adis16475(uri=iio_uri)

assert adis16475.product_id != 0


@pytest.mark.iio_hardware(hardware)
def test_adis16475_serial_number(iio_uri):
adis16475 = adi.adis16475(uri=iio_uri)

assert adis16475.serial_number != "0x0000"


@pytest.mark.iio_hardware(hardware)
def test_adis16476_conv_data(iio_uri):
adis16475 = adi.adis16475(uri=iio_uri)

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


@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"classname, attr, start, stop, step, tol",
[(classname, "sample_rate", 1000, 2000, 1000, 0)],
"attr, start, stop, step, tol",
[
("sample_rate", 1000, 2000, 1000, 0),
("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),
],
)
def test_adis16475_sample_rate(
def test_adis16475_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)

0 comments on commit a5eb253

Please sign in to comment.