-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #178: Add LH angle streaming support
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# || ____ _ __ | ||
# +------+ / __ )(_) /_______________ _____ ___ | ||
# | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \ | ||
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ | ||
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/ | ||
# | ||
# Copyright (C) 2020 Bitcraze AB | ||
# | ||
# Crazyflie Nano Quadcopter Client | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
# MA 02110-1301, USA. | ||
|
||
import struct | ||
|
||
|
||
# Code from davidejones at https://gamedev.stackexchange.com/a/28756 | ||
def fp16_to_float(float16): | ||
s = int((float16 >> 15) & 0x00000001) # sign | ||
e = int((float16 >> 10) & 0x0000001f) # exponent | ||
f = int(float16 & 0x000003ff) # fraction | ||
|
||
if e == 0: | ||
if f == 0: | ||
return int(s << 31) | ||
else: | ||
while not (f & 0x00000400): | ||
f = f << 1 | ||
e -= 1 | ||
e += 1 | ||
f &= ~0x00000400 | ||
# print(s,e,f) | ||
elif e == 31: | ||
if f == 0: | ||
return int((s << 31) | 0x7f800000) | ||
else: | ||
return int((s << 31) | 0x7f800000 | (f << 13)) | ||
|
||
e = e + (127 - 15) | ||
f = f << 13 | ||
result = int((s << 31) | (e << 23) | f) | ||
return struct.unpack("f", struct.pack("I", result))[0] |