The problem is that the above algorithm only works if
the card is already somewhat aligned. If the card is totally
askew — as in Figure 5 — the above algorithm can produce
erratic results. For that reason, a different algorithm must
be applied first. The goal of this additional algorithm is to
get the card somewhat aligned, so that the original
algorithm described above can be applied to finish the job.
For our purposes, somewhat aligned means within 20° or
so of vertical.
The algorithm I used to achieve this partial alignment is
as follows: The arm should move up and down toward
each sensor in turn, until that sensor fails. The arm’s
position at each of these endpoints should be noted.
is located, the arm can move slightly further along the
same path (to arrive somewhere near the card’s center). If
only one of the sensors is triggered, the arm should also
move toward that sensor until both sensors activate.
Aligning the card is a much more difficult problem. My
general plan was to have the arm move toward the edge
of the card until one or both of the sensors fail to see it. If
both sensors fail simultaneously, then the card is
considered vertically aligned. If only one sensor fails, then
the card must be rotated to achieve the desired vertical
orientation. The direction of rotation is dictated by which
sensor fails as shown in Figure 4. (Note: The circles in the
figure indicate the sensor positions.)
The distance between these two points correlates to
the width (or length) of the card at the point of the
measurement. Notice that this measurement is not the
actual width of the card — it is the distance moved by the
end effector itself (see Figure 6). Since the distances are
correlated though, we can utilize the calculated distance in
the same way we might use the actual distance.
The point is that if this distance is small enough, we
know the card is aligned somewhat horizontally. If it is
large enough, the card is somewhat vertical. Anything in
between means the card should be considered neither
vertical nor horizontal. Figure 7 demonstrates these ideas.
After making the measurement, the program must
Figure 7. #include “ MagicianLibrary.bas”
main: gosub Initialization repeat gosub MoveToStart delay 3000 // give user time to present new card gosub FindCard if CardFound gosub RotateToNearVertical gosub RotateToVertical gosub CenterArmOnCard gosub MoveCardToStack endif until not CardFound
46 SERVO 05.2017