OpenMarine
Wind mode tacking issue - Printable Version

+- OpenMarine (https://forum.openmarine.net)
+-- Forum: Pypilot (https://forum.openmarine.net/forumdisplay.php?fid=17)
+--- Forum: General discussion (https://forum.openmarine.net/forumdisplay.php?fid=18)
+--- Thread: Wind mode tacking issue (/showthread.php?tid=4892)



Wind mode tacking issue - kniven - 2023-09-18

Hi all. I'm investigating an issue that I'm experiencing with my TinyPilot.

When tacking in compass mode, everything works really good. The parameters for tack rate and threshold are set to 10 degrees per second, and 50%, respectively.

Problems appear when trying to tack in wind mode (apparent). When tacking to port, the tacking subroutine completes immediately, and the normal ap algorithm eventually manages to slowly turn the boat onto the new tack.
When tacking to starboard, the boat violently turns (with the defined tack rate) into a 180 degree turn, where I manually disengaged the AP.

When looking at the code, there is one little thing that seems strange to me: 

Code:
# tacking, moving rudder continuously at tack rate
        if self.state.value == 'tacking':
            # command servo to turn boat at tack rate
            command = ap.heading_command.value
            heading = ap.boatimu.SensorValues['heading_lowpass'].value
            headingrate = ap.boatimu.SensorValues['headingrate_lowpass'].value
            headingraterate = ap.boatimu.SensorValues['headingraterate_lowpass'].value

            if 'wind' in ap.mode.value:
                d = .5 - 2*heading / command
                tack_heading = -command
                direction = 1 if command < 0 else -1
            else:
                direction = 1 if self.current_direction == 'port' else -1
                tack_heading = command - direction * self.tack_angle
                d = direction * (command - resolv(heading, command)) / self.tack_angle

            # see if we passed the tack user defined tack threshold
            if 100*d > self.threshold.value:
                self.state.update('none')
                self.direction.toggle()
                ap.heading_command.set(tack_heading)
                return

            # for now very simple filter based on turn rate for tacking
            command = (headingrate + headingraterate/2)/self.rate.value + direction
           
            command = min(max(command, -1), 1) # do not cause integrator windup
            ap.servo.command.set(command)
            return True # ensure current pilot is overridden
Could it be possible that the "direction" variable is assigned to the wrong side in line 153?
And is the "d" variable in line 151 correct?

Unless anyone immediately see any issues here, I could try to print some debug info next time I'm on the water, and share it in the thread.
Best regards, Leif


RE: Wind mode tacking issue - kniven - 2023-09-22

(2023-09-18, 09:07 AM)kniven Wrote: Hi all. I'm investigating an issue that I'm experiencing with my TinyPilot.

When tacking in compass mode, everything works really good. The parameters for tack rate and threshold are set to 10 degrees per second, and 50%, respectively.

Problems appear when trying to tack in wind mode (apparent). When tacking to port, the tacking subroutine completes immediately, and the normal ap algorithm eventually manages to slowly turn the boat onto the new tack.
When tacking to starboard, the boat violently turns (with the defined tack rate) into a 180 degree turn, where I manually disengaged the AP.

When looking at the code, there is one little thing that seems strange to me: 

Code:
# tacking, moving rudder continuously at tack rate
        if self.state.value == 'tacking':
            # command servo to turn boat at tack rate
            command = ap.heading_command.value
            heading = ap.boatimu.SensorValues['heading_lowpass'].value
            headingrate = ap.boatimu.SensorValues['headingrate_lowpass'].value
            headingraterate = ap.boatimu.SensorValues['headingraterate_lowpass'].value

            if 'wind' in ap.mode.value:
                d = .5 - 2*heading / command
                tack_heading = -command
                direction = 1 if command < 0 else -1
            else:
                direction = 1 if self.current_direction == 'port' else -1
                tack_heading = command - direction * self.tack_angle
                d = direction * (command - resolv(heading, command)) / self.tack_angle

            # see if we passed the tack user defined tack threshold
            if 100*d > self.threshold.value:
                self.state.update('none')
                self.direction.toggle()
                ap.heading_command.set(tack_heading)
                return

            # for now very simple filter based on turn rate for tacking
            command = (headingrate + headingraterate/2)/self.rate.value + direction
           
            command = min(max(command, -1), 1) # do not cause integrator windup
            ap.servo.command.set(command)
            return True # ensure current pilot is overridden
Could it be possible that the "direction" variable is assigned to the wrong side in line 153?
And is the "d" variable in line 151 correct?

Unless anyone immediately see any issues here, I could try to print some debug info next time I'm on the water, and share it in the thread.
Best regards, Leif

Actually, I think line 151 is wrong. If I understand correctly, the d-variable should start at 0 at the beginning of the tack (when heading/command =-1), and end up at the self.threshold.value/100. 
I then end up with the relation
Code:
d=0.5 * (1 + heading/command)
 
I have not yet tested this, but would like to hear from you experts.


RE: Wind mode tacking issue - seandepagnier - 2023-09-24

(2023-09-18, 09:07 AM)kniven Wrote: Hi all. I'm investigating an issue that I'm experiencing with my TinyPilot.

When tacking in compass mode, everything works really good. The parameters for tack rate and threshold are set to 10 degrees per second, and 50%, respectively.

Problems appear when trying to tack in wind mode (apparent). When tacking to port, the tacking subroutine completes immediately, and the normal ap algorithm eventually manages to slowly turn the boat onto the new tack.
When tacking to starboard, the boat violently turns (with the defined tack rate) into a 180 degree turn, where I manually disengaged the AP.

When looking at the code, there is one little thing that seems strange to me: 

Could it be possible that the "direction" variable is assigned to the wrong side in line 153?
And is the "d" variable in line 151 correct?

Are you using the unstable branch?

testing tacking with wind sensors was one of the final things i need to do before releasing the software so... it probably is wrong code.

could you try:
d = (1 - heading / command) / 2
direction = 1 if command > 0 else -1

i am working on making it work for jibing too