Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some fixes and improvements #31

Merged
merged 19 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions Sail_Instrument/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ var WindPlotWidget = {
unit: "°",
history: 600,
range: 20,
aspect: 1,
quantity: "TWD",
storeKeys: {
TIME: 'nav.gps.rtime',
Expand All @@ -159,15 +160,19 @@ var WindPlotWidget = {
initFunction: function() {},
finalizeFunction: function() {},
renderCanvas: function(canvas, data) {
// console.log(data);
// console.log(data);
if(typeof(data.TIME)=="undefined") return;
let time=data.TIME.valueOf();
let tmax=data.history, n=5;

let ctx = canvas.getContext('2d');
ctx.save();
canvas.style.height='99%';
let bcr = canvas.getBoundingClientRect();
let w = bcr.width, h = bcr.height;
if(w<150){
canvas.style.height='';
h = w;
h = w*data.aspect;
}
canvas.width=w; canvas.height=h;

Expand All @@ -176,9 +181,6 @@ var WindPlotWidget = {
// console.log(data.quantity,v);
if(!valid) return;

let time=data.TIME.valueOf();
let tmax=data.history, n=5;

var hist=window.windplothist;
if(typeof(hist)=="undefined"){
window.windplothist=hist=new Map();
Expand Down Expand Up @@ -330,8 +332,8 @@ var WindPlotWidget = {
ctx.beginPath();
for (k of hist.keys()) {
let t=Math.max(0,time-k)/1000;
if(t>tmax){ continue; }
if(t>1800){ hist.delete(k); continue; }
if(t>tmax){ continue; }
let x=xc+val(hist.get(k))*dx/2;
let y=y0+t*dy/tmax;
let s = col(hist.get(k));
Expand Down Expand Up @@ -375,6 +377,10 @@ var WindPlotParams = {
type: 'NUMBER',
default: 0
},
aspect: {
type: 'NUMBER',
default: 1
},
};
avnav.api.registerWidget(WindPlotWidget, WindPlotParams);

Expand Down Expand Up @@ -498,6 +504,10 @@ var Sail_Instrument_OverlayParameter = {
type: 'NUMBER',
default: 1
},
Rings: {
type: 'BOOLEAN',
default: true
},
};

let Sail_Instrument_Overlay = {
Expand Down Expand Up @@ -541,7 +551,7 @@ let Sail_Instrument_Overlay = {
if (data.Widgetposition == 'Mapcenter') {
ctx.translate(canvas.width/2, canvas.height/2);
} else if (data.Widgetposition == 'Boatposition') {
if (typeof(data.POS) != 'undefined') {
if (typeof(data.POS) != 'undefined' && data.POS.lat!=0 && data.POS.lon!=0) {
coordinates = this.lonLatToPixel(data.POS.lon, data.POS.lat)
ctx.translate(coordinates[0], coordinates[1]);
} else {
Expand Down Expand Up @@ -570,16 +580,17 @@ function drawWindWidget(ctx,size, maprotation, data){
// console.log("wind widget",data);
if (typeof(maprotation) == 'undefined') { return; }
var vmin = typeof(data.VMIN) == 'undefined' ? 0 : data.VMIN;
DrawKompassring(ctx, size, maprotation);
var rings = typeof(data.Rings) == 'undefined' ? true : data.Rings;
if(rings) DrawKompassring(ctx, size, maprotation);
if (data.HDT>=0) {
DrawOuterRing(ctx, size, maprotation + data.HDT);
if(rings) DrawOuterRing(ctx, size, maprotation + data.HDT);
} else {
return; // cannot draw anything w/o HDT
}
if (knots(data.DFTF)>=vmin && data.SETF>=0) {
drawTideArrow(ctx, size, maprotation + data.SETF , "teal", knots(data.DFTF).toFixed(1));
}
if (knots(data.TWSF)>=1) {
if (knots(data.TWSF)>=1 && rings) {
if(data.POLAR){
drawPolar(ctx,size,maprotation,data,"black");
}
Expand All @@ -599,14 +610,16 @@ function drawWindWidget(ctx,size, maprotation, data){
if (knots(data.TWSF)>=1) {
DrawWindpfeilIcon(ctx, size, maprotation + data.TWDF, blue, data.HDT==data.COG ? 'G' : 'T');
}
if (data.BRG>=0) {
DrawWPIcon(ctx, size, maprotation + data.BRG);
}
if (knots(data.SOG)>=vmin && data.COG>=0) {
DrawEierUhr(ctx, size, maprotation + data.COG, orange);
}
if (data.HDT>=0) {
DrawCourseBox(ctx, size, maprotation + data.HDT, black, Math.round(data.HDT));
if(rings) {
if (data.BRG>=0) {
DrawWPIcon(ctx, size, maprotation + data.BRG);
}
if (knots(data.SOG)>=vmin && data.COG>=0) {
DrawEierUhr(ctx, size, maprotation + data.COG, orange);
}
if (data.HDT>=0) {
DrawCourseBox(ctx, size, maprotation + data.HDT, black, Math.round(data.HDT));
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions Sail_Instrument/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
except:
pass

PLUGIN_VERSION = 20240731
PLUGIN_VERSION = 20240911
SOURCE = "Sail_Instrument"
MIN_AVNAV_VERSION = 20230705
KNOTS = 1.94384 # knots per m/s
Expand Down Expand Up @@ -361,7 +361,7 @@ def writeValue(self, data, key, path):
return
a = self.api.getSingleValue(path, includeInfo=True)
if a is None or SOURCE in a.source:
self.api.addData(path, data[key])
self.api.addData(path, data[key], source=SOURCE)

def mag_variation(self, lat, lon):
if not self.variation_model:
Expand Down Expand Up @@ -497,8 +497,8 @@ def run(self):
calculated -= present

data.VMIN = self.config[VMIN]
for k in ("COG","SOG","HDT","STW"):
if data.misses(k): data[k] = -1 # explicitly mark as undefined
# for k in ("COG","SOG","HDT","STW"):
# if data.misses(k): data[k] = -1 # explicitly mark as undefined, workaround for https://github.com/wellenvogel/avnav/issues/347

for k in data.keys():
# print(f"{PATH_PREFIX + k}={data[k]}")
Expand Down Expand Up @@ -572,6 +572,8 @@ def laylines(self, data):
self.msg += ", laylines from table"

data.VPOL = self.polar.value(twa, tws * KNOTS) * MPS
if data.has("VPOL","STW"):
data.VPP = data.STW/data.VPOL*100
self.msg += ", calculate VPOL"

if self.config[SHOW_POLAR]:
Expand Down Expand Up @@ -867,8 +869,6 @@ def angle(self, a):

def to360(a):
"limit a to [0,360)"
while a < 0:
a += 360
return a % 360


Expand Down
14 changes: 13 additions & 1 deletion docs/3-Calculated-Data.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,19 @@ This equation corresponds to the triangle/parallelogram on the right side of the

### Wind

In general, angles (xxA, relative to heading) and directions (xxD rel. to true north) are always converted by adding/subtracting true heading HDT.
- AWS = Apparent Wind Speed = wind speed relativ to boat, measured by the wind sensor
- AWA = Apparent Wind Angle = angle between the direction of apparent wind (where it comes from) and direction the bow is pointing to (heading), measured by the wind sensor
- AWD = Apparent Wind Direction = direction of the wind relative to true north (usually not used)
- TWS = True Wind Speed = wind speed relative to the surface of the water, true wind is calculated from apparent wind, heading, waterspeed (and leeway)
- TWA = True Wind Angle = angle between the direction of the true wind and heading
- TWD = True Wind Direction = direction of the true wind relative to true north
- GWS = Ground Wind Speed = wind speed relative to the ground, ground wind is calculated from apparent wind, heading, course and speed over ground, in the weather forecast
- GWA = Ground Wind Angle = angle between the direction of the ground wind and heading (usually not used)
- GWD = Ground Wind Direction = direction of the ground wind relative to true north, in the weather forecast

In general, angles (xxA, relative to heading) and directions (xxD rel. to true north) are always converted by adding/subtracting true heading HDT.

$$ xxD = xxA + HDT, xxA = xxD - HDT $$

True wind, which is the wind vector relative to water, can be obtained from apparent wind measured by the wind meter (direction and speed) and water speed. To get the angle right, leeway also enters the equation.

Expand Down
85 changes: 69 additions & 16 deletions docs/Images/vectors.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.