Society of Robots - Robot Forum
Software => Software => Topic started by: saba_rish91 on August 23, 2012, 11:20:05 AM
-
Hi,
I built a line following robot and it didn't come out well. Can someone upload the code of line follower with and without PID control for reference? (Preferably Arduino code)
Thanks in Advance.
-
I'll share my linefollow-code with and without PD-control
With PD-control (http://git.hax0r.se/?p=Arduino/.git;a=blob;f=LineFollowingPID/LineFollowingPID.pde;h=06b1aae6398fab504a9cf1479ec654dce50041eb;hb=master)
Without PD-control (http://git.hax0r.se/?p=Arduino/.git;a=blob;f=LineFollowing/LineFollowing.pde;h=99fb40adde477c01d9b1d5663c775cb927868efe;hb=master)
-
I'll share my linefollow-code with and without PD-control
With PD-control (http://git.hax0r.se/?p=Arduino/.git;a=blob;f=LineFollowingPID/LineFollowingPID.pde;h=06b1aae6398fab504a9cf1479ec654dce50041eb;hb=master)
Without PD-control (http://git.hax0r.se/?p=Arduino/.git;a=blob;f=LineFollowing/LineFollowing.pde;h=99fb40adde477c01d9b1d5663c775cb927868efe;hb=master)
Thanks a lot!
-
How many sensors do you have and what kind are they? It makes a big difference.
// taskControl
// This task runs in parallel to taskBalance. This task monitors
// the optical and ultrasonic sensors and sets the global variables motorControlDrive
// and motorControlSteer. Both of these values are in degrees/second.
//
task taskControl()
{
Follows(main);
char pfData[8];
while(true) {
LightSignal = SensorNormalized(LIGHT_SENSE);
LightSignalPrev = LightSignalBar;
// calculate filtered value of light signal for Deriv. control.
LightSignalBar = FCTRACKING*LightSignal + (1.0-FCTRACKING)* LightSignalBar;
// derivitive of light signal
LightSignalDeriv = KDTRACKING*(LightSignalBar - LightSignalPrev);
LightSignalErr = (LightSignal - LIGHT_TARGET);
LightSignalInt += KITRACKING*LightSignalErr;
NumOut(50, LCD_LINE6, LightSignal);
// change over to use ultrasonic sensor for object detection
// stop when object detected - later on we can add u turn after timeout
// JMK
ObjectDistance = SensorUS(ULTRASONIC_SENSOR);
if (ObjectDistance < MIN_DISTANCE) {
// stop here.
motorControlDrive = 0;
motorControlSteer = 0;
}
else {
// Set control Drive and Steer. These are in motor degree/second
// KPTRACKING proportional gain for line following mode
// KITRACKING Integral gain for line following mode
// KDTRACKING Derivitive gain for line following mode - currently set = 0
// FCTRACKING filter constant for derivitive gain
motorControlDrive = NOM_SPEED;
motorControlSteer = (KPTRACKING * LightSignalErr )+ LightSignalDeriv + LightSignalInt
;
// Turn left if the intensity is too low, right if it is too high.
}
//Wait(CONTROL_WAIT);
}