Visualizzazione post con etichetta nmea. Mostra tutti i post
Visualizzazione post con etichetta nmea. Mostra tutti i post

giovedì 16 giugno 2022

Sailboat Polar Chart Builder helps you to create polar diagram for your sailboat

First of all , sorry for my bad english ... 

The boats are very different from each other, as are the styles of the captains who lead them: there is the loner, the regatta man and who enjoy the journey without considering speed at all. This does not mean that having a reference, and therefore a diagram of how our boat proceeds according to the weather conditions, allows us to better plan our routes with more safety.

What I propose is the use of a free software Sailboat Polar Chart Builder very easy to use which, with the help of your onboard GPS (or Water sensor if present) and your wind station, will record the boat's performance for you and compile a file with the polar of the boat (CSV) to be used in other planning software or you can print your polar chart to always have it at hand.

At the moment the software is released in BETA version completely free of charge and therefore all your feedback is more than appreciated.





note: The data displayed in the image are not true as they are obtained from a simulation.


How does it work.

Sailboat Polar Chart Builder collect the data coming from a connection (TCP) on which the NMEA messages travel by taking the important ones in order to plot the polar chart which are:

WIMWV - this type of message contains the intensity and direction of the wind data relative to boat.

GPRMC - the message contains data relating to speed and position of the boat.

What you need to do is connect to a TCP server that can provide such data (for example an outgoing connection from OpenCPN) and begin collecting data from the boat for a long enough period to be able to have the amount of information necessary to create a detailed polar chart of the boat.

Requirements

At the moment the software has been tested to work only on the Windows 10/11 operating system and does not require any particular performance from the PC.
In the future, a Mobile App could be created that does the same job but more affordable for everyone.

Tutorial. How to use.

The first thing to do is to have software that provides wind and gps data, in this tutorial we will use OpenCPN.
First of all, let's create an outgoing connection from OpenCPN where we will publish all the NMEA messages and therefore also the messages coming from our wind and GPS station:


It is important to enter the IP 0.0.0.0 in the network address which indicates to openCPN that it must be a Server to which our software will have to connect.

Once this is done we can start our software and configure the connection to our server:

In box 1 shown in the image above we must put the IP address of our server (e.g. where OpenCPN resides), if our software runs on the same machine we can write localhost and in the Port Number field we will put the same port number used by the our server (eg 10112) at this point we can click on the Connect button which, if all goes well, will change its wording to Disconnect (see first image). We are now ready to receive the data we need.

Box 2 of the image above shows the section where the acquisition of data arriving from the instruments is managed.
First of all we choose the interval with which these data are collected, too small interval can collect data too quickly respect to variations of navigation conditions, a good compromise is to set 60 to 120 seconds as an interval for each acquisition, if you provide for long periods of navigation this value can also be set much higher.
Once the interval has been set, we can press the START button to start the acquisition and if everything works as it should, the "Number of measures" counter should begin to increase its value. It is important that the acquisitions are stopped when you intend to moor, anchor or in general not to use the sails of the boat.

Also from box 2 it is possible, through the SAVE, LOAD and RESET buttons, respectively
save the "raw" data acquired on a file and then resume the measurements at another time,
load the previously saved acquisitions to be able to integrate them with the new ones arriving from the server,
reset and then delete all the acquired data that the software keeps in memory.

When we have a considerable number of data: that is, when we have acquired data of the boat in all speeds and for different wind intensities we can proceed (in box 3 of the image) to the data analysis to build our graph and our file csv with polars.

We first proceed in choosing the intervals between one wind speed and another and immediately afterwards it is possible to generate the graph through the CALCULATE button.

Here you have 2 possible choices:
print the graph obtained through the PRINT button
or create the file with the polars in CSV format that you can use with your planning software: one above all qtVlm.
Before using the file it is necessary to look at its content, if inside there are values marked as null then it will be necessary to integrate by making other detections or alternatively add manually the missing values.


04/01/23 New release

In addition to fixing some bugs, here are some of the new features:

- It is now possible to expand the application to full screen with the consequent enlargement of the polar graph for better consultation.

- Texts have been introduced that describe the connection/disconnection and data acquisition status more clearly.


Installation

Download the software from this link:

Those who do not have a DropBox account can still download the file by clicking at the top left on DOWNLOAD always on the link page above.

Unzip compressed file into a folder with everything you need to run the software inside.

Run the PolarChartGUI.exe file.

For any info / help or bug report you can contact me on the email alemassimo[@]yahoo.it ( remove [ ])


Fair wind!

martedì 2 febbraio 2021

Pilota a barra per barca con nodemcu

Piccolo progetto sviluppato durante il periodo di lockdown di questo maledettissimo 2020.


Di cosa si tratta: avevo un vecchio pilota automatico a barra (autohelm 800) per la mia piccola barchetta a vela che ormai non funzionava più e le uniche parti recuperabili erano l'involucro, la pulsantiera e il motorino con attuatore lineare, mi sono detto " e se rimpiazzo tutta la logica con una scheda arduino compatibile?", da questa semplice domanda ho fatto la lista della spesa cercando di riciclare quello che avevo già in casa ( cioè una schedina nodemcu con wifi e il modulo di controllo L298N per motori in cc), quindi ricapitolando :

- scheda di sviluppo open source ESP8266 NodeMCU
- ponte H L298N per pilotare il motore 
- motore cc già presente originale
- pulsantiera già presente originale

Mi sono orientato su questa funzionalità:
ricevere i dati nmea del navigatore attraverso il collegamento wifi su protocollo UDP della scheda nodemcu e utilizzare questi dati per pilotare il braccio dell'autopilota. Risultato PERFETTO! 

Ma vediamo i dettagli cominciando dall'hardware :
Come già detto del vecchio autohelm 800 ho riutilizzato il motore (in corrente continua), l'involucro plastico e la pulsantiera provvista di un led rosso molto comodo.

Mi sono studiato la pulsantiera e sono riuscito a mappare i collegamenti di ogni pulsante, attraverso l'uso di una breadboard ho testato il funzionamento mediante l'uso di una libreria per arduino scritta appositamente per tale scopo, trovate i dettagli a questo indirizzo Keypad library .

Qui di seguito lo schema elettrico della pulsantiera e di come è stata connessa alla scheda nodemcu:

Adesso passiamo al circuito per pilotare il motore in cc. Per tale scopo ho utilizzato un  ponte H ed esattamente il circuito L298N che oltre a fornire la componentistica per pilotare il motore ha anche una uscita da +5v ( pilotandolo con i 12v della batteria)  da utilizzare per alimentare la piccola scheda nodemcu.
I collegamenti sono molto semplici : il negativo della batteria è comune sia al L298N che alla scheda di controllo nodemcu, mentre l'alimentazione di quest'ultima viene prelevata dall'uscita da 5v del ponte H ( L298N).
A questi collegamenti vanno aggiunti quelli di controllo ( pin 1 e 2 ) che asseconda che essi sia in stato alto ( +5 v) o basso ( 0 v) determinano il senso di rotazione del motore secondo questo schema:

1 basso , 2 alto -> senso orario
1 alto , 2 basso -> senso antiorario
1 basso, 2 basso -> motore fermo 

A questo punto i collegamenti sono finiti e non resta che studiare bene come inscatolare il tutto.


Adesso passiamo al software:
Per un risultato ottimale quello che serve è un algoritmo basato sul controllo Proporzionale-Integrale-Derivativo, tale algoritmo consente un pilotaggio privo di oscillazioni e permette di effettuare le giuste correzioni di rotta.
L'algoritmo PID meriterebbe un post apposito per la piena comprensione ( perchè no ...).

Ma vediamo sia lo pseudo codice che il codice effettivo poi sviluppato per il nostro autopilota:

previous_error = 0
 integral = 0 
 start:
   error = setpoint - measured_value
   integral = integral + error*dt
   derivative = (error - previous_error)/dt
   output = Kp*error + Ki*integral + Kd*derivative
   previous_error = error
   wait(dt)
   goto start

I parametri fondamentali da settare sono Kp ( azione proporzionale), Kd ( azione derivativa)  e Ki (azione integrale).

Dopo diverse prove i valori che più hanno soddisfatto le mie attese sono stati questi :

float DT = 500;

float KP = 1.2;

float KI = KP/DT * 0.8;

float KD = KP*DT * 100;

dove DT è l'intervallo di tempo (millisecondi) tra una azione compensativa e l'altra.

Quello che segue è l'implementazione del pseudocodice appena visto adattato allo specifico utilizzo sull'autopilota a barra:


void calculateTargetMotorPosition()
{
  
  float headingDiff = targetHeading - Heading;
  if ( headingDiff > 180 ) headingDiff -= 360;
  if ( headingDiff < -180 ) headingDiff += 360;
  
  Error = Error + (headingDiff * DT);
  if ( Error > MaxError) Error = MaxError;
  if ( Error < MinError) Error = MinError;
  
  //Compute error derivative
  ErrorDer = (headingDiff - prevError)/DT;
  prevError = headingDiff;

  //Compute correction 
  Correction = KP * headingDiff;
  Correction += KD * ErrorDer;
  Correction += KI * Error ;
  if ( abs(Correction) > MaxCorrection) Correction = MaxCorrection;

  if ( abs(Correction) > MinCorrection ) moveMotor(abs(Correction), Correction > 0);
}

Il codice completo è disponibile a questo indirizzo: https://www.dropbox.com/s/5554l3br1wuzzof/AutopilotaPID.ino?dl=0

E' importante ricordarsi di configurare correttamente la connessione all hotspot Wifi della barca o del plotter nell'apposita sezione ( linee 12 e 13 del codice):

//WiFi Config

#define WIFI_SSID  "wifiSSIDName" 

#define WIFI_PASS "WifiPassword"


e configurare il plotter in modo tale che i dati relativi alla rotta da seguire e alla posizionje (gps) siano correttamente trasmessi all'autopilota sulla porta 10112 ( modificabile) su protocollo UDP :

unsigned int UDPPort = 10112;

In questo post potete trovare le informazioni per configurare OpenCPN  in modo tale da inviare le informazioni necessarie all'autopilota per poter funzionare. In particolare i messaggi NMEA che servono al pilota per funzionare sono ECAPB per l'ottenimento della rotta da seguire e ECRMC per acquisire quella che è la direzione attuale della barca (COG) .

Per chi non lo sapesse OpenCPN è un software open source disponibile per diversi sistemi operativi.  Questo software è in grado di trasformare un computer ( PC o mini computer come Raspberry) in un sistema cartografico.

Ma come funziona una volta programmato e montato ? 

Molto semplice: appena acceso l'autopilota può essere mosso attraverso i tasti +10 +1 -10 -1 della pulsantiera che muovono il braccio in maniera proporzionale al numero premuto.

In questa modalità la barra rimarrà ferma e il pilotaggio sarà totalmente manuale.

Per attivare il pilota automatico bisognerà premere il tasto AUTO ( rosso ), solo a questo punto il pilota automatico proverà a connettersi alla rete wifi, precedentemente configurata, e, se tutto funziona a dovere, comincerà a ricevere i dati di navigazione dal plotter, l'intermittenza del led confermerà che questo stia accadendo.

Il progetto è notevolmente migliorabile e sicuramente può essere arricchito di tante funzionalità ...

Aspetto i vostri feedback.