# Stay both pointed forward and equal distance from side walls

Simple task, robot with total knowledge about the world or at least a few side mounted IR sensors which can accurately measure where the robot is relative to a long straight corridor.

We want to BOTH:

1. Keep the robot moving straight down said corridor

2. Keep an equal distance from each wall

Noting that the robot is two wheeled or four wheeled. Point being sometimes it will be necessary to not drive straight in order to correct for drift we have accumulated which has pushed us either left or right relative to the virtual center-line we want to stay on.

I'm looking for an approach. Maybe some pseudocode, but even that's not necessary.

Don't say PID, a simple PID controller only accounts for one error term. We have two, the error as an angle between our heading and the desired straight heading and the error as a distance between us and the virtual center-line we'd like to be on at all times.

My previous approach was to attempt to use two PD loops. That didn't work out so well.

• Doesn't "keep an equal distance" imply "driving straight"? – FooTheBar Oct 17 '18 at 13:46
• what is your actual question? – jsotola Oct 17 '18 at 20:30
• you need to think clearly about the goal of your project ..... the title of your post has a goal that makes no sense .... stay pointed forward .... the robot is always pointing forward, no matter which direction it is facing ...... of the two goals in the text, the first one is redundant .... all you need is the second one. unless there is some information that you forgot to share – jsotola Oct 17 '18 at 20:35
• How are you measuring your "distance between us and the virtual center-line?" The IR sensors? But aren't they also affected by the robot angle? Sounds like you really only have one error. Why not make a steering PD based on either angle error or distance error (but not both)? – MindS1 Oct 18 '18 at 14:12