I’ve got 2 motors that drives my unit and I can easily steer it manually by simply adding more speed to one wheel vs the other.
Now I’m automating the rover using image processing to follow a driveway. As the rover travels I calculate the distance in pixels between the rover center and the target (middle of driveway). I then use some factor (1.1) and use that to add speed to the correct wheel.
Kinda works good until it needs to make large corrections. I can only update the speed every .75secs.
After it turns and drives to the middle the wheel speeds are equalized - but the rover is pointing in the direction of the turn. In the best case it then goes past the center before correcting back again and eventually stabilizes.
Original Poster here with some more details of what i've tried so far. Attached is a frame from my imagine processing. As you can see i have 2 green circles along the edges that define the sides of the road and a green circle in the middle that is simply the mid-point between them (TARGET). This isn't a great example because I also have a red circle behind the center which indicates the center of the camera (CENTER). When i am not centered on the driveway the TARGET will be some number of pixels from CENTER - this is my DELTA as indicated in the legends.
So what i have so far is that i take DELTA and multiple it by 1.1 and then add that to the correct wheel to steer it back towards the center. Each time I get a new image frame (every .5 - 1sec) DELTA is smaller and I reduce the rate of the turn - but its still turning. Once I get to the center or past the center I either make both motors the same or i add to the opposite motor since i over corrected.
If things go well this actually works good enough - i get some S turns as it zeros in on the center. Problem is when the image processing doesn't work perfectly and the algorithm needs to make large changes. In this case the DELTA needs to be significant to turn it but then reduce so it doesn't turn beyond the center point.
In a perfect world i would be able to turn a calculated amount depending on how far off i was (size of DELTA), drive straight to the center, then turn in opposite direction a specific amount to center the rover. Problem is i need to do this relative to each frame from the camera as the DELTA gets smaller as i am correcting.
This really feels like i'm trying to invent a new algorithm for something i have a feeling has been solved a long time ago. I am not 100% sure what a PID controller does but I have a feeling it may help here. Or do i need some sort of additional piece of information (feedback?) to indicate my orientation?
I don't need perfect here - just want the rover not to go off the side of the driveway...