View unanswered posts | View active topics It is currently Tue Sep 02, 2014 12:43 pm






Reply to topic  [ 5 posts ] 
PID line follower 
Author Message
Rookie

Joined: Fri Sep 04, 2009 3:03 pm
Posts: 10
Post 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?

_________________
Jordan Miller
2010 Dean's List Semi-Finalist
FRC 1741 --- Engineering Captain, Driver
Vex 323a --- Team Captain, Driver


Wed Feb 02, 2011 11:25 am
Profile
Expert

Joined: Wed Jun 30, 2010 7:15 am
Posts: 181
Post Re: PID line follower
this is for NXT, so you might have to change some of it, but this the code I use:
Code:
#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;

  wait10Msec(200);
  PlaySound(soundBlip);
  tooLow = SensorValue(LS);
  wait10Msec(200);
  tooHigh = SensorValue(LS);
  PlaySound(soundBlip);
  offset = (tooLow+tooHigh)/2;

  while(true){
    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.

DiMastero

_________________
leonoverweel.com


Wed Feb 02, 2011 2:51 pm
Profile WWW
Rookie

Joined: Fri Sep 04, 2009 3:03 pm
Posts: 10
Post 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.

Jordan

_________________
Jordan Miller
2010 Dean's List Semi-Finalist
FRC 1741 --- Engineering Captain, Driver
Vex 323a --- Team Captain, Driver


Wed Feb 02, 2011 3:59 pm
Profile
Rookie

Joined: Mon Jun 20, 2011 1:21 am
Posts: 2
Post 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


Mon Jun 20, 2011 1:27 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3210
Location: Rotterdam, The Netherlands
Post Re: PID line follower
This is a ROBOTC forum, not EasyC. You may want to ask this question on the EasyC forums instead.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jun 20, 2011 10:19 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.