We have not printed the other subprograms here. If you have difficulty
programming a process, you can find the finished subprograms in the
MIKE_TEMPLATE.MDL file on the CD. The main program of this project
is blank. You can find a list with existing subprograms, which you can
insert in the main program, in the function block under the Subprograms
heading.
Task 4:
Program Mike, so that he takes five steps forward, turns two
steps to the left, then two steps to the right and then three steps
back before starting all over again. Use the variable Var1 as count
variable for the number of steps. Use E8 as reset pushbutton.
Solution:
This project is called MIKE_DANCE.MDL.
But don't look right away
there to see how it works.
First try to figure out the
solution yourself. If you
do not succeed, you can
always look up the solution.
To try out all subprograms,
we now want to get Mike
to dance.
3.2.5 Detecting Obstacles
As a last step, we want to get Mike to detect obstacles with his movable
fender ("sensor" would be a better term) and avoid them.
Task 5a:
Program Mike to
that when he
detects an obstacle
at his left sensor
(pushbutton E6),
he first takes four
steps back and
then two steps to
the right. If there
is an obstacle at
his right sensor
(pushbutton E5),
he should take
four steps back
and then three
steps to the left.
Solution:
Mike first walks straight ahead. After each step, the pushbuttons E5 and
E6 are queried. If E6 is pressed, the program branches to the left process
(first back, then right). If E5 is pressed, the program branches to the middle
process (first back, then left).
Because the pushbuttons E5 and E6 are only queried after each full step,
it takes a relatively long time until Mike reacts to an obstacle.
Task 5b:
Optimize the STRAIGHT
subprogram, so that
Mike can react more
quickly to an obstacle.
Tip:
Do not use the EDGE
function block but
instead the COMPARE
function block for
querying the pushbut-
tons E1 and E2.
Also query whether E5
or E6 is pressed.
Solution:
GB+USA
15