Replies: 1 comment 6 replies
-
I am glad you asked! I have been wondering about exactly this, and prepared some code as well (I might need to dig it up somewhere). I haven't added it to the device class because I wasn't sure anyone else would ever need it 😄 The use case I was originally after, was to provide tilt in the full range (outside of -45/45), and optionally also outside the default orientation as we do allow for hubs.
We probably couldn't add it to the Move Hub firmware due to build size, and it would be nice to keep the classes the same on all hubs. So having a few examples like those might be the best thing to start with indeed. It would be great if you want to make a pull request in the docs. Here's another possibility if you want to take it further. Perhaps as an additional example: Now that we support importing code across modules in Pybricks Code, it's possible to extend the In your example: # Calculate acceleration vector from tilt angles
acceleration = [sin(t[0])*cos(t[1])*cos(t[2]),
cos(t[0])*sin(t[1])*cos(t[2]),
cos(t[0])*cos(t[1])*sin(t[2])] Does this work along the whole sphere of rotations? Looking back at my notes, I found that I had to use various if/else branches to ensure that I didn't use one of the values that was capped at 45 degrees, but always the other two to get tilt/acceleration. |
Beta Was this translation helpful? Give feedback.
-
In my spare-time I am building a lego robot dog and would like to teach it to walk. Each leg has a technic-hub in the upper part and a (WeDo-)tilt-sensor in the lower part to keep track of the position using acceleration. For this I am using the tilt-sensor in "CAL" mode where it reads 3 angles that are supposed to go from -45 to 45 degrees. If you shake the sensors you can easily get values above or below that interval. For that reason and to be similar to the integrated accelerometer in the technic-hub I convert the values to acceleration like this:
What do you think of this? This could maybe be a nice addition to the library. Maybe as an example in the documentation of the tilt-sensor although it is not using the tilt-sensor-class? Or the "CAL" mode could be implemented and then used like this? I also made a proof of concept of implementing this conversion itself
https://github.com/pybricks/pybricks-micropython/compare/master...Debenben:pybricks-micropython:acceleration?expand=1
I did not try to optimize it for compilation size, but I imagine one could make it smaller by restructuring and possibly reusing code.
Also I wanted to format the acceleration output like that of the internal technic-hub accelerometer but it seems the code does not match the documentation. The magnitude of the vector my technic-hub returns with the current master branch of pybricks-micropython is around 1000. The documentation
https://docs.pybricks.com/en/latest/hubs/technichub.html#pybricks.hubs.TechnicHub.imu.acceleration
sais the unit is mm/s^2. Gravitational acceleration on earth is around 9.81m/s^2 = 9810 mm/s^2 which is about 10 times larger than 1000 from the technic-hub.
Beta Was this translation helpful? Give feedback.
All reactions