Skip to content

Commit c742e2f

Browse files
committed
Make gyro rate functions public
1 parent 7c2f19a commit c742e2f

File tree

1 file changed

+66
-66
lines changed

1 file changed

+66
-66
lines changed

XRPLib/imu.py

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -137,70 +137,6 @@ def _raw_to_mg(self, raw):
137137

138138
def _raw_to_mdps(self, raw):
139139
return self._int16((raw[1] << 8) | raw[0]) * LSM_MDPS_PER_LSB_125DPS * self._gyro_scale_factor
140-
141-
def _get_gyro_x_rate(self):
142-
"""
143-
Individual axis read for the Gyroscope's X-axis, in mg
144-
"""
145-
# Burst read data registers
146-
raw_bytes = self._getregs(LSM_REG_OUTX_L_G, 2)
147-
148-
# Convert raw data to mdps
149-
return self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[0]
150-
151-
def _get_gyro_y_rate(self):
152-
"""
153-
Individual axis read for the Gyroscope's Y-axis, in mg
154-
"""
155-
# Burst read data registers
156-
raw_bytes = self._getregs(LSM_REG_OUTY_L_G, 2)
157-
158-
# Convert raw data to mdps
159-
return self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[1]
160-
161-
def _get_gyro_z_rate(self):
162-
"""
163-
Individual axis read for the Gyroscope's Z-axis, in mg
164-
"""
165-
# Burst read data registers
166-
raw_bytes = self._getregs(LSM_REG_OUTZ_L_G, 2)
167-
168-
# Convert raw data to mdps
169-
return self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[2]
170-
171-
def _get_gyro_rates(self):
172-
"""
173-
Retrieves the array of readings from the Gyroscope, in mdps
174-
The order of the values is x, y, z.
175-
"""
176-
# Burst read data registers
177-
raw_bytes = self._getregs(LSM_REG_OUTX_L_G, 6)
178-
179-
# Convert raw data to mdps
180-
self.irq_v[1][0] = self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[0]
181-
self.irq_v[1][1] = self._raw_to_mdps(raw_bytes[2:4]) - self.gyro_offsets[1]
182-
self.irq_v[1][2] = self._raw_to_mdps(raw_bytes[4:6]) - self.gyro_offsets[2]
183-
184-
return self.irq_v[1]
185-
186-
def _get_acc_gyro_rates(self):
187-
"""
188-
Get the accelerometer and gyroscope values in mg and mdps in the form of a 2D array.
189-
The first row is the acceleration values, the second row is the gyro values.
190-
The order of the values is x, y, z.
191-
"""
192-
# Burst read data registers
193-
raw_bytes = self._getregs(LSM_REG_OUTX_L_G, 12)
194-
195-
# Convert raw data to mg's and mdps
196-
self.irq_v[0][0] = self._raw_to_mg(raw_bytes[6:8]) - self.acc_offsets[0]
197-
self.irq_v[0][1] = self._raw_to_mg(raw_bytes[8:10]) - self.acc_offsets[1]
198-
self.irq_v[0][2] = self._raw_to_mg(raw_bytes[10:12]) - self.acc_offsets[2]
199-
self.irq_v[1][0] = self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[0]
200-
self.irq_v[1][1] = self._raw_to_mdps(raw_bytes[2:4]) - self.gyro_offsets[1]
201-
self.irq_v[1][2] = self._raw_to_mdps(raw_bytes[4:6]) - self.gyro_offsets[2]
202-
203-
return self.irq_v
204140

205141
"""
206142
Public facing API Methods
@@ -300,6 +236,70 @@ def get_acc_rates(self):
300236
self.irq_v[0][2] = self._raw_to_mg(raw_bytes[4:6]) - self.acc_offsets[2]
301237

302238
return self.irq_v[0]
239+
240+
def get_gyro_x_rate(self):
241+
"""
242+
Individual axis read for the Gyroscope's X-axis, in mg
243+
"""
244+
# Burst read data registers
245+
raw_bytes = self._getregs(LSM_REG_OUTX_L_G, 2)
246+
247+
# Convert raw data to mdps
248+
return self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[0]
249+
250+
def get_gyro_y_rate(self):
251+
"""
252+
Individual axis read for the Gyroscope's Y-axis, in mg
253+
"""
254+
# Burst read data registers
255+
raw_bytes = self._getregs(LSM_REG_OUTY_L_G, 2)
256+
257+
# Convert raw data to mdps
258+
return self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[1]
259+
260+
def get_gyro_z_rate(self):
261+
"""
262+
Individual axis read for the Gyroscope's Z-axis, in mg
263+
"""
264+
# Burst read data registers
265+
raw_bytes = self._getregs(LSM_REG_OUTZ_L_G, 2)
266+
267+
# Convert raw data to mdps
268+
return self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[2]
269+
270+
def get_gyro_rates(self):
271+
"""
272+
Retrieves the array of readings from the Gyroscope, in mdps
273+
The order of the values is x, y, z.
274+
"""
275+
# Burst read data registers
276+
raw_bytes = self._getregs(LSM_REG_OUTX_L_G, 6)
277+
278+
# Convert raw data to mdps
279+
self.irq_v[1][0] = self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[0]
280+
self.irq_v[1][1] = self._raw_to_mdps(raw_bytes[2:4]) - self.gyro_offsets[1]
281+
self.irq_v[1][2] = self._raw_to_mdps(raw_bytes[4:6]) - self.gyro_offsets[2]
282+
283+
return self.irq_v[1]
284+
285+
def get_acc_gyro_rates(self):
286+
"""
287+
Get the accelerometer and gyroscope values in mg and mdps in the form of a 2D array.
288+
The first row is the acceleration values, the second row is the gyro values.
289+
The order of the values is x, y, z.
290+
"""
291+
# Burst read data registers
292+
raw_bytes = self._getregs(LSM_REG_OUTX_L_G, 12)
293+
294+
# Convert raw data to mg's and mdps
295+
self.irq_v[0][0] = self._raw_to_mg(raw_bytes[6:8]) - self.acc_offsets[0]
296+
self.irq_v[0][1] = self._raw_to_mg(raw_bytes[8:10]) - self.acc_offsets[1]
297+
self.irq_v[0][2] = self._raw_to_mg(raw_bytes[10:12]) - self.acc_offsets[2]
298+
self.irq_v[1][0] = self._raw_to_mdps(raw_bytes[0:2]) - self.gyro_offsets[0]
299+
self.irq_v[1][1] = self._raw_to_mdps(raw_bytes[2:4]) - self.gyro_offsets[1]
300+
self.irq_v[1][2] = self._raw_to_mdps(raw_bytes[4:6]) - self.gyro_offsets[2]
301+
302+
return self.irq_v
303303

304304
def get_pitch(self):
305305
"""
@@ -503,7 +503,7 @@ def calibrate(self, calibration_time:float=1, vertical_axis:int= 2):
503503
time.sleep(.1)
504504
start_time = time.ticks_ms()
505505
while time.ticks_ms() < start_time + calibration_time*1000:
506-
cur_vals = self._get_acc_gyro_rates()
506+
cur_vals = self.get_acc_gyro_rates()
507507
# Accelerometer averages
508508
avg_vals[0][0] += cur_vals[0][0]
509509
avg_vals[0][1] += cur_vals[0][1]
@@ -538,7 +538,7 @@ def _stop_timer(self):
538538

539539
def _update_imu_readings(self):
540540
# Called every tick through a callback timer
541-
self._get_gyro_rates()
541+
self.get_gyro_rates()
542542
delta_pitch = self.irq_v[1][0] / 1000 / self.timer_frequency
543543
delta_roll = self.irq_v[1][1] / 1000 / self.timer_frequency
544544
delta_yaw = self.irq_v[1][2] / 1000 / self.timer_frequency

0 commit comments

Comments
 (0)