This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wind mode tacking issue
#1
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
Reply
#2
(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.
Reply
#3
(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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)