  Program Simulation Mechanism of 2 Bar Robot Arm with 2 Degrees of freedom

This text is a simple example of how to use the HP to simulate movement of a
robot arm controlled with few keys. The example is not exactly spectacular as
you will be able to verify, but serves as an example of various techniques of
programming as you can see: use of variables, graphics, functions, use of
customized menus, CASE structures, infinite detection of keys, curls, etc...

This program has been proposed as an example in one of the programming courses
for the HP-48 that I have distributed in the E.T.S.I.I. of Vigo, and this
proposal is merely educative, and much can be improved, mainly graphically.

  ------------------------------------------------------------------------

Theoretical introduction:

The mechanical arm that we will try to simulate is outlined in the following
figure:

Equations that govern this movement are:

                X1 = Xr + l1 * cos(F) ; Y1 = Yr + l1 * sin(F)

      X2 = X1 + dX = X1 + l2 * cos(A) ; Y2 = Y1 + dY = Y1 + l2 * sin(A)

The representation is simple in the sense that it is necessary only to 
determine the points within a curl.

 ------------------------------------------------------------------------

Next is the code of the program along with the pertinent comments:

 DEG FUNCTION			@Set Degree-mode and Function plot type 
0 3 5 5 45 -20 15 15
RCLMENU \-> \<-XR \<-YR		@Beginning structure of local variables
L1 L2 F A INC1 INC2		@Note arm length (L1, L2), Fi and Alfa
MenuAct				@angles (F, A), Increments of angle
                                @by step and the present menu
  
    DO				@Beginning of curl DO-UNTIL-END
\<-XR L1 F COS * +		@Find x1
\<-YR L1 F SIN * +		@Find y1
L2 A COS *			@Find >x for x2
L2 A SIN *			@Find >y for y2
\-> X1 Y1 DX DY			@Note them for use in local variable
                                @substructure
       ERASE \<-XR             @This structure is used to draw the
\<-YR R\->C X1 Y1 R\->C         @bars from their coordinates
LINE X1 Y1 R\->C X1
DX + Y1 DY + R\->C
LINE
{ # 0d # 0d } PVIEW		@Show the image
3 FREEZE                       @and freeze the display to make it
				@persistent
"\|v\Ga" " "End"} TMENU         @Show the custom menu
-1 WAIT				@Wait for a key press
  CASE DUP 11.1 ==		@If A key, add INC1 to angle F
        THEN 'F'
INC1 STO+
        END
DUP 12.1 ==			@If B key, subtract INC1 from F
        THEN 'F'
INC1 STO-
        END
DUP 13.1 ==			@If C key, add INC2 to angle A
        THEN 'A'
INC2 STO+
        END
DUP 14.1 ==			@If D key, subtract INC2 from A
        THEN 'A'
INC2 STO-
        END
DUP 16.1 ==			@If F key, drop key, erase PPAR
        THEN DROP		@and exit the program
'PPAR' PURGE

        END
      END
DROP				@Erase the key (We don't need it anymore)
UNTIL 0				@Repeat infinitely
    END				@Previous process
  				@Process end


An image of the program in operation can be seen in the following figure:

  ------------------------------------------------------------------------

This text is  Jose M., 1997 archive and it cannot be used nor be reproduced
in any course, book, etc.. without the express permission of the author.

Translation undertaken by David J Porter <mailto:porterd@netaccess.co.nz>,
July 16, 1998. All errors in translation are mine.
