Line Following Development

The feedback control for basic line following is ‘bang-bang’, meaning the robot either turns left or right based upon the reflectance value being either above or below a threshold value of grey that indicates the edge of the line.  However, this is a crude criteria, and one which causes an oscillatory behavior, swinging back and forth across the edge of the line and never commanding the  robot to just  ‘move forward’. [This action is more or less noticeable depending upon the motion between samples and the fraction of sideways-to-forward incremental motion.   To test this effect try adding a delay (msleep()) to the feedback loop, and test it with values from 10 to 100 milliseconds. If there is a lot of sideways jitter without any extra loop delay, reduce the side-ways component (del) before adding delay. ]

We can take advantage of a sensor which has a significant field-of-view (such as the large ‘top hat’ sensor in the botball kit), by raising it slightly above the line and changing the control loop, to improve  the line following performance.   This control process uses the analog sensor signal in proportion to its offset from the edge of the line:  If the sensor is exactly above the edge, at the threshold, moving straight is commanded.  If the sensor is just slightly off the edge a slight turn is generated.  But, if the total reflectance is much brighter, turning hard toward the line is required, and if it’s much darker, turning hard away from the line is required.

It should be obvious that proportional feedback from an analog sensor should provide better control. Therefore, we are led to try a line following control function based on the difference, or error, from the sensor threshold and to use the feedback to proportionately set the rate of turning (proportionate control).

We can design the control as described above, and with a little insight about the geometry and sensor response, the feedback control gain can be set by trial-and-error.  By gradually increasing the gain, and testing the response, a value can be found that improves performance without oscillating.  Since the turning rate is determined by the difference in drive wheel speed, the wheel rotation speed and wheel diameter, all these factors are part of the multiplier and become factors in the feedback gain.  Also, sensitivity of the reflectance sensor to the turning  motion is another factor.  The sensor sample rate relative to the motion rate is a third factor.   Lastly, the sensor position as measured by the D/A ratio (see the diagram in the Line Following Task description) is a factor in calculating turning, or side-ways rate.

The response-time of the drive motors (50-100 ms) is a major factor in the control loop stability and thus a good reason to set the loop gain by trail-and-error.

Sensor Geometry

To understand how the line-following sensor’s position changes the feedback sensitivity, or gain, it helps to see the geometry of wheel motion and sensor motion as paths on two circles.

Bot diagram

Thus if the position, D, is only half as far from the axle, the feedback gain is half as great.

Range of proportional response

If we want proportional control we must sense the edge of the line over a range of angular attitudes between the robot and the line edge.  This range is determined by the width of the sensor response(S) and its distance(D) which is the radius from the spin axis of the robot.  If the large ‘top hat’ sensor is ~ 6 mm (1/4”) off the surface, it will generate a signal from ‘full white’ to a ‘grey’ threshold in 6-8 mm of sideways motion, then go on to a ‘full black’ value in another 6-8 mm.

Bot Orientations

The angle range of the turn, or ‘turning response range’, in radians, is approximately  S/D where ‘S’ is the sideways response range of the sensor (6-8mm).  If ‘D’ is reduced the ‘turning response range’ is increased (and the sensitivity to turns is reduced).

Putting sample rates and motion rates together

• For proportional line-following, it’s the ‘turning response range’ that determines the control, but how does speed and sample rates factor in?
• Sideways motion can be described as ‘delta R’ per sample period in the feedback loop:
–Ex: Assume the line turns 10 mm for each 100 mm of forward motion or line extension, and the bot moves forward equivalent to  a rate of 100 mm/sec.  (actual forward speed can be faster if the line curves only slightly)
        Sampling at 10 times/sec results in only 1 mm sideways motion for each sample.
–Feedback gain should spin the bot sensor at 1/10th of the equivalent forward speed, and, if the sensor is at the same radius as the wheels,  the sensor signal times the processing gain will cause a turn (delta R) of 1/10th of the forward extension.
–The required turn delta per sample is the result of the incremental line turn, produced by both the line path and the forward motion of the bot (as assumed in the example).
• If feedback gain is too great per sample and the motor response time, the turn delta will over-correct and the bot will oscillate sideways as it follows the line, if it is too little, the bot will fail to follow the line. [If the gain is very large, the amount of turning/sample will be beyond the proportional range of the sensor, and performance will be like ‘bang-bang’]
• If sample rate is fast relative to the line change-rate, and the feedback gain is well matched, the error signal will be small and the following of the line path will appear smooth.

Measuring performance

• In the previous example a very slow speed and very slow sample rate for the control feedback loop was assumed .
• How do you measure robot speed and sample rate?
  –Average forward speed is just distance/time:
• Set the target motor speed, run the motors for 1 or 2 seconds,  mark the start and stop position, and measure.
  –Average sample rate is just the number loops/time:
• Set a variable to the start_time <seconds()> and another to index the increments of the feedback loop, run the loop for a few hundred increments, then print out the time difference <seconds()– start_time>
• How do you measure Line-Following performance? *
  –Setup a line with a measured  turn radius
  –Run your experimental robot with a test program using various  forward speeds and record the results; include changes in sensor position, D, and the processor feedback gain
  –Write your report!

* Example: Proportional Control Line Following Code –

// Timed line follow 8/8/12; 10/4 mod for CBC or Link 8/20/15 tlg
 //assume left motor is #2, right motor is #0
 //prox sensor is analog(3) [an 8 bit A/D; for Link controller, use analog8(3)]
 /*4-a add start mode -run straight until sense line, then turn ~60 deg, run
 straight at 1/2 SP for a short distaance, to merge w. line, then begin
 line-following loop for a fixed # of samples */
 /*******POPORTIONAL CONTROL******* 6/13/2013 */
 //For Std DemoBot w. sensor at radius D =2.7" from the spin axis (D/A= 0.5)
 // CBC2 used for tests;
 //Similar tests with Link: SP =50, for motor() functions, gain ~ 2/3
 /*5-a try a proportional control where |delp|=4*|analog(3)-mid| only
 20% slower loop, */
 /*5-c try an adaptive start, less spin, move at 1/2 speed until time or
 sense line */
 #define SP 583
 #define left 3
 #define rt 0
 int main() {
   int mid =145; // average sensor level between dark & light for 8 bit A/D
   // for Link change to analog8(3) below to read sensor
   int delp, i=0;
   float startt; // time ref
   printf("start pointing at line, then press B -5c\n");
   while(b_button()==0){} //wait for B press
   mav(left,SP); mav(rt,SP);
   while(analog(3)<mid){}// wait to sense line 
   mav(rt,-SP/2); mav(left,SP/2);//spin to right
   msleep(1600); ao(); // turn ~ 60 deg
   //while(1); //test for angle & set sleep time above
   mav(rt,SP/2); mav(left,SP/2); 
   //********* run line follow  *******
   startt = seconds();
   while(i<1000) //count # of loops to the end of line
       if (analog(3) < mid )// too white 
         {delp=4*(mid-analog(3));//delta R speed proportional to error 
          // lower power foward on left, raise on right: turn left 
          mav(left,SP-delp); mav(rt,SP+delp);
       if (analog(3) >= mid ) // too black 
         { delp=4*(analog(3)-mid); //delta R speed proportional to error 
          // lower power foward right, raise on left, turn right 
          mav(left,SP+delp); mav(rt,SP-delp);
       if (seconds()-startt > 23.)break ; // alternate timing option
   printf("finish ,%d loops - %.2f sec",i, seconds()-startt);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s