Parking Finder
The Parking Finder system is a smart parking solution designed to help drivers efficiently locate available
Loading...
Searching...
No Matches
imu.IMU Class Reference

Public Member Functions

 __init__ (self)
 __str__ (self)
 update_loop (self)
 get_accel (self)
 get_gyro (self)
 get_magn (self)
 stop (self)

Public Attributes

 sensor = adafruit_icm20x.ICM20948(i2c)
bool running = True
 accel = self.sensor.acceleration
 gyro = self.sensor.gyro
 magnetic = self.sensor.magnetic
bool new_data = False
 thread = threading.Thread(target=self.update_loop, daemon=True)

Detailed Description

Definition at line 15 of file imu.py.

Constructor & Destructor Documentation

◆ __init__()

imu.IMU.__init__ ( self)

Definition at line 16 of file imu.py.

16 def __init__(self):
17
18 i2c = board.I2C()
19 self.sensor = adafruit_icm20x.ICM20948(i2c)
20 #self.rate = rate_hz
21 self.running = True
22
23 self.accel = self.sensor.acceleration# m/s^2
24 self.gyro = self.sensor.gyro #rad/s
25 self.magnetic = self.sensor.magnetic # uT
26
27 # new data flag
28 self.new_data = False
29
30 # start background thread
31 self.thread = threading.Thread(target=self.update_loop, daemon=True)
32 self.thread.start()
33

Member Function Documentation

◆ __str__()

imu.IMU.__str__ ( self)

Definition at line 34 of file imu.py.

34 def __str__(self):
35 return (
36 f"Acceleration: X:{self.accel[0]:.3f}, Y:{self.accel[1]:.3f}, Z:{self.accel[2]:.3f} m/s^2\n"
37 f"Gyroscope: X:{self.gyro[0]:.3f}, Y:{self.gyro[1]:.3f}, Z:{self.gyro[2]:.3f} rads/s\n"
38 f"Magnetometer: X:{self.magnetic[0]:.3f}, Y:{self.magnetic[1]:.3f}, Z:{self.magnetic[2]:.3f} uT\n"
39 )
40

◆ get_accel()

imu.IMU.get_accel ( self)

Definition at line 50 of file imu.py.

50 def get_accel(self):
51 return self.accel
52

◆ get_gyro()

imu.IMU.get_gyro ( self)

Definition at line 53 of file imu.py.

53 def get_gyro(self):
54 return self.gyro
55

◆ get_magn()

imu.IMU.get_magn ( self)

Definition at line 56 of file imu.py.

56 def get_magn(self):
57 self.new_data = False
58 return self.magnetic
59

◆ stop()

imu.IMU.stop ( self)

Definition at line 60 of file imu.py.

60 def stop(self):
61 self.running = False
62 self.thread.join()

◆ update_loop()

imu.IMU.update_loop ( self)

Definition at line 41 of file imu.py.

41 def update_loop(self):
42 #period = 1 / self.rate
43 while self.running:
44 self.accel = self.sensor.acceleration
45 self.gyro = self.sensor.gyro
46 self.magnetic = self.sensor.magnetic
47 self.new_data = True
48 #time.sleep(period)
49

Member Data Documentation

◆ accel

imu.IMU.accel = self.sensor.acceleration

Definition at line 23 of file imu.py.

◆ gyro

imu.IMU.gyro = self.sensor.gyro

Definition at line 24 of file imu.py.

◆ magnetic

imu.IMU.magnetic = self.sensor.magnetic

Definition at line 25 of file imu.py.

◆ new_data

bool imu.IMU.new_data = False

Definition at line 28 of file imu.py.

◆ running

bool imu.IMU.running = True

Definition at line 21 of file imu.py.

◆ sensor

imu.IMU.sensor = adafruit_icm20x.ICM20948(i2c)

Definition at line 19 of file imu.py.

◆ thread

imu.IMU.thread = threading.Thread(target=self.update_loop, daemon=True)

Definition at line 31 of file imu.py.


The documentation for this class was generated from the following file: