Arduino windvane self steering.

Friction is a big issue in a wind angle sensor, optical or magnetic sensors are often preferred. Making it cheap and waterproof is not trivial.
Your horizontally pivoted vane might have enough force to use a simple potentiometer?
A potentiometer was the initial thought, but with limited programming skills i am not aware how it can drive the motor CW, or CCW were with the rotary encoder its more obvious.
 
I would definitely recommend starting with fixed error = fixed rudder position. This gives you only one variable to tune (the ratio). You may find you need a control loop on the motor to drive to the correct position, do you have a rudder angle sensor?
Could you explain the "fixed error = fixed rudder position" a little more?
I don't have a rudder sensor.
 
Control systems like this can be extremely complex to program and even harder to get all the parameters correct; there's a lot of non-linear feedback going on! It's a research topic in itself. And when you start to take into account periodic forces such as wave interaction with vane, heading and rudder forces, gust response and so on, it gets even more complex. It's all doable, but expect to a) need algorithms that can handle all the inputs and b) have a lot of tuneable parameters. And even then, expect it to do odd things from time to time!
The purpose of the "device" is only to simulate a real mechanical wind vane system taking wind direction as the only data input. But even to achieve only this might be very complicated as you say. I am not aware if the mechanical wind vane steering, interacts with the rudder forces, or it is just one-way "data" - from the vane to rudder. My reasonιng says that only the vane should move the rudder and not the opposite?
 
Could you explain the "fixed error = fixed rudder position" a little more?
I don't have a rudder sensor.

Once you know how far off the desired heading you are (the 'error'), you have to decide what to do with this information in terms of steering the boat. You could for example have a very simple system where any error to one side results in driving the wheel/tiller at maximum force in the relevant direction. Of course this will result in full force being applied at all times so is not efficient (or effective). You could use proportional control, so as error increases the applied force increases. The problem with this is best illustrated with an example. Imagine the bow is pushed some angle to leeward by a wave. There is a large error so a large force is applied to the tiller. The tiller starts to move and the boat starts to round up. The error will therefore start to reduce, but will continue to be on the same side. Thus the force applied to the tiller will start to reduce, but will still be in the same direction. Thus the rudder angle will continue to increase until you return to the correct heading at which point the applied force will be zero. Unfortunately you will now be on the correct heading, but with the rudder hard over, and so you will continue turning onto the other side. And so on forever.

A much better solution is to have proportional control between input error and rudder angle. Thus as the boat returns to the correct course the rudder will return to the centreline. Mechanical windvane systems use a differential to achieve this result. If you don't have a rudder angle sensor you could probably get close by measuring the integral of applied force over time. This assumes a stiff system where there is little backdriving.

The problem with a proportional control system is that if there is some continuous bias (in this case weather helm) then you need a constant force applied to the helm. This force will only be applied if there is an input error, so you will reach a steady state that is slightly off your desired course. PID control avoids this, at the expense of being harder to tune. An alternative is a length of bungy cord between tiller and cockpit coaming.
 
The purpose of the "device" is only to simulate a real mechanical wind vane system taking wind direction as the only data input. But even to achieve only this might be very complicated as you say. I am not aware if the mechanical wind vane steering, interacts with the rudder forces, or it is just one-way "data" - from the vane to rudder. My reasonιng says that only the vane should move the rudder and not the opposite?
I have no practical experience, but the linkages I've seen portrayed would certainly allow feedback from the rudder - no worm drives or similar to stop feedback forces. Whether they're significant is beyond me, but most people describe windvanes as tracking the motion of the boat over waves. On my own boat such forces could be significant - she is well balanced, but the tiller loads up quickly when she heels beyond a certain point, so she rounds up when a gust hits her.
 
I have no practical experience, but the linkages I've seen portrayed would certainly allow feedback from the rudder - no worm drives or similar to stop feedback forces. Whether they're significant is beyond me, but most people describe windvanes as tracking the motion of the boat over waves. On my own boat such forces could be significant - she is well balanced, but the tiller loads up quickly when she heels beyond a certain point, so she rounds up when a gust hits her.

The tiller can definitely move the servo rudder, but in doing so will also rotate it (due to the design of the linkage). This rotation will act to try to return the servo and rudder to their original position (though if the force persists it will return to a position with a slight offset). The size of this offset and the rapidity of reaching steady state will depend on the 'power' of the system, in practice it may not even be noticeable.
 
Once you know how far off the desired heading you are (the 'error'), you have to decide what to do with this information in terms of steering the boat. You could for example have a very simple system where any error to one side results in driving the wheel/tiller at maximum force in the relevant direction. Of course this will result in full force being applied at all times so is not efficient (or effective). You could use proportional control, so as error increases the applied force increases. The problem with this is best illustrated with an example. Imagine the bow is pushed some angle to leeward by a wave. There is a large error so a large force is applied to the tiller. The tiller starts to move and the boat starts to round up. The error will therefore start to reduce, but will continue to be on the same side. Thus the force applied to the tiller will start to reduce, but will still be in the same direction. Thus the rudder angle will continue to increase until you return to the correct heading at which point the applied force will be zero. Unfortunately you will now be on the correct heading, but with the rudder hard over, and so you will continue turning onto the other side. And so on forever.

A much better solution is to have proportional control between input error and rudder angle. Thus as the boat returns to the correct course the rudder will return to the centreline. Mechanical windvane systems use a differential to achieve this result. If you don't have a rudder angle sensor you could probably get close by measuring the integral of applied force over time. This assumes a stiff system where there is little backdriving.

The problem with a proportional control system is that if there is some continuous bias (in this case weather helm) then you need a constant force applied to the helm. This force will only be applied if there is an input error, so you will reach a steady state that is slightly off your desired course. PID control avoids this, at the expense of being harder to tune. An alternative is a length of bungy cord between tiller and cockpit coaming.

Great explanation. It's getting more complicated as things get more clear!
Can't we assume the vane, (whether horizontal or vertical) might work as the unique sensor that gives the error? A very basic algorithm could be like that:

1) Let's say we set the boat at beam reach with the wind coming from the 90 degrees. The vane is pointing the wind ( let's say its a horizontal vane) and the rudder is at the center, maybe with some kind of break keeping it there. This is the zero setting of whatever sensor is connected to the vane. ( rotary encoder? ) .

2) Suddenly the wind comes from the 45 degrees. The encoder, which was at its 0 position in 90 degrees wind direction, will now give a -45 reading so it must turn the rudder left. The question is how much it will turn it and for how long, before reversing the rudder motor so that when it returns at the center we'll be at the correct heading ( 90 degrees to wind)

3) Trying to simulate a helmsman, the process would continue as such: turn the rudder left 10 degrees -e.g our motor needs 5 revs and 5 seconds- so run the motor for 5 seconds and stop it at that position.


4) Now the hard part...The boat starts to turn left and the relative angle of the windvane starts to increase again -45, -40, -35... The rudder should start correcting and when the vane reads 0, it should be at the center...oh...that's really hard!
 
4) Now the hard part...The boat starts to turn left and the relative angle of the windvane starts to increase again -45, -40, -35... The rudder should start correcting and when the vane reads 0, it should be at the center...oh...that's really hard!
That's what a PID controller will do, when correctly tuned. It will need a lot of testing and adjustment but the principle is straightforward: There's some output because there is an error - the Proportional part; there' another contribution because there has been an error the Integral part; and there's a further addition because the error is changing (Differential).

If I was trying to do this (I prefer to leave it to Raymarine myself!) I would set the Differential part to 0 and leave it like that then start by twiddling the Proportional part. One that was doing something reasonable, adjust the Integral bit to deal with long term changes. Return to Proportional to refine. Repeat ad infinitum ...
 
You could probably go a fair way in designing the response of the system by measuring how fast the boat responds to the helm.
Sailing along, if you waggle the helm fast, very little happens.
If you waggle it slowly the boat follows the input.
There is no point the autopilot trying to work faster than the boat can respond. Better to just average out the fast error signals. That averaging is the 'integral' bit.

You could start off with a slow response and increase the speed until the pilot started making too many ineffectual helm movements and then back off a little.
 
Great explanation. It's getting more complicated as things get more clear!
Can't we assume the vane, (whether horizontal or vertical) might work as the unique sensor that gives the error? A very basic algorithm could be like that:
......
Spot on! The challenge is that the thing you can actually control (motor torque) is several steps removed from the thing you are sensing (heading or AWA). Adding a rudder position sensor would definitely help, as would starting with the simplest possible control algorithm (proportional rather than PID).
 
Very valuable feedback from everyone- gathered very useful information to study further now in order to move forward. Also gathering info from other arduino forums regarding motors and encoders, and will be back as soon as I have something new.

So far guess the logic is (very roughly) :

1) read the error
2) move the rudder proportionally to the error - small error- small rudder move. Big error bigger rudder move.
3) as the error diminishes towards zero, proportionally return the rudder to the center.

Wonder if instead of a rudder sensor that will recognise the angle of the rudder shaft from the center and drive the dc motor, use a stepper motor.
e.g, you know that the motor moved 100 steps clockwise so if it does 100 steps CCW it will be at the center again. Moreover, the stepper acts as a break when not working so it can hold the rudder in the center. So the system consists of an absolute encoder on the wind vane that drives the stepper motor. If the vane moves, its translated into motor steps. Whatever moves the vane does, it will always return the rudder to the center when the error is 0.
 
Top