Reading an accelerometer in Python
In this section, we will learn how to use an accelerometer to measure forces acting on the robot, and most often, which way is down. Let's find out more about it, then write some code to see how it works.
Understanding the accelerometer
An accelerometer measures acceleration or changes in speed, both in terms of size and direction. It does so by providing three values – one for each of the X, Y, and Z axes:
The preceding diagram shows a conceptual view of an accelerometer. Let's take a look at it in more detail:
- This shows a ball (a mass) suspended by six springs in a box. When there are no forces on the box, the ball stays in the middle.
- This shows how this system behaves when the large arrow pushes it. The mass retains inertia by moving to the right, compressing the right spring and extending the left spring. ...