# Acceleration without gravity

Posted on
Page
of 2
/ 2
• Hi,

Is there any good ways to get acceleration sensor data without gravity? Like it would use magnetometer to get the orientation and then remove gravity based on it? Some ready made examples.
I would like to calculate 3-4 seconds the speed the watch has and if possible, also a location/orientation.

• location will be GPS lat/lon ? It will take you at least 20 seconds to power on the GPS and get a fix and that is assuming you have downloaded AGPS data - otherwise expect 12 minutes for the first fix.

• I guess you not think of GPS but double integration of acceleration.
Be warned, that is very difficult - basically an ill posed problem for several reasons!

Main thing is that every sensor is noisy. Integration amplifies this noise, so you will have wrong speed. This will change your location all the time without bounds, even if in reality you are standing still. So after double integration you will have very big error after very short amount of time.
The only way you have a chance to get reasonable location from accelerometer is to make use of some other constraints.

That could be the Magnetometer if you operate quite close to a strong magnet, but no way to count on earth magnetic field (lots of noise from all kind of metal and fields in the environment)

Depending on what you want to do, you might think of instead make use of the gravity, since this is something that can anker you. But of course only if you can discriminate gravity and acc through some other constraints or system model (not magnetometer unfortunately).

All this is not specific to bangle but true even for much more expensive sensors.

• Yes, I'm afraid it's an almost impossible problem with only the accelerometer... A Gyro would help no end but the Bangle doesn't have one (Puck.js does).

But, one hack that might help you is you say that when you're not accelerating, gravity should be 1, and the accelerometer will be pointing towards the earth. So when that happens you know kind-of where you are. For example:

``````var Vec3 = require("Vec3");
var G = new Vec3();

Bangle.on('accel',a=>{
if (a.mag>0.98 && a.mag<1.02) {
G = new Vec3(a);
} else {
var diff = G.sub(a);
print(diff);
}
});
``````
• Yeah, I was wondering why bangle doesn't have gyro. I thought magnetometer is there for that.
Your idea is good. I'm drying to measure hand speed when you throw disk or ball, so there is time frame when there is no acceleration( I can get the gravity direction) and the throw will last 2s so I might get the right speed and maybe even hand location.

• That's interesting - you can put the accelerometer into a higher speed mode as well (check the acceleration recorder source). I would have thought for something like throwing you may well be able to at least get some values that are useful for comparison.

Because your arm will be rotating the actual velocity may be different, but it may be some more information can be gathered using the compass as well.

• I have been using "Acceleration Logger" app and it gets the data in 12.5Hz. What would be the max logger frequency (about a guess) and how I can get "higher speed mode" on?
I got some data, but it is not accurate enough or I have to analyze it more.

• Ahh, right - I was thinking of https://banglejs.com/apps/?id=accelrec but that's only available on Bangle.js 1 at the moment.

I've just fixed that and it's in the development app loader, so you can check out how it gets the higher frequency by poking the accelerometer itself - right now it runs at 100Hz but you might be able to push it higher.

• " I have just fixed that.." Where is that? I can't find any new commit on "Acceleration Recorder" or on the " Acceleration Logger" app in development branch :/

• I could swear that wasn't there for two days. I looked through all your commits and I didn't see that one. Thanks!

• It works, but it only records for 2s ( or 5 second as code says so). I need to record 30min. What if I increase sample size, like 1800 * Hz. Will my watch burn or something else? Is 256 kB ram enough?
Other option is to modify "Acceleration Logger" app and change setPollInterval to lower value. Maybe like 10 ms. Documentation mentions "max value" for this but not a minimum :D

• How's it gone from "I would like to calculate 3-4 seconds " to 30 minutes?

Increasing the buffer size is ok, but you have 6 bytes/sample - and lets say you have ~150k free RAM, that's 25000 samples, or 250 seconds at 100Hz.

If you want more, you're going to have to save to flash memory. Lots of info on how to do that at http://www.espruino.com/Data+Collection#­flash-memory - I don't see a problem writing 100Hz, but you may struggle getting it higher.

You're not going to 'burn' your watch playing with settings, but I guess you might crash it and have to long-press to restart. Have a try and see what works.

• Good to know that I can't 'burn' it :D Then I will test different thinks.

"How's it gone from..." ah yeah, sorry for that. The idea is measure now the data and explore it and see how it behaves. Then later I will make an app that shows you live how many throws you have had and speed of the throws and so one. So I don't eventually need to measure 30 min, just now to collect the data from the game. In the future app I need to have live array or list of acceleration data and then update it by adding new one and removing oldest. Then when the app measures spike on the acceleration, it can calculate all the data from the array. But first I need to explore the data. For example I was expecting do see from data, which way the hand is moving (backwards or forwards), but for some reasons I cant see that. I only see spikes on x-axis but all the spikes are negatives, so I need to explored more why. Maybe the hand just turns when there is bull forward.

But now I think I will modify the "Acceleration Logger" app and add option to change the data collection frequency, so I can see what is good enough, so when I will make the app, I know what frequency to have and it doesn't use all battery in one call :D

Thanks for the "http://www.espruino.com/Data+Collection#­flash-memory " link. This was good!

I still feel I need to order second watch, just in case my one breaks down ^^ or is there there bangle.js 3 coming with gyro ;)?

• I still feel I need to order second watch, just in case my one breaks down

Well if you want to that's great, but I wouldn't do it because you'll be worried you'll break it - they're made for this. Look at it this way - we've sold around 10,000 Bangle.js 2s, mostly to folks who spend a lot of time messing around with all kinds of things on them, and I don't believe I've had a single one returned that was broken by something done in software.

is there there bangle.js 3 coming with gyro?

Not any time soon I'm afraid, I'll be sticking with Bangle.js 2 for quite a while!

• I'm [trying] to measure hand speed when you throw disk or ball,

If I am throwing a frisbee, the actual throw probably takes place over a quarter second or less. The acceleration due to the throw could be multiple orders of magnitude greater than gravity.

I have heard quotes that a frisbee throw can involve instantaneous force vectors of 150 times the force of gravity. If you just ignore any data point where the accelerometer is reading a vector with a magnitude less than 10 Gs, and then don't even bother to account for gravity, you will probably be able to end up with less than 5-10% error overall compared to if you did account for gravity (which also might not be perfectly accurate, but that's a different problem).

On top of that, if you have a magnitude limit, you can throw for 30 minutes and end up with only like 10 seconds of actual data that you need to save.

• just a update:
tried simple trick by editing Accellog app by changing the "Bangle.setPollInterval(x)" value to 50 ms. First sample gets in around 50 ms, but rest of the values have around 100ms interval. I tried to disable layout updating, because maybe that takes too much time, but didn't help.
Maybe I need to go with accelrec app and modify it. Maybe it can't write to file so fast. I will continue to try different things.

you can throw for 30 minutes and end up with only like 10 seconds of actual data

True. Now I just want to collect data. If the writing to text file takes too much time, I can make it write only when there is a peak. Otherwise I will just update an array on the ram with new values. Lets see.

• The app does a bit more than changing just the poll interval.

The poll interval is the rate the accelerometer is checked for new data - but the accelerometer is only recording at 12.5Hz by fault anyway - it needs configuring to output data faster using `accelWr` like the app does.

• Yeah I was watching this from the accelrec, but I didn't find any documentation about the options and what to write.

``````  Bangle.accelWr(0x18,0b01110100); // off, +-8g
Bangle.accelWr(0x1B,0x03 | 0x40); // 100hz output, ODR/2 filter
Bangle.accelWr(0x18,0b11110100); // +-8g
``````

What happens in here?
First you turn 8g off?
Set the update ratio to 100 hz with 0x03? How can I set it to 50 or 30 hz?
What is ODR/2 filter. Di didn't find anything about this topic.
And then in the end you turn 8g back?

update: reading from the datapage, I can see why you have to turn the acceleration on and off and what are the update options.
But still don't understand the '(0x1B,0x03 | 0x40)' part, what happens in here?

• `0x03 | 0x40` just means an 'OR' - it's the same as writing `0x43`. It's just configuring the sensor to output at 100hz with a filter on it to stop it being too noisy (and you have to do that while the sensor is turned off).

• Ok this project is on hold, because I can't connect to my watch anymore. Have to get new one. There is no possibility to connect it by cable, is there?

• Have you tried finding the watch with one of the 'nrf Connect' apps? https://www.espruino.com/Firmware+Update­#android-ios-app

(Or toggled the different bluetooth settings, doing factory reset from the watch etc...?)

• You can't connect with the cable, no (apart from for low level debug access, which is not what you want).

But it's extremely likely you can get bluetooth to work again. Sometimes it's even just that your PC gets confused and your computer needs a restart before it'll see the Bangle again

• I did everything from other forum post: reset settings, factory reset, scan with different deices, all the bluetooth settings ok, no pass code, pinch from the corner... nothing for a 2-3 weeks. It is not the first time, I lost it, but now I think it really break.

• I got a new one. Testing is continued

• Post a reply