Skip to content

Commit

Permalink
Add new attributes in adis16475 driver and update example
Browse files Browse the repository at this point in the history
Signed-off-by: Ramona Gradinariu <[email protected]>
  • Loading branch information
rbolboac committed Jan 9, 2024
1 parent 3c15b18 commit 353d2f9
Show file tree
Hide file tree
Showing 2 changed files with 300 additions and 8 deletions.
248 changes: 247 additions & 1 deletion adi/adis16475.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright (C) 2019-2023 Analog Devices, Inc.
# Copyright (C) 2019-2024 Analog Devices, Inc.
#
# SPDX short identifier: ADIBSD

from adi.attribute import attribute
from adi.context_manager import context_manager
from adi.rx_tx import rx

Expand All @@ -18,6 +19,12 @@ class adis16475(rx, context_manager):
"accel_y",
"accel_z",
"temp0",
"deltaangl_x",
"deltaangl_y",
"deltaangl_z",
"deltavelocity_x",
"deltavelocity_y",
"deltavelocity_z",
]
_device_name = ""

Expand Down Expand Up @@ -58,9 +65,107 @@ def __init__(self, uri="", device_name="adis16505-2"):
self._ctrl = self._ctx.find_device(device_name)
self._rxadc = self._ctx.find_device(device_name)

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")
self.accel_x = self._channel_with_offset(self._ctrl, "accel_x")
self.accel_y = self._channel_with_offset(self._ctrl, "accel_y")
self.accel_z = self._channel_with_offset(self._ctrl, "accel_z")
self.temp = self._channel(self._ctrl, "temp0")
self.deltaangl_x = self._channel(self._ctrl, "deltaangl_x")
self.deltaangl_y = self._channel(self._ctrl, "deltaangl_y")
self.deltaangl_z = self._channel(self._ctrl, "deltaangl_z")
self.deltavelocity_x = self._channel(self._ctrl, "deltavelocity_x")
self.deltavelocity_y = self._channel(self._ctrl, "deltavelocity_y")
self.deltavelocity_z = self._channel(self._ctrl, "deltavelocity_z")

rx.__init__(self)
self.rx_buffer_size = 16 # Make default buffer smaller

def __get_scaled_sensor(self, channel_name: str) -> float:
raw = self._get_iio_attr(channel_name, "raw", False)
scale = self._get_iio_attr(channel_name, "scale", False)

return raw * scale

def get_anglvel_x(self):
"""Value returned in radians per second."""
return self.__get_scaled_sensor("anglvel_x")

anglvel_x_conv = property(get_anglvel_x, None)

def get_anglvel_y(self):
"""Value returned in radians per second."""
return self.__get_scaled_sensor("anglvel_y")

anglvel_y_conv = property(get_anglvel_y, None)

def get_anglvel_z(self):
"""Value returned in radians per second."""
return self.__get_scaled_sensor("anglvel_z")

anglvel_z_conv = property(get_anglvel_z, None)

def get_accel_x(self):
"""Value returned in meters per squared second."""
return self.__get_scaled_sensor("accel_x")

accel_x_conv = property(get_accel_x, None)

def get_accel_y(self):
"""Value returned in meters per squared second."""
return self.__get_scaled_sensor("accel_y")

accel_y_conv = property(get_accel_y, None)

def get_accel_z(self):
"""Value returned in meters per squared second."""
return self.__get_scaled_sensor("accel_z")

accel_z_conv = property(get_accel_z, None)

def get_deltaangl_x(self):
"""Value returned in radians."""
return self.__get_scaled_sensor("deltaangl_x")

deltaangl_x_conv = property(get_deltaangl_x, None)

def get_deltaangl_y(self):
"""Value returned in radians."""
return self.__get_scaled_sensor("deltaangl_y")

deltaangl_y_conv = property(get_deltaangl_y, None)

def get_deltaangl_z(self):
"""Value returned in radians."""
return self.__get_scaled_sensor("deltaangl_z")

deltaangl_z_conv = property(get_deltaangl_z, None)

def get_deltavelocity_x(self):
"""Value returned in meters per second."""
return self.__get_scaled_sensor("deltavelocity_x")

deltavelocity_x_conv = property(get_deltavelocity_x, None)

def get_deltavelocity_y(self):
"""Value returned in meters per second."""
return self.__get_scaled_sensor("deltavelocity_y")

deltavelocity_y_conv = property(get_deltavelocity_y, None)

def get_deltavelocity_z(self):
"""Value returned in meters per second."""
return self.__get_scaled_sensor("deltavelocity_z")

deltavelocity_z_conv = property(get_deltavelocity_z, None)

def get_temp(self):
"""Value returned in millidegrees Celsius."""
return self.__get_scaled_sensor("temp0")

temp_conv = property(get_temp, None)

@property
def sample_rate(self):
"""sample_rate: Sample rate in samples per second"""
Expand All @@ -69,3 +174,144 @@ def sample_rate(self):
@sample_rate.setter
def sample_rate(self, value):
self._set_iio_dev_attr_str("sampling_frequency", value)

@property
def filter_low_pass_3db_frequency(self):
"""filter_low_pass_3db_frequency: Bandwidth for the accelerometer and
gyroscope channels"""
return self._get_iio_dev_attr("filter_low_pass_3db_frequency")

@filter_low_pass_3db_frequency.setter
def filter_low_pass_3db_frequency(self, value):
self._set_iio_dev_attr_str("filter_low_pass_3db_frequency", value)

@property
def anglvel_x_calibbias(self):
"""User calibration offset for gyroscope for the x-axis."""
return self._get_iio_attr("anglvel_x", "calibbias", False)

@anglvel_x_calibbias.setter
def anglvel_x_calibbias(self, value):
self._set_iio_attr("anglvel_x", "calibbias", False, value)

@property
def anglvel_y_calibbias(self):
"""User calibration offset for gyroscope for the y-axis."""
return self._get_iio_attr("anglvel_y", "calibbias", False)

@anglvel_y_calibbias.setter
def anglvel_y_calibbias(self, value):
self._set_iio_attr("anglvel_y", "calibbias", False, value)

@property
def anglvel_z_calibbias(self):
"""User calibration offset for gyroscope for the z-axis."""
return self._get_iio_attr("anglvel_z", "calibbias", False)

@anglvel_z_calibbias.setter
def anglvel_z_calibbias(self, value):
self._set_iio_attr("anglvel_z", "calibbias", False, value)

@property
def accel_x_calibbias(self):
"""User calibration offset for accelerometer for the x-axis."""
return self._get_iio_attr("accel_x", "calibbias", False)

@accel_x_calibbias.setter
def accel_x_calibbias(self, value):
self._set_iio_attr("accel_x", "calibbias", False, value)

@property
def accel_y_calibbias(self):
"""User calibration offset for accelerometer for the y-axis."""
return self._get_iio_attr("accel_y", "calibbias", False)

@accel_y_calibbias.setter
def accel_y_calibbias(self, value):
self._set_iio_attr("accel_y", "calibbias", False, value)

@property
def accel_z_calibbias(self):
"""User calibration offset for accelerometer for the z-axis."""
return self._get_iio_attr("accel_z", "calibbias", False)

@accel_z_calibbias.setter
def accel_z_calibbias(self, value):
self._set_iio_attr("accel_z", "calibbias", False, value)

@property
def firmware_revision(self):
"""firmware_revision: the firmware revision for the internal firmware"""
return self._get_iio_debug_attr_str("firmware_revision")

@property
def firmware_date(self):
"""firmware_date: the factory configuration date"""
return self._get_iio_debug_attr_str("firmware_date")

@property
def product_id(self):
"""product_id: the numerical portion of the device number"""
return self._get_iio_debug_attr("product_id")

@property
def serial_number(self):
"""serial_number: lot specific serial number"""
return self._get_iio_debug_attr_str("serial_number")

@property
def flash_count(self):
"""flash_counter: flash memory write count"""
return self._get_iio_debug_attr("flash_count")

class _channel_with_offset(attribute):
"""Channel with offset"""

def __init__(self, ctrl, channel_name):
self.name = channel_name
self._ctrl = ctrl

@property
def calibbias(self):
"""ADIS165x channel offset"""
return self._get_iio_attr(self.name, "calibbias", False)

@calibbias.setter
def calibbias(self, value):
self._set_iio_attr(self.name, "calibbias", False, value)

@property
def raw(self):
"""ADIS165x channel raw value"""
return self._get_iio_attr(self.name, "raw", False)

@property
def scale(self):
"""ADIS165x channel scale(gain)"""
return float(self._get_iio_attr_str(self.name, "scale", False))

class _channel(attribute):
"""Channel"""

def __init__(self, ctrl, channel_name):
self.name = channel_name
self._ctrl = ctrl

@property
def raw(self):
"""ADIS165x channel raw value"""
return self._get_iio_attr(self.name, "raw", False)

@property
def scale(self):
"""ADIS165x channel scale(gain)"""
return float(self._get_iio_attr_str(self.name, "scale", False))

def reg_read(self, reg):
"""Direct Register Access via debugfs"""
self._set_iio_debug_attr_str("direct_reg_access", reg, self._ctrl)
return self._get_iio_debug_attr_str("direct_reg_access", self._ctrl)

def reg_write(self, reg, value):
"""Direct Register Access via debugfs"""
self._set_iio_debug_attr_str("direct_reg_access", f"{reg} {value}", self._ctrl)
60 changes: 53 additions & 7 deletions examples/adis16475.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,64 @@
# Copyright (C) 2019 Analog Devices, Inc.
#
# SPDX short identifier: ADIBSD
import sys

import adi

# Set up AD7124
adis16475 = adi.adis16475()
my_dev_name = sys.argv[1]
my_uri = sys.argv[2]

adis16475 = adi.adis16475(device_name=my_dev_name, uri=my_uri)

# print Y and Z axis acceleration
# print(data)
print("Product id: " + str(adis16475.product_id))
print("Serial number: " + adis16475.serial_number)
print("Firmware revision: " + adis16475.firmware_revision)
print("Firmware date: " + adis16475.firmware_date)
print("\nX acceleration: " + str(adis16475.accel_x_conv) + " m/s^2")
print("Y acceleration: " + str(adis16475.accel_y_conv) + " m/s^2")
print("Z acceleration: " + str(adis16475.accel_z_conv) + " m/s^2")

print("\nX angular velocity: " + str(adis16475.anglvel_x_conv) + " rad/s")
print("Y angular velocity: " + str(adis16475.anglvel_y_conv) + " rad/s")
print("Z angular velocity: " + str(adis16475.anglvel_z_conv) + " rad/s")

adis16475.rx_output_type = "raw"
adis16475.rx_enabled_channels = [0, 1, 2, 3, 4, 5, 6]
adis16475.sample_rate = 2000
adis16475.rx_buffer_size = 100
adis16475.rx_enabled_channels = [6, 7, 8, 9, 10, 11, 12]
adis16475.sample_rate = 10
adis16475.rx_buffer_size = 10

data = adis16475.rx()

# print Y and Z axis acceleration
print(data)
for i in range(0, 9):
# arr = i
print(
"\nTemperature: "
+ str(data[0][i] * adis16475.temp.scale)
+ " millidegrees Celsius"
)
print(
"X delta angle: " + str(data[1][i] * adis16475.deltaangl_x.scale) + " radians"
)
print(
"Y delta angle: " + str(data[2][i] * adis16475.deltaangl_y.scale) + " radians"
)
print(
"Z delta angle: " + str(data[3][i] * adis16475.deltaangl_z.scale) + " radians"
)
print(
"X delta velocity: "
+ str(data[4][i] * adis16475.deltavelocity_x.scale)
+ " m/s"
)
print(
"Y delta velocity: "
+ str(data[5][i] * adis16475.deltavelocity_y.scale)
+ " m/s"
)
print(
"Z delta velocity: "
+ str(data[6][i] * adis16475.deltavelocity_z.scale)
+ " m/s"
)

0 comments on commit 353d2f9

Please sign in to comment.