Bug in pivot steering code

Hi, I’ve been following this forum and using Ardurover on boats for a while now. Been a quiet observer but it seems like I finally have a reason to post! I believe I found a bug in the steering code for pivot turns, and have a fix for it that works in simulation and that I’ll probably test out on a boat over the weekend.

I was tuning one of my boats to follow this series of waypoints:

I had set PIVOT_TURN_ANGLE to 135, so I was expecting to not get pivot turns on 90 degree turns. Oddly, I was getting a pivot on turn 3. My other 90 degree turn (turn 2), I was not getting a pivot. I guess turn 7 is just shy of 135, so no pivot there either.

In this youtube video, you can see the boat executing a pivot turn at turn 3 at 25 seconds

I was able to reproduce this problem in simulation. It seems that if you have a turn that is less than PIVOT_TURN_ANGLE, but the following turn is greater than PIVOT_TURN_ANGLE, you might erroneously get a pivot turn. In the case of the path above, the sharp turn at waypoint 4 was causing me to also pivot at waypoint 3.

The reason this happens is, while passing waypoint 3, ardupilot calculates what the final speed at waypoint 4 should be. Part of that process involves calling the rover.use_pivot_steering function, which can set pivot_steering_active to true, causing the rover to pivot at the current waypoint while calculating the final speed for the following waypoint.

Here’s the specific line of code that’s causing the issue

One way to fix this is to make a separate function for figuring out if the rover should pivot at the next waypoint. Here’s my solution:
https://github.com/ArduPilot/ardupilot/compare/master...jeff567:rover_pivot_turn_fix

This solves the problem in simulation. Happy to follow up with plots and logs. Plan on testing it out on the same path above over the weekend.

4 Likes

Jeff,

Great find! That’s definitely a bug.

The solution looks good. You want to PR it? One small non-functional change is perhaps to collapse the stuff below, “// calc bearing error” into a single line… or a small number of lines… but in any case, nicely done!

sure! just submitted a PR.
thanks

3 Likes

… and merged… so we should probably push this out in a point release (i.e. Rover-3.4.2)… I might aim to do that next week sometime…

great! looking forward to testing it out.

I compiled and loaded firmware with this fix and things are working nicely now. seems to be obeying the PIVOT_TURN_ANGLE parameter of 135 degrees.

Here’s a video:

And bonus onboard video:

2 Likes

Jeff,

Great, thanks for testing it and really love the videos. I stuck them on the ArduPilot.org facebook channel, hope that’s OK.

1 Like

something else I’ve been wondering… are rovers expected to stop when pivoting? I know while pivoting, the desired_speed_final gets set to zero, but it seems like in my boats and in simulations that they don’t necessarily have zero forward speed while pivoting.

I believe ideally, the rover will approach a waypoint, decelerate to zero velocity, execute a pivot turn (with no forward speed), then accelerate towards the next waypoint.

However looking at logs, it seems during a pivot turn, the desired speed doesn’t actually reach zero.

I haven’t dug into it much, but I think this may have to do with AR_AttitudeControl::get_desired_speed_accel_limited

Jeff,

It may not quite reach zero. I guess it’s possible to make it do that although that would also slow down the cornering. I think the key thing that people want is the vehicle to stick close to the path… so that should probably be the specific thing to look at and fix (if necessary).

ok understood, thanks. just wanted to make sure I’m not trying to fix something that doesn’t need to be fixed!

1 Like

hi, I think your boat’s performance very well when trigger the pivot , but in my boat always first turn to the reverse direction and then turn to the next waypoint , would you give me some advice ? very thanks