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.

  • 1
    $\begingroup$ Doesn't "keep an equal distance" imply "driving straight"? $\endgroup$ – FooBar Oct 17 '18 at 13:46
  • $\begingroup$ what is your actual question? $\endgroup$ – jsotola Oct 17 '18 at 20:30
  • $\begingroup$ 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 $\endgroup$ – jsotola Oct 17 '18 at 20:35
  • $\begingroup$ 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)? $\endgroup$ – MindS1 Oct 18 '18 at 14:12

Implement two low-level PID controllers, one for each wheel. Then compute the targets for both wheels using a path planner which determines next wheel setpoints based on the error computed after reading the IR sensors. If you cannot determine both position and orientation errors using your sensors (you cannot), then keep track of the last few positions to determine actual angle of travel.

I would add a third PID loop for “squashing” the orientation error, but that isn’t required if you can accept some wavering about the centerline of travel.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.