Download Line following

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Opto-isolator wikipedia , lookup

Pulse-width modulation wikipedia , lookup

Electric motor wikipedia , lookup

Brushless DC electric motor wikipedia , lookup

AC motor wikipedia , lookup

Stepper motor wikipedia , lookup

Brushed DC electric motor wikipedia , lookup

Induction motor wikipedia , lookup

Variable-frequency drive wikipedia , lookup

Transcript
Line Following
This discussion assumes that a robot is used in which there are sensors at the front that detect the
presence of a white line on the floor.
Also it assumes that the robot is steered by varying the power to each of two motors, separately
driving the two rear wheels:
Sensors
Robot
Driving wheels
1 Simple Line Following
Here the sensors are used to detect just 3 signals
- On the line
-
To the left of the line
-
To the right of the line
Or perhaps 2 more:
- To the very left of the line
-
To the very right of the line
There are 3 (or 5) different sets of power levels fed to the motors:
- Both motors fast
- Left motor fast, right motor slower
- Right motor fast, left motor slower
- Left motor fast, right motor stopped
- Right motor fast, left motor stopped
Using the plug-in line sensors for the “Picaxe buggies” (Alice etc), the 3 sensors can be read on
Input 7 = left sensor
Input 6 = middle sensor
Input 2 = right sensor
You can read all 3 sensors with the following 2 lines in PicAxe BASIC:
B0 = pins
B0 = B0 & %11000100
After which you can use a basic select statement to pick out the 8 different patterns:
select B0
case %00000000
...
case %00000100
...
case %01000000
...
...
etc etc.
endcase
2 Simple Motor Control
The motors on the picaxe buggies have just 3 settings
- Off
- Full speed forwards
- Full speed backwards
For the right hand motor you use pins 7 and 6:
Off:
pinsb = %00000000
Forwards: pinsb = %01000000
reverse: pinsb = %10000000
To run at half speed you need to change the motor settings after a few milliseconds
pinsb = %01000000
pause 10
pinsb = %00000000
pause 10
For the left hand motor you use pins 5 and 4:
Off:
pinsb = %0000000000
Forwards: pinsb = %00010000
reverse: pinsb = %00100000
For both motors, simply add the binary patterns above.
3 Line Spinning
This is a simpler use of the sensors and motors, in which the motor speeds are kept always the
opposite of the other. The motors are always running at the same speed as each other, but if one
goes forwards, the other goes backwards.
The robot will therefore spin clockwise or anti-clockwise, around the halfway point between the 2
wheels:
The program controlling the motors now has 3 options as above:
- Both motors stopped
- Left motor forwards, right motor backwards
- Right motor backwards, left motor forwards
Spin left
Spin right
I suggest that you use “line spinning” for testing control methods below instead of line following,
because you need only a small space and don’t have to carry the robot backwards and forwards
around the room.
When you have stability in line spinning, make the motors actually run forwards as well and you
will have a line follower.
4 Analogue sensors
The sensor modules actually produce a voltage which indicates the amount of reflected light that
each of them sees.
The previous examples regarded each sensor as “on” or “off”. You then used which of them was
on to determine the position of the line.
It is possible to use the actual voltage from the sensors (taken in pairs), to give a very fine reading
of the line position. It can be broken down into about 600 different values.
There is a subroutine in the Larry subroutine kit called Readline that sets picaxe variable W0
to 1000 for the centre of the line, 1300 at the right and 700 at the extreme left.
This gives you much finer control.
You can still use the basic select statement to pick out different ranges:
select W0
case 0 to 900
...
...
case 900 to 1100
...
...
case 1100 to 3000
...
...
etc etc.
endcase
The above divides the readings up into 3 bands as before.
5 PWM Motor Control
The motors on the Larry PicOne, and Dolly buggies have a different method of controlling the
motors.
There are outputs that control the direction – much like the picaxe buggies:
high S.8 ; Left Motor fwd
low S.8
; Left Motor reverse
high S.11 ; Right Motor fwd
low S.11 ; Right Motor reverse
But there is no simple pin command that stops the motor.
Instead you set the speed with a command like
pwmout C.1, 99, 0
; set left speed = 0
pwmout C.2, 99, 0
; set right speed = 0
pwmout C.1, 99, 400
pwmout C.2, 99, 400
;
;
set left speed = maximum
set right speed = maximum
There are 2 subroutine in the Larry subroutine kit called RightMotor
that take a speed value from variable W0 and set the motor speed.
Use:
W0 =-400
W0 = 0
W0 = -400
for full speed forwards,
for stop, and
for backwards.
and LeftMotor
6 Proportional control
If you use the reading from subroutine Readline to indirectly set the motor speed, you can
have what is called “Proportional Control”.
You will have to treat the output from subroutine Readline differently for values less than
1000, than for more than 1000, because you will be adjusting different motors in each case.
A simple approach for line-following is to make the speed of the slowed motor
= 400 – (difference between sensor reading and 1000)
And the speed of the fast motor = 400.
For spin-following, make the motor speed = (difference between sensor reading and 1000) in one
case, and the nagative for the other.
Proportional control gives every sensor position its own set of motor speed settings
It should make the buggy more stable, and less likely to overshoot.
You can make the control more reactive by using 2 x (sensor reading - 1000) or even 3 times. Or
you can make it less reactive by dividing it by 2 or 3.
In BASIC:
gosub Readline
if W0 > 1000
difference = W0 – 1000
W0 = 400 – difference
gosub leftmotor
W0 = 400
gosub RightMotor
else
difference = 1000 – W0
W0 = 400 – difference
gosub RightMotor
W0 = 400
gosub LeftMotor
endif
7 Speed adjustment
In the sections above we used 400 as the maximum speed. This might make the buggy
uncontrollable. Try using 300 or 200 for a slower, more stable follower.
If you use a picaxe basic symbol “SPEEDMAX” to represent the top speed, you will need to
adjust the speed in only one place in your program.
Another approach is to use the potentiometer in the Larry and Dolly robots to set the maximum
speed – you can then quickly find out how fast you can run the robot without it falling off the
line.
There is a subroutine in the Larry subroutine kit called Potentiometer that sets W0 to a
number in the range 0-255 depending on the potentiometer position.
If you multiply this by 25/16 it will be in the range 0 - 400.
8 Motor braking
A disadvantage of the PWM method of speed control is that the motor takes a longer time to slow
down when you use:
pwmout C.1, 99, 0
; set left speed = 0
It can improve stability if you use a negative speed value instead of zero, to actively slow the
motor down.
9 Automatic Speed adaptation
In the sections above we made the maximum speed easily settable by the programmer.
A competition Robot will adjust its own speed at different points around the track.
It will smoothly speed up along the straights, and cut the maximum speed when it detects a
corner.
Use a picaxe word variable to store this speed, and make it increase each time round the main
loop, if the sensor reading is close to the centre. Cut it back to a slow speed when the sensor
reading shows you are close to the edge of the line.
In addition, you can set the speed back to slow when you see a curvature marker on the left hand
side of the robot.
10 Derivative (or predictive) control
The reading from subroutine Readline is always a little out of date.
It takes a few milliseconds to calculate. Also the motors take some time to respond to the PWM
commands.
Control theory tells us that if a response to a stimulus is delayed then the system is in danger of
over-reacting, and becoming unstable.
This happens especially if the response (motor speed) is high.
A method of improving stability is to make the motor speeds depend not on the current reading
but on a prediction of the reading at some point in the future.
In simple terms, if you record the reading before the current one,
then you can calculate the change since the last reading.
By adding this change onto the current reading, you have an estimate of the next reading:
symbol Last = W1
symbol Change = W2
symbol Next = W3
...
‘ the following is in a do loop..
gosub ReadLine
change = W0 – Last
Next = W0 + Change
‘ now record the current reading for use next time…
Last = W0
‘ now set W0 for the rest of your program to use…
W0 = Next
...
Use W0 in the normal way and you will be using Derivative control.
To use a prediction further into the future use:
Next = Change * 2 + W0
- Or
Next = Change * 5 + W0
Experiment to get the best stability.
Line following topics
Function
Discrete sensors (3 digital)
Discrete responses
- 3 options
- 5 options
Digital motors
Technology
Input pins 6,7,2
Output pins 7654 (Alice)
7652 (Harvey)
- on-off
- software PWM
Pause values
Illumination pulsing
PicOne only
“Analogue” sensor.
Subroutine kit
- Calibration / overlap
Discrete range responses
- 2 options
- 5 options
- “25” options
Analogue Motors
Subroutine kit
Select command
Computed (Proportional) response
Picaxe Maths
Subroutine kit
PWM commands Larry.
PWM Picone
Picaxe bytes, words number range
negative numbers
Derivative response
Braking / coasting
Larry: Reverse power option
Dolly. BrakeRight subroutine
Speed adaptation
- curvature change markers
Responding simultaneously
- Line only
- Line and stop marker
- curvature marker
- software PWM
Do loop. Minimal loop time