-
Notifications
You must be signed in to change notification settings - Fork 53
Add calibration offsets and radii as properties on BNO055 library #22
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
Conversation
Thanks for the PR. It's not passing the Travis check. Looks like it's missing docstrings. Let us know if you need help checking and reading the Travis report. |
@caternuson Would you mind picking this up? I think @katlings is travelling. They did this during the PyCascades sprint last week. |
My bad! @tannewt is right, I'm on the road, but I should be able to find time to fix this up on Monday. If you'd like it sooner, feel free to take over! |
@caternuson Check again! :) |
It looks good and is readable, but that's a lot of repeated code. I wonder if it would make sense to have something like a context manager for encapsulating that code. Something like: class Mode:
__init__(self, sensor, mode):
self.sensor = sensor
self.mode = mode
self.last_mode = None
___enter__(self):
self.last_mode = self.sensor.mode
self.sensor.mode = mode
return self
__exit__(self, exc_type, exc_value, traceback):
self.sensor.mode = last_mode and then: with EnsureMode(self, CONFIG_MODE):
return self._offsets_accelerometer Alternatively (and I think ultimately better), perhaps we could have a mode-aware version of the class ModeStruct(Struct):
def __init__(self, register_address, struct_format, mode):
super().__init__(register_address, struct_format)
self.mode = mode
def __get__(self, obj, objtype=None):
last_mode = obj.mode
obj.mode = self.mode
result = super().__get__(obj, objtype)
obj.mode = last_mode
return result
def __set__(self, obj, value):
last_mode = obj.mode
obj.mode = self.mode
super().__set__(obj, value)
obj.mode = last_mode |
@deshipu That's a good idea but let's not require it for this PR. That way someone else can pick it up. |
@deshipu I like both solutions; the mode struct in particular looks like it would enable manually setting these parameters (which I believe is supported) with no further fuss. I'm still traveling and am happy to follow up when I get home tomorrow, though I don't have the right board to test this with and might need @tannewt's help for that. |
@katlings I'm happy to get you boards if you want to keep working on this when you get home. |
@katlings Thanks, this is looking good. Nice continued use of Current code for reading tests and works: Adafruit CircuitPython 3.1.2 on 2019-01-07; Adafruit ItsyBitsy M0 Express with samd21g18
>>> import board, busio
>>> import adafruit_bno055
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> bno = adafruit_bno055.BNO055(i2c)
>>> bno.offsets_magnetometer
(0, 0, 0)
>>> bno.offsets_gyroscope
(-2, -2, 0)
>>> bno.offsets_accelerometer
(0, 0, 0)
>>> bno.radius_magnetometer
0
>>> |
@katlings Still interested in wrapping this up? |
…pose calibration and radii as r/w properties on BNO055
expose calibration and radii as r/w properties on BNO055
The code is working from a python point of view, but the board does not always accept the new calibration value
|
remove sleep from set method in ModeStruct
This ready to go? |
Are 1D tuples the only way to get this to work? I'm concerned that subtle little |
I am pretty sure we can make that more natural. Will look at it this weekend and submit an updated PR. Any advice on how to submit the PR directly and avoid @katlings having to broker this through her fork? |
@sjirwin you can make a new PR to this repo and we can close this one. |
Seems this PR was left open by mistake. |
Issue #21
the
@property
decorator +Struct
had some interesting__get__
interactions, resulting in some repetition in the code. Happy to revisit if someone has a better idea.I didn't use the
ReadOnlyStruct
s already defined in this file because letting the user overwrite the calibration is supported in Arduino, so someday it would be nice to do that here too. I don't think it'll take much