Pages

Tuesday, June 2, 2015

InLinea01: A PID controlled line following robot build on an ATmega 8



InLinea01 is a simple PID controlled line following robot.
This is not speed oriented line follower, this is just a prototype I built to experiment with this type or machines, though it can be the first step to build a faster one.


The goal of a line following robot is follow a line that is draw on the floor, usually this line is a black on white floor line, or a white on black one.
A sensor is needed to detect the line, and mantain the robot over the line.

This follower has two 200rpm @ 6v DC motors, driven by a L9110S H-bridge based controller board.


Detector is build using 8 cheap TCRT5000 reflective sensors. It can detect black on white, or white on black lines. The dection inversion must be decided at compile time.


It uses PID controller to make the robot follow the line smoother.
The PID parameters can be setup via UART using a GUI, the UART connection can be estabilished through a bluetooth adapter like the HC-05, if you use this type of connection, you can setup PID variables leaving cables out of the robot. That's pretty usefull for a line following robot.


The core of the robot is a ATmega8 microcontroller running at 8Mhz with his internal crystal.

A 7.4v LiPo battery powers the robot. Then an LM2596S based DC/DC converter regulated to 6v feed the 2 motors, and a LM7805 voltage regulator all other components.


In a few words, sensor detect the line. In order for the robot to follow the line, it has to be centered over it. To keep the robot in the middle of the line the speed of eveny wheel must be changed. The difference in speed of rotation determines the robot direction. That speed is evaluated by the PID controller depending on the position error.


As example, if the line is detected by the right detectors, then left motor has to spin less than the right one, that way the robot will turn a little on the left, and the line will be again in the center position.
The PID controller prevents robot oscillations and smooth his path.



Changelog
  • 01c: fixed a typo error on schematics, thanks to Visweswara Rao Kalla for this feedback.
  • 01b: fixed a typo error on schematics, thanks to Abdullbasit AlHaita for this feedback.
  • 01: first release

Code

Notes
  • read risk disclaimer
  • excuse my bad english

19 comments:

  1. Great project . BTW, You missed to connect VCC to 4k7 pull-ups schematic :) right ?

    ReplyDelete
    Replies
    1. Ups.. Thank you for your feedback! It was my mistake, a "typo" error on that schematic. Now, I've fixed it, also i've added the GUI for the parameters update in the 01b version.

      Delete
  2. I have build brushed dc servo driver as here using servostrap2 file
    https://googleweblight.com/?lite_url=https://www.youmagine.com/designs/dc-motor-closed-loop-control-software?_escaped_fragment_%3Ddesign-information&ei=Qb3avN-I&lc=en-IN&s=1&m=664&ts=1443591066&sig=APONPFlrX8_ZiVN26yov2Z_A5b2quKjioQ https://googleweblight.com/?lite_url=https://www.youmagine.com/designs/dc-motor-closed-loop-control-software?_escaped_fragment_%3Ddesign-information&ei=Qb3avN-I&lc=en-IN&s=1&m=664&ts=1443591066&sig=APONPFlrX8_ZiVN26yov2Z_A5b2quKjioQ and it's working great now at higher speed error ocurred that time motor becomes unstable so I want to solve that ...so when error ocuur that time I can make enable pin of l298 becomes low and that disable l298 need your help here

    ReplyDelete
    Replies
    1. Hello, please write here only comments related to this topic (InLinea01 PID follower robot). Your comment is not about that.

      Delete
    2. Okay exuse me for that...
      Acctuall when this line follower eccidenty goes off the way that time its becomes unstable that means error is too much high that our bot can not handle so that time we should stop our motor from running so our bot does not damage so will you please suggest me how to do that?

      Delete
    3. First i will adjust the PID in such a way the bot will not goes off the line. Then, if this happens, because of too much speed of the motor, or other reason, there are a few way to make it came back to the like, one reallly simple could be to make is slowly run in pattern to search the line.

      Delete
    4. I'm talking about if motor is too fast and
      If input count rate exceeds the sampling rate, count error will occur and the correspondence between actual bot position and current position register will be lost that time bot becomes unstable that time we want to write pwm zero so our bot does not damge ..so how found that register is lost and by that we write some code to disable out bot by zero pwm and that keep ourbot safe

      Delete
    5. How does the input count rate can exceed the sampling rate, as long as the sample rate, in this project, is the input count rate? Anyway, if you lost something due to too slow sampling rate, if possible, raise the sampling rate.

      Delete
  3. Thats what I m talking about so due to slow sampling rate if I miss something that time bot should stop by disabling motor so what logic is used to find sampling rate so
    if samplingrate <inputrate then disable motor driver howto thisin practical coding

    ReplyDelete
    Replies
    1. There is no sampling rate frequency defined by timer in this project. What do you mean with "if I miss something", then "sampling rate so
      if samplingrate <inputrate" ? You can not miss something cause the input rate it is equal to sampling rate, i mean, to me the sampling rate is the rate you get input from positioning sensors, in this project that's the sample rate.

      Delete
  4. Thanks for clearing my doubt thanks

    ReplyDelete
  5. Great how to tune pid because pid will be different for each setup ..I also googled on tuning but cant find something useful so wil you please show me practical approach to tune pid thanks in advance ...also pid library u have used is really useful in other project also...I am waing for your next blog on pid based dc closed loop servo thanks .

    ReplyDelete
    Replies
    1. Hello, and thanks for your feedback. There a few methods you can try, in the first stage I've used the Ziegler-Nichols method, then i fine tuned by experimenting values. A simple approach could be start by the value I'm using, and fine tuning for your build.

      Delete
  6. i have lotsof qution to ask ..so should i ask here ? or on email ? because i dont want to fill your beautiful blog with tons of comment !

    ReplyDelete
    Replies
    1. Thank you for asking. If you can do a summuary in a few line for questions, put it here, otherwise write by mail.

      Delete
  7. Nice project sir, I think you need to connect those IR LED(Tx) to Vcc.

    ReplyDelete
    Replies
    1. Thank you for your feedback. I've fixed it. You have been cited on download link for this bugfix suggestion. If you do not want to be cited please tell me, and i will remove your name from there.

      Delete
    2. Side note. It was some sort of "typo" error on the schematics.

      Delete