home *** CD-ROM | disk | FTP | other *** search
- unit Robot_A;
-
- interface
-
- uses Graph, Mouse, Crt, RobotSeg;
-
- type
-
- RobotArm = object( Segment )
- constructor Init( AnchorX, AnchorY, ArmLen : Integer;
- Position : Degrees;
- RotStat, DispQ : Boolean );
- procedure MoveTo( APoint : Point; ShowQ : boolean );
- procedure ShowBase;
- procedure ShowLimit; virtual;
- end;
-
- implementation
-
- constructor RobotArm.Init( AnchorX, AnchorY, ArmLen : Integer;
- Position : Degrees;
- RotStat, DispQ : Boolean );
- begin
- Segment.Init( AnchorX, AnchorY, ArmLen, Position, RotStat );
- if DispQ = true then
- begin
- Show;
- ShowBase;
- end;
- end;
-
- procedure RobotArm.MoveTo( APoint : Point; ShowQ : boolean );
-
- var D : real;
- RotDelta : integer;
- AxDelta : integer;
- begin
- if RotateQ = true then begin
- 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;
- 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 }
- if ShowQ = true then
- begin
- ShowLimit;
- ShowBase;
- end;
- 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.