Puck.js v2 Accelerometer/Gyroscope output... #3612
Replies: 13 comments
-
Posted at 2020-10-04 by Robin Sun 2020.10.04
There is a note concerning the mag, presumably the gyro also: Has Are the same flutuations observed when using the low power module?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-10-04 by BrianH Thanks for the tip regarding the battery charge. However, Unfortunately, using the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-10-05 by @gfwilliams
Yes, however I'd say only if what you're attaching the Puck to is moving slowly. Since you're unlikely to be able to get the accelerometer at the centre of rotation, at higher speeds the centrifugal force could cause issues.
You mean for the gyro? The accelerometer itself looks pretty good. In the gyro case I think it's an issue with the accelerometer - basically because Espruino turns the accelerometer on, then takes the first reading, then turns it off, the gyro doesn't get time to 'settle' before a reading is made. I bet if you run
The other thing you could try for counting revolutions is the magnetometer. For instance you could stick a magnet on whatever is rotating and then have the Puck next to it. You could use the XYZ values from the magnetometer to get a pretty good idea of absolute position. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-11-02 by BrianH Thanks Gordon, I was able to get better readings from the IMU after using The application I'm working on is a bit unique. I need to count revolutions of a spindle with the Puck mounted inside the spindle itself. I can't use any external reference source like a magnet or light to count the revolutions. The spindle will spin infrequently, and at varying velocities (think of pulling a length of paper from a roll). I'm hoping the gyroscope might be a reliable source of data for this application (spinning on the z axis). If I can get the gyro to reliably output scaled values in degrees or revolutions per second, would it just be a matter of dividing the the output by the amount of time that it spun? Or is the math not that simple? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-11-03 by @gfwilliams Ahh, interesting. Try this:
If you rotate the Puck around like it's a knob then it will do a pretty convincing job of counting rotations (I can't promise it's actually calibrated in any way though). However it will wander off over time because the gyro does have noise. How is the spindle mounted? Because if it's horizontal then you've also got gravity, so you could detect when the Puck hasn't moved for a while and then use gravity to get an 'absolute' reading for rotation... This one seems to work reasonably well - it uses a slightly higher data rate of 26Hz which I think works better:
However with that kind of thing it's drawing around 1mA, so you could expect a battery life of around 10 days. You might also want to consider combining it with the movement detection on http://www.espruino.com/Puck.js#accelerometer-gyro to get it to enter a low power sleep mode when nothing is happening. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-11-04 by BrianH Wow! Thanks, Gordon. Both of those examples seem to be working well. A couple questions:
Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-11-04 by @gfwilliams I actually just added this to the Espruino App loader as well: https://espruino.github.io/EspruinoApps/#puckrotate You can get the code by clicking the GitHub icon but the code has some power saving built in too which will really increase the battery life.
Honestly, I started out calculating it based on 2000dps, 26 samples per second, and 360 degrees but then I just rotated the Puck by 360 degrees looked at the value I got, and divided by that - so it's almost certainly not exactly right.
They're created in line 10/11. Just added to the acceleration object because then I could see what they were by looking at
Yes, sorry - it was a quick hack so I didn't document it too well...
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-11-28 by BrianH Hi Gordon, I've been playing around with the puckrotate code you have added to the Espruino App loader. I really like how you've added the sleep/awake functionality. However, I'm running into a bit of trouble after the Puck wakes (using the "puckjsv2-accel-movement" module) from the first time it has fallen asleep. The scaling that was initially, say 12.5Hz/2000dps, set seems to be erased (or overwritten) and where a single revolution might have outputted 1.00, now outputs as 4 or 5 revolutions. This only happens after the Puck is waken from its first sleep, and the only way I can seem to set the device straight again is by power cycling it. This makes me think that the issue is with the accel/gyro chip itself, perhaps? It's almost as if the 12.5Hz data rate gets stuck at 26Hz and can't be changed back by writing to that register again. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-11-30 by @gfwilliams That's really odd. And this is using https://espruino.github.io/EspruinoApps/#puckrotate unmodified? What firmware version do you have on your Puck? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-12-01 by BrianH Ok, after a bunch of messing around I figured out what's been giving me trouble. In the process, I've learned a few things, but now have a bunch more questions... hehehe.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-12-01 by @gfwilliams
Yes - I think mainly it's that for the gyro to be useful everything needs to be running more quickly - so more power.
Yes - otherwise it's drawing a lot more power. Putting the accelerometer into the 12.5Hz mode helps it get much lower power consumption.
The function is using a callback for So in reality it uses Then when movement is detected it does
I think that's possible, yes. I'm not sure but it may take a while to calibrate itself - it shouldn't be long though. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-01-02 by SimonT On power usage - the gyroscopic effect requires motion, so that's why gyro is significantly higher power than accelerometer. Accelerometer is just a mass on a spring, I think MEMS gyros tend to be tuning-fork type arrangements that are induced to vibrate at a certain frequency. Therefore it's also likely there's a bit of a warm-up time, and the one-shot call will probably never return reasonable values for the gyro. @brianh - if your spindle is fixed, ie there will never be linear motion of it, and you can mount the puck so the Z axis is aligned with the spindle axis, then using purely the accelerometer might be best. In that setup it should measure gravity without any other accelerations (if it's not on the axis you'd get some centripetal acceleration mixed in). For each rotation the accelerometer value (in either x or y) will basically be a sinusoid - so you can just count a rotation each time there's a sign change from -ve to +ve in acc.x for example. No drift to worry about, power will be lower (if you manually turn off gyro via register), and I suspect maximum supported rotational speed is higher (2000 dps max scale for gyro is still "only" 5.5 full rotations per second, so with an accelerometer at 12.5Hz or above you should be able to beat that). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-01-03 by BrianH Thanks so much for the insights, @gfwilliams & @simont. Your thorough explanations are most helpful! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-10-04 by BrianH
Hi Everybody,
I've just recently begun working with the Puck.js v2 board. I updated the firmware to "espruino_2v07" immediately after powering it up. I'm starting a project hoping to count revolutions on a rotating spindle with the Puck's onboard LSM6DS3TR-C. Two questions:
Is counting revolutions this way even possible (versus using a more traditional optical encoder or magnetic sensor approach)?
When I manually execute "Puck.accel();" in the command line repeatedly (without moving the sensor at all), I get a huge range of output. Why is "Puck.accel();" returning such a variation in values?
Sometimes I'll just get a dead response and have to cycle the power to fix:
And sometimes the gyro output seems totally random (without physically moving the Puck at all):
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions