SignalK / signalk-java

Installer and web-app for the artemis-server (a java based Signal K master server)
Apache License 2.0
6 stars 6 forks source link

Vessel rotation in freeboard-sk not correct #19

Open rob42 opened 5 years ago

rob42 commented 5 years ago

I get the strange vessel rotation in freeboard-sk when running plaka.nmea as demo file.

COG true is 208 (about right), COG magnetic is 293deg, about where the vessel is pointing when set to magnetic in settings. When set to true its 0deg, I assume its not getting a heading, maybe its listening for a value artemis doesnt send?. Anyway, both are wrong, the magnetic one by 90deg clockwise, which I have seen long ago. Its a common error when converting geo headings to computer graphics.

rob42 commented 5 years ago

From AdrianP: the boat icon will be rotated based on the following in order of precedence : using either the True or Magnetic values (based on preference set in config) of headingTrue or headingMagnetic or if not available cogTrue or cogMagnetic. If preference is magnetic and these values are not available it will not default to True values and vice versa

rob42 commented 5 years ago

Confirming NMEA conversion in artemis is producing correct values in rads. Both create a heading around 205deg, which is roughly correct allowing for declination diff (about 7deg)

rob42 commented 5 years ago

Found it I think. All data in artemis is persisted to the influxdb, the most recent is recovered by a query that selects the newest record. So we have this in the db:

> select * from vessels where skey=~/navigation.course/ order by time desc limit 2
name: vessels                                                                                                                                                                                                                                
time                doubleValue         skey                                                             uuid                                                                  
----                -----------         ----                                                             ----                                                                  
1553630687688000000 1.7482963121219077  navigation.courseOverGroundTrue.values.NMEA0183.SERIAL.value     urn:mrn:signalk:uuid:5da2f032-fc33-43f0-bc24-935bf55a17d1             
1553630687688000000 1.7482963121219077  navigation.courseOverGroundMagnetic.values.NMEA0183.SERIAL.value urn:mrn:signalk:uuid:5da2f032-fc33-43f0-bc24-935bf55a17d1             

> select * from vessels where skey=~/navigation.head/ order by time desc limit 2
name: vessels                                                                                                                                                                                                                                
time                doubleValue  skey                                                           uuid
----                -----------  ----                                                           ----
1544238574813000000 4.57         navigation.headingMagnetic.values./dev/ttyACM3.pesky.IMU.value urn:mrn:signalk:uuid:a8fb07c0-1ffd-4663-899c-f16c2baf8270
1544238574277000000 4.57         navigation.headingMagnetic.values./dev/ttyACM3.pesky.IMU.value urn:mrn:signalk:uuid:a8fb07c0-1ffd-4663-899c-f16c2baf8270

> select * from vessels where skey=~/navigation.mag/ order by time desc limit 2
name: vessels
time                 longValue      skey                                           uuid
----                 ---------      ----                                           ----
1551841382225000000  1551841382225  navigation.magneticVariationAgeOfService.value urn:mrn:signalk:uuid:5da2f032-fc33-43f0-bc24-935bf55a17d1
1551841382225000000 0.148605  navigation.magneticVariation.value             urn:mrn:signalk:uuid:5da2f032-fc33-43f0-bc24-935bf55a17d1                                                     

Bit hard to read, but there are two vessels in there (a different demo file was used earlier) so the 'newest, headingMagnetic value is from the other vessel. Same for declination. So when I set freeboard-sk to use magnetic, its picking up the other vessel, which is 4.57rad + 0.14rad declination, eg ~293 deg.

Given there is no courseOverGroundTrue for the other vessel it seems that freeboard-sk is getting the heading data for the other vessel, hence no courseOverGroundTrue, so the vessel show 0deg.

rob42 commented 5 years ago

Seems the queries are selecting the correct vessel (self=urn:mrn:signalk:uuid:5da2f032-fc33-43f0-bc24-935bf55a17d1), but there is historic data from some time ago:

time                doubleValue skey                                                           uuid
----                ----------- ----                                                           ----
1531689537105000000 5.12        navigation.headingMagnetic.values./dev/ttyACM3.pesky.IMU.value urn:mrn:signalk:uuid:5da2f032-fc33-43f0-bc24-935bf55a17d1
1531689536612000000 5.12        navigation.headingMagnetic.values./dev/ttyACM3.pesky.IMU.value urn:mrn:signalk:uuid:5da2f032-fc33-43f0-bc24-935bf55a17d1

Again it translates to ~302deg,...

The db is my dev db - full of accumulated rubbish...time to clear it

rob42 commented 5 years ago

Same effect, but without the history issues. freeboard-sk only allows selection of 'True' now as there is no longer any navigation.heading* keys in history.

Tried NeutronDance.log as demo source - also same effect, but found and fixed parsing error noted by @RBerliner

rob42 commented 5 years ago

Huh...history is working too well...

When I run the demo file, then stop and restart the demo file (with NMEA0183 in this case) the RMC sentence (lat/lon) contains a timestamp, hence is converted to the signalk timestamp. So the navigation.position overwrites the position at that time (in the past). But COG doesnt have a timestamp, so it gets the current time.

Remember influx gets the latest timestamp for a given key.

When you run the demo the second time the boat position is the same as it was when the last run ended (eg the position with the highest timestamp). The COG etc works as expected. Eventually your demo catches up to the current position, and suddenly the boat moves on...

The demo data format or importing will need to be adjusted to bring sanity. Separate issue created

20