How to determine the position of the cube?

Good day!
There is a cube inside of which is a microcontroller with sensors.
Sides of a cube are numbered from 1 to 6. When throwing the cube to determine what number fell.
There's a gyroscope and accelerometer. These sensors are enough for this task or need some more? And how can I withdraw formulas (conditions) for each side using their values?
June 27th 19 at 15:12
2 answers
June 27th 19 at 15:14
three-axis accelerometer. Gyro is not needed. Look at what axis we have the acceleration of free fall. 401911900f957f3db7cd68acab3e7fae.jpg
Suppose, on the x-axis, then if the acceleration is with the sign +, the bottom side is shaded, if-opposite to it. The accelerometer will naturally make noise and not always fall evenly, so interference is filtered quite a bit and not bothered and put the setting in the area of 8-9.
I have the accelerometer shows three values X, Y, And Z. for one side when cornering (without changing direction) the values change. It turns out, I got out of the range of these values to be the condition and all? - Hobart_Swift commented on June 27th 19 at 15:17
When the dice are calm, it operates only one acceleration - acceleration of free fall. In this case, if the accelerometer is exposed to the two axes is horizontal, the third axis will be the acceleration of free fall, in one case approximately +9.8, -9.8 in another
A cubed accelerometer(better charge - shield or self-made) as evenly as possible, so that the plane of the Board parallel to one of sides of the cube. In the drawing of a cube I would use about the same algorithm:
if 8<abs(ax+ay+az)<0 then 12 3 check stopped if the cube side="round(Ax*1/9.8)+round(Ay*2/9.8)+round(Az*3/9.8)" it'll be a face of a cube in the range from -3 to end if no< code></abs(ax+ay+az)<12>
<br / > You can simply use conditions to find the axis on which the acceleration of free fall, and depending on the axis and sign to choose a side.<br> You can filter this way:<br><pre><code>Ax=(Xinput-Ax)*dt/0.1+Ax //Xinput - value sensor, 0.1 constant time, in seconds, the more, the less the noise will be and the higher the reaction time, 0.1 close to the balance //dt is the integration step, if the signal is removed with a frequency of 100 Hz can be taken as 1/100</code></pre> - jeramie.Lesch commented on June 27th 19 at 15:20
: many thanks, I will try! - Hobart_Swift commented on June 27th 19 at 15:23
If we are to rely on physics, the body is the force of gravity, and it counteracts the force of friction. In the end, they balance each other and the body is at rest. And if so, then its acceleration is 0. - Keira commented on June 27th 19 at 15:26
well, add the word "apparent" before each "acceleration" and the text will not look so challenging. I explained to the person far from physics, the approximate principle, without clogging your head with unnecessary terms (superfluous in the context of the question). After all, if you start talking about the power, it will necessarily have to recall about the mass. Then delve into the principle of operation of accelerometers, to explain why the acceleration is not, as he sees it/feels and so on.) - jeramie.Lesch commented on June 27th 19 at 15:29
: only if you use this code, test stopped if the cube is better for acceleration derived in the current version it is easy to create a situation where the cube has not stopped, and the program did the math. However, if it works in real time and for indication only human, it's not scary - jeramie.Lesch commented on June 27th 19 at 15:32
: I have the accelerometer shows 988 is 9.8, so I wrote the formula like this:
side = round((Ax*1/988)+(Ay*2/988)+(Az*3/988));
The values from -3 to 3 is displayed. Only problem with the definition of peace. In Your formula, verify in the range of (800;1200) does not work, because the values can go in the negative. Tried the condition ((800 < x < 1200) or (-1200 < x < -800)), but it also does not determine the rest. I have no idea yet, what do You think, how can this be solved? - Hobart_Swift commented on June 27th 19 at 15:35
through derivatives:
dx=(Ax-Axprevious)/dt //dt is the time step between two measurements of the accelerometer reading, you can do without it, but then the scale of the other numbers will be
if (abs(dx)<50) then //50 - threshold acceleration at which it is considered that the cube is at rest
idlecount+=1//number of iterations of code, which acceleration has not been
end if
if idlecount>5 then //check for the rest

The code first derivative is acceleration, i.e. the change of acceleration, then we look whether it is changing acceleration. If the acceleration does not change much (the threshold is 50, which is set empirically), then the cube is at rest. If we made 5 measurements and all 5 dimensions in the cube was at rest, then execute further code.
Example is provided only to the X-axis, and the need to check all three axis.
Too low threshold does not allow to detecting a state of rest even when the cube is stationary, too high will give false positives.
The number 5 can be changed from the calculation that we need the stillness of the cube for at least 0.3 seconds. That is, if you measure the acceleration with a frequency of 100 Hz (every 1/100 of a second), instead of the 5 must be wagered 30 (30*1/100=0.3 sec). - jeramie.Lesch commented on June 27th 19 at 15:38
: great idea, thanks again! Today I will try - Hobart_Swift commented on June 27th 19 at 15:41
: made under all three axes, as You said, get everything working :) - Hobart_Swift commented on June 27th 19 at 15:44
: one last question. How You deduced this formula:

Wanted to expand to the dodecahedron, it's the principle of construction of formulas :) - Hobart_Swift commented on June 27th 19 at 15:47
: very intuitive. I know that if the accelerometer is exactly exhibited in the cube, the force of gravity will always act only along one axis of the accelerometer. If the cube is calm along other axes is 0. Then the expression round(Ax/9.8) we obtain 1, if the force of gravity is acting on the x-axis. the Sign would indicate the direction (up or down). And Damnoen on the number that would divide the axis. Two of them will still be equal to 0 (suspended), and the third will be multiplied by their number, which ultimately gives us a number from 1 to 3 with a + or-sign. In zero gravity or in free fall can be 0.
For the dodecahedron the same formula, you can display, but it will be necessary to consider the projection of the gravity axis. We can assume the angles of the accelerometer in three axes and depending on them to have to choose a side. Depending on the understanding of mathematics, in the Internet you can find different variants of implementation. And ready-made library for your MK certainly is. - jeramie.Lesch commented on June 27th 19 at 15:50
June 27th 19 at 15:16
3 coordinates of the accelerometer, each has the value of "g" or "-g" if the surface on which the cube is perfect. The resulting value will be in the range of "g/2< val < g or-g < val < -g/2" for the opposite side. val is one of the coordinates x,y,z acceleration data from the accelerometer. you can even take 1/2 and 2/3 of the maximum to more clearly separate values.
Thank you. And which sensors to add to determine even with an imperfect surface? As still an ideal is not - Hobart_Swift commented on June 27th 19 at 15:19

Find more questions by tags keyboard sensorsPhysicsAccelerometerSTM