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
#29
(2022-04-10, 02:26 PM)abarrow Wrote: True wind angle has to be calculated, as on a moving vessel the speed of the vessel and the current the vessel is traveling in contribute to the wind speed and direction that is detected by your sensor.

If the sensor is stationary, apparent wind speed will be the same as true wind speed. Apparent wind will be the angle referenced to the forward position on the sensor (+/- 180 degrees). I assume that you will be pointing this reference to north. On my ultrasonic sensor, it's a little mark that I have to align with the centerline of the boat. There are ways in OpenPlotter to calculate true wind direction and speed, but they require a vessel heading and speed to create the numbers, which I'm assuming you don't have. 

Hi, do you know the formula? I have NMEA2000 data that gives me AWA AWS have heading and speed, wich to calculate TWS TWA
Reply
#30
(2022-04-10, 08:19 PM)dreeas Wrote: Thanks for taking the time to answer.
You mention I could do that in Grafana but math is not my strong side. I see 1 radian is 57.29 degrees and I could use the "math" function in the Grafana query, but not sure about the formula when negative goes from 180-360 degrees and positive from 0-180.

1 RAD = 180° / pi
Can you put in that in your formula?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)