Stormworks - Measure angle for Pitch/Roll of your vehicle. Simple circuit guide.
Measure the angle for pitch/roll of your vehicle.
Ever wondered how to measure the roll of your vehicle or detect if it flipped ? It's simple by using two Altimeters!
If you want you can leave a comment with feedback or suggestions for further guides!
Table of contents
Setup:
As a setup place one altimeter inline with the rotational axis. If we want to measure the roll of the vehicle - let's take an aircraft as an example - we would place one altimeter between the wings and one other altimeter on either the left or the right side of it in line. Important is that the altimeters (when there is no roll / pitch) are on the same height. A simplified schematic build:
This setup simulates the vehicles rotation (roll or pitch) at the pivot. Sidenote: the rotation axis is in most cases around the center of mass or a mechanical pivot - for planes and the such it is usually the center of mass and if it's not it's usually a good enough approximation.
The Calculation:
In order to do the calculation we will need a microcontroller. If you don't want to go into the math no problem just skip this section.
So what do we need to calculate ? Unit circle !
(Source: https://en.wikipedia.org/wiki/Unit_circle#/media/File:Unit_circle.svg)
What we can see above is a circle with the radius of 1. This makes the calculations a bit easier and let's assume our altimeters are exactly 1 meter apart (that would be 3 blocks between them). t is the angle between the x axis and the line and that's what we want if we assume the altimeter on the rotation axis is in the middle of the circle and the tip of the line is our other altimeter (we will discuss what to do if that's not exactly the case).
As we can see in the drawing, the y coordinate of the lines endpoint is sin(t). In this case sin(t) is the height difference between the two altimeters. In order to get the angle we need asin(y).
Additionally we need to 'norm' the height difference between our altimeters. We do that by dividing the height difference by the real distance of our altimeters.
Microcontroller
Hint: Scroll down after the pictures for a quick explanation.
The microcontroller will need 2 number inputs (the heights they measure) and one number output which will be the angle:
So first we need to compute the difference in height:
Next we will 'norm' the height difference by dividing it by the distance the altimeters are apart. We acquire the distance by a property because in most cases the distance will be constant if not just add a number input to the microcontroller.
The conversations are listed in the tooltip of the function interface. To convert from radians to degree: x * (180/pi)
In short:
- Subtract the height of the outer altimeter by the height of the one in the middle
- Divide this value by the distance between the altimeters (in meters !!)
- Apply the "asin" function on that value ("asin(x)").
- If you want convert the radian value to degrees by using this formula "x * (180 / pi").
And there we are we are done.
There is a bit more
If we want to have the altimeters on either side of the plane / helicopter / boat /... we can achieve this by dividing the height difference by 2 IF the two altimeters have the same distance to the rotational axis.
Troubleshooting
Problem: I'm getting inverted values to what I have expected.
Solution: Just invert the end result by multipling to by -1
Problem: My values are wrong.
Solution: Try the distance between the altimeters. Take the amount of blocks between the altimeters add one and multiply it by 0.25 (the length of a single block).






Comments
Post a Comment