Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert quaternions to yaw degrees. #84

Open
wants to merge 1 commit into
base: develop-0.7.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Convert quaternions to yaw degrees.
  • Loading branch information
Ryan Sprott committed Jul 9, 2020
commit 231b4f80c0de47a4c88b4777d44a14a60e51c161
12 changes: 11 additions & 1 deletion tellopy/_internal/protocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import struct
import math
from io import BytesIO

from . import crc
@@ -377,7 +378,7 @@ def format_cvs(self):

def format_cvs_header(self):
return (
"mvo.vel_x,mvo.vel_y,mvo.vel_z" +
"mvo.vel_x,mvo.vel_y,mvo.vel_z" +
",mvo.pos_x,mvo.pos_y,mvo.pos_z" +
"")

@@ -406,6 +407,7 @@ def __init__(self, log = None, data = None):
self.q1 = 0.0
self.q2 = 0.0
self.q3 = 0.0
self.yaw = 0.0
self.vg_x = 0.0
self.vg_y = 0.0
self.vg_z = 0.0
@@ -436,11 +438,19 @@ def format_cvs_header(self):
",imu.vg_x,imu.vg_y,imu.vg_z" +
"")

def quaternion_to_yaw_degree(self, qw, qx, qy, qz):
degree = math.pi / 180.0
sin_y = 2.0 * (qw * qz + qx * qy)
cos_y = 1.0 - 2 * (qy * qy + qz * qz)
yaw = round(math.atan2(sin_y, cos_y) / degree, 2)
return yaw

def update(self, data, count = 0):
self.log.debug('LogImuAtti: length=%d %s' % (len(data), byte_to_hexstring(data)))
self.count = count
(self.acc_x, self.acc_y, self.acc_z) = struct.unpack_from('fff', data, 20)
(self.gyro_x, self.gyro_y, self.gyro_z) = struct.unpack_from('fff', data, 32)
(self.q0, self.q1, self.q2, self.q3) = struct.unpack_from('ffff', data, 48)
(self.vg_x, self.vg_y, self.vg_z) = struct.unpack_from('fff', data, 76)
self.yaw = self.quaternion_to_yaw_degree(self.q0, self.q1, self.q2, self.q3)
self.log.debug('LogImuAtti: ' + str(self))