Measuring speed with inertial sensor?

Is it possible to get speed readings using the accelerometer in the inertial sensor, if so how?

Itll be along the lines of:

double xspeed = 0;
double yspeed = 0;
double zspeed = 0;
while (true) {
xspeed += xacceleration;
yspeed += yacceleration;
zspeed += zacceleration;
vex::task::sleep(20);
}

Dont know how to get acceleration from inertial sensor but likely can be found from the vexcode api. In addition, this code likely will only work if the robot is not turning. You may need to add calculus knowledge to get speed based upon world space as well. Also, I may not garuntee it’ll be consistent.

ok, that helps, (btw im a builder not a programer so everything I say might be wrong) only problem I can think about is what if the robot is traveling in a diagonal, increasing both x and y. Would the speed still be as accurate as traveling in just x?

@jpearman Do you know if the acceleration for the internal sensor is based upon relative space or world space?

1 Like

The IMU provides acceleration values in all 3 dimensions. If one has some form of holomnic drive that can strafe, the IMU can provide the acceleration vector along that axis.

I believe James has indicated in previous threads that solely using the IMU to calculate position (and therefore velocity) is unlikely to be possible/accurate.

I believe when you request the x-axis acceleration from the IMU, the x-axis is always oriented based on the IMU’s orientation (with the fancy stuff it does at initialization where it determines which axis is returning the effects of gravity). Thus, if you were to accelerate and read the the x-axis value (lets say you get 1). Stop. Turn 90 degress. Accelerate again (as you did the first time) and read the x-axis value, you would also get 1 and not 0.

5 Likes

wow thats fancy, thanks for the info

2 Likes