home *** CD-ROM | disk | FTP | other *** search
- unit List10_2; { Listing 10-2 }
-
- interface
-
- uses Graph, Mouse, Crt, ProRobot;
-
- type
-
- RobotArm = object( Segment )
- procedure Init( AnchorX, AnchorY, ArmLen : Integer;
- Position : Degrees;
- DispQ : Boolean );
- procedure MoveTo( APoint : Point );
- procedure ShowBase;
- procedure ShowLimit;
- end;
-
- implementation
-
- procedure RobotArm.Init( AnchorX, AnchorY, ArmLen : Integer;
- Position : Degrees;
- DispQ : Boolean );
- begin
- Segment.Init( AnchorX, AnchorY, ArmLen, Position );
- if DispQ = true then
- begin
- Show;
- ShowBase;
- end;
- end;
-
- procedure RobotArm.MoveTo( APoint : Point );
-
- var D : real;
- RotDelta : integer;
- AxDelta : integer;
- begin
- { Phase 1 }
- RotDelta := 1;
- D := Distance( APoint, BusyEnd ); { find distance }
- Rotate( RotDelta ); { rotate }
- if D < Distance( APoint, BusyEnd ) then begin
- { if new distance is greater than old distance }
- D := Distance( APoint, BusyEnd ); { set distance }
- RotDelta := -RotDelta; { reverse direction of rotation }
- Rotate( RotDelta ); { rotate in opposite direction }
- end;
- while D > Distance( APoint, BusyEnd ) do begin
- { new distance should be less than old }
- D := Distance( APoint, BusyEnd );
- Rotate( RotDelta );
- end;
- { stops when Distance starts to get big again }
- RotDelta := -RotDelta;
- Rotate( RotDelta ); { go back one }
- { End of Phase 1 }
- { Phase 2 }
- AxDelta := 4;
- { set distance }
- D := Distance( APoint, BusyEnd );
- MoveAxial( AxDelta ); { move axially }
- if D < Distance( APoint, BusyEnd ) then begin
- D := Distance( APoint, BusyEnd );
- AxDelta := -AxDelta;
- MoveAxial( AxDelta );
- end;
- while D > Distance( APoint, BusyEnd ) do begin
- D := Distance( APoint, BusyEnd );
- MoveAxial( AxDelta );
- end;
- AxDelta := -AxDelta div 2;
- MoveAxial( AxDelta ); { should be here }
- ShowLimit;
- ShowBase;
- { End of Phase 2 }
- end;
-
- procedure RobotArm.ShowBase;
- begin
- with Anchor do
- Graph.PieSlice(X, Y, 268, 272, Round(GetMaxY/2.2));
- end;
-
- procedure RobotArm.ShowLimit;
- begin
- SetColor( red );
- with Anchor do
- Circle( X, Y, Length );
- SetColor( white );
- end;
- end.