accel.filtered_xyz returns wrong values

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
scaldara
Posts: 2
Joined: Mon Nov 17, 2014 6:40 pm

accel.filtered_xyz returns wrong values

Post by scaldara » Wed Nov 19, 2014 10:02 pm

I'm a newbie so, apologies if I'm off the mark. I've been playing around with the accelerometer on PYBv1.0. I'm running Micro Python v1.3.6-26-g5694cc5 on 2014-11-17; PYBv1.0 with STM32F405RG. From the accelerometer data sheet it says that raw values are between -32 and 31. I wrote a test that prints out the filtered values. In the data below you can see how the first entry is added to generate the second, third and fourth until the length of the filter which is 4. In the code, I would have expected:

tuple = mp_obj_new_int(val);

to be something like

tuple = mp_obj_new_int(val/FILT_DEPTH);

with appropriate float/int conversions.

-steve

msec= 6901,x= 4,y= 1,z= 24
msec= 6903,x= 8,y= 2,z= 48
msec= 6904,x= 12,y= 3,z= 72
msec= 6905,x= 16,y= 4,z= 96
msec= 6906,x= 16,y= 4,z= 96
msec= 6907,x= 16,y= 4,z= 96
msec= 6908,x= 16,y= 4,z= 96

From: https://github.com/micropython/micropyt ... al/accel.c

#define NUM_AXIS (3)
#define FILT_DEPTH (4)


mp_obj_t tuple[NUM_AXIS];
for (int i = 0; i < NUM_AXIS; i++) {
self->buf[NUM_AXIS * (FILT_DEPTH - 1) + i] = MMA_AXIS_SIGNED_VALUE(data);
int32_t val = 0;
for (int j = 0; j < FILT_DEPTH; j++) {
val += self->buf[i + NUM_AXIS * j];
}
tuple = mp_obj_new_int(val);
}

return mp_obj_new_tuple(3, tuple);[/code][/code]

Post Reply