PID line follower
Page 1 of 1

Author:  Dracco1993 [ Wed Feb 02, 2011 11:25 am ]
Post subject:  PID line follower

I have read several posts about people making PID line followers, but I can't find any code for them. I would love to use one on my robot, but I am not familar with how to code one. Does anyone have "standard" code that would do pid line following?

Author:  DiMastero [ Wed Feb 02, 2011 2:51 pm ]
Post subject:  Re: PID line follower

this is for NXT, so you might have to change some of it, but this the code I use:
#pragma config(Sensor, S1,     LS,                  sensorLightActive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main(){
  float offset;
  float Kp = 7;
  float Ki = 0.00018;
  float Kd = 0.00018;
  float Tp = 40;
  float error;
  float integral;
  float derivative;
  float lastError;
  float turn;
  float powerA;
  float powerC;
  int tooLow;
   int tooHigh;

  tooLow = SensorValue(LS);
  tooHigh = SensorValue(LS);
  offset = (tooLow+tooHigh)/2;

    error = SensorValue(LS)-offset;
    integral = integral+error;
    derivative = error-lastError;
    turn = (Kp*error)+(Ki*integral)+(Kd*derivative);
    powerA = Tp-turn;
    powerC = Tp+turn;
    motor[motorA] = powerA;
    motor[motorC] = powerC;
    lastError = error;

I used this AWESOME guide by J. Sluka, a step by step tutorial on how to write and tune PID controllers (for line followers). That's mindstorms based, too, though.


Author:  Dracco1993 [ Wed Feb 02, 2011 3:59 pm ]
Post subject:  Re: PID line follower

Thank you very much. Right now im tuning it so that I can get it to follow the line that I want it to. =) The guide is very helpful, thank you for pointing me to it.


Author:  093611k [ Mon Jun 20, 2011 1:27 am ]
Post subject:  Re: PID line follower

Can i implement PID line following using easyc?? i need it soo much for my line follower robot... i will appreciate some help

Author:  mightor [ Mon Jun 20, 2011 10:19 am ]
Post subject:  Re: PID line follower

This is a ROBOTC forum, not EasyC. You may want to ask this question on the EasyC forums instead.

- Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group