mirror of
https://github.com/apirrone/Open_Duck_Mini_Runtime.git
synced 2025-09-03 03:33:54 +00:00
update
This commit is contained in:
parent
2ea34de1db
commit
1a84c47231
1 changed files with 8 additions and 4 deletions
|
@ -139,19 +139,23 @@ class Imu:
|
|||
took = time.time() - s
|
||||
time.sleep(max(0, 1 / self.sampling_freq - took))
|
||||
|
||||
def get_data(self, as_euler=False, as_mat=False):
|
||||
def get_data(self, rot_as_euler=False, rot_as_mat=False, gyro_as_euler=False):
|
||||
try:
|
||||
self.last_imu_data = self.imu_queue.get(False) # non blocking
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
if as_euler:
|
||||
if rot_as_euler:
|
||||
euler = R.from_quat(self.last_imu_data["orientation"]).as_euler("xyz")
|
||||
self.last_imu_data["orientation"] = euler
|
||||
elif as_mat:
|
||||
elif rot_as_mat:
|
||||
mat = R.from_quat(self.last_imu_data["orientation"]).as_matrix()
|
||||
self.last_imu_data["orientation"] = mat
|
||||
|
||||
if gyro_as_euler:
|
||||
euler = R.from_quat(self.last_imu_data["gyro"]).as_euler("xyz")
|
||||
self.last_imu_data["gyro"] = euler
|
||||
|
||||
return self.last_imu_data
|
||||
|
||||
|
@ -164,7 +168,7 @@ if __name__ == "__main__":
|
|||
imu = Imu(50, calibrate=False, upside_down=False)
|
||||
# imu = Imu(50, upside_down=False)
|
||||
while True:
|
||||
data = imu.get_data(as_mat=True)
|
||||
data = imu.get_data(rot_as_mat=True, gyro_as_euler=True)
|
||||
if data is None:
|
||||
continue
|
||||
# print(data)
|
||||
|
|
Loading…
Reference in a new issue