Repository navigation
Native bno080 (spi) + bno080i2c implementation in circuitpython v9 #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
bb20c02
Add ringbuffer lib
jocelynmass f76f3d7
Use a ringbuffer to store ADS samples
jocelynmass b9c3133
Initial BNO driver (only fquat for now) - wip
jocelynmass a3388d2
Add accel and gyro reports
jocelynmass ec3461c
initial i2c implementation (untested)
christopherwun 7bd50a9
refactor files for compilation issues-compiles now
christopherwun d313e9f
new
christopherwun 58a891c
fix module naming
christopherwun ef3307a
i2c driver in progress
christopherwun 7aafe3e
separate read/write
christopherwun 6a6f84d
fixed soft reset command
christopherwun 8c824cc
remove unused pin declarations
christopherwun 3efe626
construct working
christopherwun dccfb2e
working i2c driver
christopherwun 12366f6
move prints to debug
christopherwun 5c3786d
added flag for data recv
christopherwun 67381e9
Merge branch 'jocelyn/bno080' into chris/native-bno-v9
christopherwun 204150b
updated syntax to compile properly
christopherwun e9c0b59
Merge remote-tracking branch 'origin/chris/bno080i2c' into chris/nati…
christopherwun f32f358
remove autogenerated build files from repo
christopherwun b0f24df
add .P to gitignore
christopherwun 5fc6ca6
edited to compile properly
christopherwun 4f40386
linted with circuitpython pre-commit
christopherwun 1d449a9
consistency with quat/gyro/accel recv flags in i2c implementation, ch…
christopherwun ec1c9f2
moved ringbuf size in ads to named constant instead of magic number
christopherwun 17e7829
commented gc_alloc line for more clarity on changes from v7
christopherwun 63027c1
addressing failing checks
christopherwun 227c7dd
ran pre-commit to fix formatting
christopherwun 297f594
fixed precommit fully
christopherwun c1f3516
fixing bno080i2c formatting
christopherwun 7e7298e
updated python docstrings for accuracy + prevent redundancy
christopherwun 85281c0
moved digitalio_edge_t typedef into shared binding for CI
christopherwun 4afb859
moved the io_irq_t typedef to shared-bindings as well
christopherwun 76cdf29
remove get_html_theme_path call as specified by CI
christopherwun c88c0e6
update build workflow to match the most recent circuitpython version …
christopherwun be5ebb0
decrease bufsize, add locking to ringbuf
christopherwun f9b44d3
backgrounding isr
christopherwun 410c7f4
update ringbuf to allow interrupts
christopherwun 927ddb2
remove ads buffering files + changes
christopherwun 1e150b5
removed remnants of ringbuf from bno08x modules
christopherwun 9987777
fixed docstring to indicate correct default
christopherwun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| ################### | ||
| *.o | ||
| *.a | ||
| *.P | ||
| !atmel-samd/asf/**/*.a | ||
| *.elf | ||
| *.bin | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,169 @@ | ||
| #include "shared-bindings/util.h" | ||
| #include "orientation.h" | ||
| #include <math.h> | ||
|
|
||
| // quaternion is a 4 float array [x,y,z,w] | ||
|
|
||
| void | ||
| orientation_multiply(float *a, float *b, float *out) | ||
| { | ||
| // val rw = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z | ||
| out[3] = a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2]; | ||
| // val rx = a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y | ||
| out[0] = a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1]; | ||
| // val ry = a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x | ||
| out[1] = a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0]; | ||
| // val rz = a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w | ||
| out[2] = a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3]; | ||
| } | ||
|
|
||
| void | ||
| orientation_inverse(float *a, float *out) | ||
| { | ||
| // val d = w*w + x*x + y*y + z*z | ||
| // return Quaternion(-x / d, -y / d, -z / d, w / d) | ||
| float d = a[3] * a[3] + a[0] * a[0] + a[1] * a[1] + a[2] * a[2]; | ||
| out[0] = -a[0] / d; | ||
| out[1] = -a[1] / d; | ||
| out[2] = -a[2] / d; | ||
| out[3] = a[3] / d; | ||
| } | ||
|
|
||
| void | ||
| orientation_difference(float *quat_a, float *quat_b, float *quat_out) | ||
| { | ||
| float inverse[4]; | ||
| orientation_inverse(quat_a, inverse); | ||
| orientation_multiply(inverse, quat_b, quat_out); | ||
| } | ||
|
|
||
|
|
||
| void | ||
| orientation_forward(float rotation, float *out) | ||
| { | ||
| float half = rotation/2; | ||
| out[0] = 0.0; | ||
| out[1] = 0.0; | ||
| out[2] = sin(half); | ||
| out[3] = cos(half); | ||
| } | ||
|
|
||
| // apply calibration to quat_in to produce quat_out | ||
| // | ||
| void | ||
| orientation_normalize(float *calibration, float *quat_in, float *quat_out) | ||
| { | ||
| float uprighted[5]; | ||
| orientation_multiply(quat_in, calibration, uprighted); | ||
|
|
||
| float forward[5]; | ||
| orientation_forward(calibration[4], forward); | ||
|
|
||
| float forwarded[5]; | ||
| orientation_multiply(uprighted, forward, forwarded); | ||
|
|
||
| float norm[5]; | ||
| orientation_forward(-calibration[4], norm); | ||
|
|
||
| orientation_multiply(norm, forwarded, quat_out); | ||
| } | ||
|
|
||
|
|
||
| void | ||
| orientation_quaternion_to_euler(float *q, float *e) | ||
| { | ||
| // roll (x-axis rotation) | ||
| float sinr = 2.0 * (q[3] * q[0] + q[1] * q[2]); | ||
| float cosr = 1.0 - 2.0 * (q[0] * q[0] + q[1] * q[1]); | ||
| e[0] = atan2(sinr, cosr); | ||
|
|
||
| // pitch (y-axis rotation) | ||
| float sinp = 2.0 * (q[3] * q[1] - q[2] * q[0]); | ||
| if (fabs(sinp) < 1) { | ||
| e[1] = asin(sinp); | ||
| } | ||
| else { | ||
| e[1] = copysign(M_PI_2, sinp); | ||
| } | ||
|
|
||
| // yaw (z-axis rotation) | ||
| float siny = 2.0 * (q[3] * q[2] + q[0] * q[1]); | ||
| float cosy = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]); | ||
| e[2] = atan2(siny, cosy); | ||
| } | ||
|
|
||
| /* | ||
| // a function that could be useful in the future | ||
| def get_quaternion_from_euler(roll, pitch, yaw): | ||
| """ | ||
| Convert an Euler angle to a quaternion. | ||
|
|
||
| Input | ||
| :param roll: The roll (rotation around x-axis) angle in radians. | ||
| :param pitch: The pitch (rotation around y-axis) angle in radians. | ||
| :param yaw: The yaw (rotation around z-axis) angle in radians. | ||
|
|
||
| Output | ||
| :return qx, qy, qz, qw: The orientation in quaternion [x,y,z,w] format | ||
| """ | ||
| qx = np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) - np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2) | ||
| qy = np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) | ||
| qz = np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) - np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) | ||
| qw = np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2) | ||
|
|
||
| return [qx, qy, qz, qw] | ||
|
|
||
| */ | ||
|
|
||
| void | ||
| euler_to_orientation_quaternion(float *e, float *q) | ||
| { | ||
| float roll, pitch, yaw; | ||
| roll = e[0]; | ||
| pitch = e[1]; | ||
| yaw = e[2]; | ||
|
|
||
| q[0] = sin(roll/2) * cos(pitch/2) * cos(yaw/2) - cos(roll/2) * sin(pitch/2) * sin(yaw/2); | ||
| q[1] = cos(roll/2) * sin(pitch/2) * cos(yaw/2) + sin(roll/2) * cos(pitch/2) * sin(yaw/2); | ||
| q[2] = cos(roll/2) * cos(pitch/2) * sin(yaw/2) - sin(roll/2) * sin(pitch/2) * cos(yaw/2); | ||
| q[3] = cos(roll/2) * cos(pitch/2) * cos(yaw/2) + sin(roll/2) * sin(pitch/2) * sin(yaw/2); | ||
| } | ||
|
|
||
|
|
||
| // clear calibration vector | ||
| int | ||
| orientation_cal_clear(float *calibration) | ||
| { | ||
| calibration[0] = 0; // i | ||
| calibration[1] = 0; // j | ||
| calibration[2] = 0; // k | ||
| calibration[3] = 1; // real | ||
| calibration[4] = 0; // rotation | ||
| return 0; | ||
| } | ||
|
|
||
| // calibrate upright | ||
| int orientation_cal_upright(float *quat, float *calibration) | ||
| { | ||
| orientation_inverse(quat, calibration); | ||
| return 0; | ||
| } | ||
|
|
||
| // calibrate forward | ||
| int orientation_cal_forward(float *quat, float *calibration) | ||
| { | ||
| float calibrated[4]; | ||
| float euler[3]; | ||
|
|
||
| // apply rotation greedily until find zero pitch | ||
| for (float i=-180.0; i <= 180.0; i += 1.0) { | ||
| calibration[4] = i * 0.0174533; // convert degrees to radians | ||
| orientation_normalize(calibration, quat, calibrated); | ||
| orientation_quaternion_to_euler(calibrated, euler); | ||
| if (RAD2DEG(euler[0]) > 0 && RAD2DEG(euler[1]) == 0) { | ||
| return 0; | ||
| } | ||
| } | ||
| calibration[4] = 0; | ||
| return -1; | ||
| } |
This file contains hidden or 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,42 @@ | ||
| #ifndef __ORIENTATION_H__ | ||
| #define __ORIENTATION_H__ | ||
|
|
||
| #define DEG2RAD(d) ((float)d * 0.0174533) | ||
| #define RAD2DEG(r) ((int)(r*57.2958)) | ||
|
|
||
| // quat_a * quat_b output to quat_out | ||
| // | ||
| void orientation_multiply(float *quat_a, float *quat_b, float *quat_out); | ||
|
|
||
| // perform quaterion invers on quat_in to produce quat_out | ||
| // | ||
| void orientation_inverse(float *quat_in, float *quat_out); | ||
|
|
||
| // calculate difference between quat_a and quat_b and output to quat out | ||
| // | ||
| void orientation_difference(float *quat_a, float *quat_b, float *quat_out); | ||
|
|
||
| void orientation_forward(float rotation, float *out); | ||
|
|
||
| // apply calibration to quat_in to produce quat_out | ||
| // | ||
| void orientation_normalize(float *calibration, float *quat_in, float *quat_out); | ||
|
|
||
| // convert a quaternion to euler | ||
| // | ||
| void orientation_quaternion_to_euler(float *quaternion, float *euler); | ||
|
|
||
| // convert euler to quaternion | ||
| // | ||
| void euler_to_orientation_quaternion(float *euler, float *quaternion); | ||
|
|
||
| // clear calibration vector | ||
| int orientation_cal_clear(float *calibration); | ||
|
|
||
| // calibrate upright | ||
| int orientation_cal_upright(float *quat, float *calibration); | ||
|
|
||
| // calibrate forward | ||
| int orientation_cal_forward(float *quat, float *calibration); | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.