Share My Creation Wind Compass - With Animation

Hi All

I made this handy wind compass using (at Erels suggestion) two images one for the compass card (scale) which is fixed and one for the compass pointer which is the moving part.

I tried using iVpointer.SetRotationAnimated, but of course animation for a circle doesn't work very well because the pointer takes the long-way-round when you are in the upper half of the compass. This is because the animation is probably done by a timer tick and a first order difference equation. Operating only on the angle means that if the wind is blowing from the NE and its swings to the NW the angle change is from 45 degrees to 315 degrees so the difference equation takes a path from 45 to 315 via the 180 degree path not the 45 - 360 - 315 path.

To fix this you have to convert from polar to Cartesian using sin and cos, filter the x and y values with separate difference equations then find the atan2 of the resulting vectors to get back to polar where the hypotenuse is construed as 1 and the angle is the angle from the x axis as per mathematical convention. Of course you make the x axis vertical in a compass as the convention is north pointing up

You have to do the same thing if you want to take the average wind direction or the wind direction weighted by the wind speed; sometimes called the vector wind direction.

The program I have written allows setting of the filter time constant, the initial angle and a switch to enable or disable the animation (filter) I put the switch in so that the animation timer can be turned off if the compass rose is not visible or enabled so that computer time isn't wasted by unused updates. (That's my embedded culture talking)

It would be simple to make the scale rotate and the pointer to remain stationary without much modification. This would be more like what a ships compass dooes with the indicator line remaining stationary and the scale moving relative to it.

I would like to be able to choose the images for the compass scale and pointer and to change the color of the pointed with say changes in wind speed, but I couldn't get this to work, because it seems you cannot change the image of a b4x custom image.


I hope this is useful.


Best regards

Rob
 

Attachments

  • WindCompassClassV1.zip
    138.8 KB · Views: 351
  • CompassMovie.zip
    301.2 KB · Views: 386

Beja

Expert
Licensed User
Longtime User

Hi Rob
Thanks for this and until I am able to test it I would like to ask a question:
Are you using a wind sensor connected somehow to the PC? (wind speed sensor + wind direction sensor)?
In other words, how are you getting the wind data?.. just wondering!
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…