This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get True Wind Direction instead of apparent using Signal K.
#21
Thank you guys. I used Techstyle´s code and added the conversion using "Derived data" addon so I get the data stored correctly in Influx and don´t have to do the conversion in Grafana.

Thanks again guys for helping a noob :-)
Reply
#22
I'm not sure that formula is correct, it seems to be 180 degree wrong. Noticed when comparing to a Netatmo wind sensor.
Can you use that formula on both positive and negative radian?
Should it not be *180/pi on positive radian, and *180/pi + 360 on negative radian?

I know my lack of math knowledge shines through here but am I wrong?
If so, how can I write the conversion code to take the negative values into account?
Reply
#23
you said the output was -3.14 to +3.14. if that is the case

add 3.14 to get 0 to 6.28

the multiply by 180 --> 0 would be 0 and 6.28 would be 1130.4

then divide by PI (3.14) --> 0 would be 0 and 6.28 (1130.4) would be 360
Reply
#24
Wont that also be 180 degrees off? Since -3.14 is 180 degrees.
0 is 0 degrees true north. -3.14 is 180 degrees counterclockwise and 3.14 is 180 degrees clockwise.

In java, how can I write:

if >0 *180/pi (positive radian)
<0 *180/pi + 360 (negative radian)

If I do that I guess it should be right.
Reply
#25
(2022-04-15, 02:12 AM)dreeas Wrote: Wont that also be 180 degrees off? Since -3.14 is 180 degrees.
0 is 0 degrees true north. -3.14 is 180 degrees counterclockwise and 3.14 is 180 degrees clockwise.

In java, how can I write:

if >0 *180/pi (positive radian)
  <0 *180/pi + 360 (negative radian)

If I do that I guess it should be right.

take a look at some of the other .js files in the Calc directory of Derived data, some of them have statements like that - try SteerError - I wrote that one and it resolves the difference between bearing to a waypoint and current course in terms of Steer right and steer left
Reply
#26
Something like this?
But this code fails to start Derived data plugin so there is some error in there:

Code:
module.exports = function (app, plugin) {
   return [
     {
       group: 'wind',
       optionKey: 'directionTrueDeg',
       title: 'Stationary True Wind Direction in Degrees (based on AWA)',
       derivedFrom: ['environment.wind.angleApparent'],
       calculator: function (awa) {
         if (awa < 0) {
         let windHeadingDeg = awa * (180 / Math.PI) + 360
       } else if (awa > 0) {
         let windHeadingDeg = awa * (180 / Math.PI)
       }
       }
 
         return [{ path: 'environment.wind.directionTrueDeg', value: windHeadingDeg }]
       }    
   ]
  }
Reply
#27
Got this code to work on my installation:

Code:
module.exports = function (app) {
  return {
      group: 'wind',
      optionKey: 'directionTrueDeg',
      title: 'Stationary True Wind Direction in Degrees (based on AWA)',
      derivedFrom: ['environment.wind.angleApparent'],
      calculator: function (awa) {
        var windHeadingDeg = 0
        if (awa < 0) {
           windHeadingDeg = awa * (180 / Math.PI) + 360
        } else if (awa > 0) {
           windHeadingDeg = awa * (180 / Math.PI)
        }

        return [{ path: 'environment.wind.directionTrueDeg', value: windHeadingDeg }]
      }
  }
}
Reply
#28
I the haste to get the code working I mixed up Apparent and True angels... the proper code for getting the True Wind Direction in degrees based on True Wind Direction (in radians) should be:

Code:
module.exports = function (app) {
  return {
      group: 'wind',
      optionKey: 'directionTrueDeg',
      title: 'Stationary True Wind Direction in Degrees (based on AWA)',
      derivedFrom: ['environment.wind.angleTrueGround'],
      calculator: function (atg) {
        var windHeadingDeg = 0
        if (atg < 0) {
           windHeadingDeg = atg * (180 / Math.PI) + 360
        } else if (atg > 0) {
           windHeadingDeg = atg * (180 / Math.PI)
        }

        return [{ path: 'environment.wind.angleTrueGroundDeg', value: windHeadingDeg, units: 'deg'}]
      }
  }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)