WITH TEXT_IO ; USE TEXT_IO ; -- setup standard text I/O package WITH robot_handler ; USE robot_handler ; -- setup robot package PROCEDURE robdemo2 IS -- demonstrates use of robot simulation package -- Type Definitions : TYPE command IS ( x_move, y_move, z_move, compound, quit ) ; TYPE conv_com IS ARRAY ( x_move..z_move ) OF axis_name ; -- Generic Package Instantiations : PACKAGE com_io IS NEW ENUMERATION_IO ( command ) ; PACKAGE mr_io IS NEW INTEGER_IO ( move_range ) ; PACKAGE an_IO IS NEW ENUMERATION_IO ( axis_name ) ; USE com_io, mr_io, an_io ; -- Global Constants : axis_for : CONSTANT conv_com := ( x_axis, y_axis, z_axis ) ; -- Global Variables : type_of_move : command ; -- type of move to perform move_params : param_array ; -- parameters for specified move marvin : robot_controller ; -- simulated robot -- Inline Procedure Definitions : PROCEDURE putln ( text : STRING ) ; PRAGMA INLINE ( putln ) ; -- putln => output a string followed by a newline PROCEDURE putln ( text : STRING ) IS BEGIN -- putln PUT ( text ) ; NEW_LINE ; END putln ; -------------------------------------------------------- -- get_move_command => obtain movement specification from user PROCEDURE get_move_command ( move_com : OUT command ; params : OUT param_array ) IS -- Local Variables : move_type : command ; -- used locally, returned in move_com -- Local Functions : -- get_param => obtain an integer parameter value FUNCTION get_param ( axis : axis_name ) RETURN move_range IS -- Local Variables : param : move_range ; -- local value of returned result BEGIN -- get_param PUT ( "? Move " ) ; -- form prompt PUT ( axis ) ; PUT ( " by how many units : " ) ; GET ( param ) ; -- get & return parameter value RETURN param ; EXCEPTION -- try to trap bad data input -- Method : -- Inform user of appropriate range of integers available then use -- get_param recursively to obtain a new parameter value. WHEN data_error | numeric_error => SKIP_LINE ; -- skip over rest of input line PUT ( "Please give an integer in the range " ) ; PUT ( move_range'FIRST ) ; PUT ( " to " ) ; PUT ( move_range'LAST ) ; NEW_LINE ; param := get_param ( axis ) ; RETURN param ; END get_param ; ------------------------------------------------- BEGIN -- get_move_command PUT ( "? Type of move required : " ) ; -- prompt user GET ( move_type ) ; -- get type of move move_com := move_type ; -- transfer to OUT parameter -- for all single axis moves just get a single parameter but for the -- compound move get a parameter for each axis CASE move_type IS WHEN x_move | y_move | z_move => params ( axis_for ( move_type ) ) := get_param ( axis_for ( move_type ) ) ; WHEN compound => FOR axis IN axis_name LOOP -- get parameters for all axes params ( axis ) := get_param ( axis ) ; END LOOP ; WHEN quit => NULL ; -- do nothing END CASE ; EXCEPTION -- try to trap bad movement specifications -- Method : -- inform user of options and then use get_move_command recursively to -- get the movement type and parameters WHEN data_error => SKIP_LINE ; -- skip over rest of input line putln ( "! Error : Invalid movement specification. " ) ; putln ( "Enter x_move, y_move, z_move, compound or quit." ) ; get_move_command ( move_com, params ) ; END get_move_command ; --------------------------------------------- BEGIN -- robdemo2 -- initialise robot system & robot marvin robot_system.open ; marvin.open ; LOOP -- loop indefinately get_move_command ( type_of_move, move_params ) ; -- get move spec -- treat single axis & compound moves differently CASE type_of_move IS WHEN x_move | y_move | z_move => PUT ( axis_for ( type_of_move ) ) ; PUT ( " move : param = " ) ; PUT ( move_params ( axis_for ( type_of_move ) ) ) ; NEW_LINE ; -- make move marvin.single_axis_move ( axis_for ( type_of_move ), move_params ( axis_for ( type_of_move ) ) ) ; WHEN compound => PUT ( "Compound move : params ( x : y : z ) = " ) ; PUT ( move_params ( x_axis ) ) ; PUT ( " : " ) ; PUT ( move_params ( y_axis ) ) ; PUT ( " : " ) ; PUT ( move_params ( z_axis ) ) ; NEW_LINE ; -- make compound move marvin.compound_move ( move_params ) ; WHEN quit => -- shut down Robot marvin.close ; NEW_LINE ; putln ( "robdemo2 terminating." ) ; EXIT ; -- exit command processing loop END CASE ; END LOOP ; -- end of command processing loop -- terminate robot system robot_system.close ; END robdemo2 ; ---------------------------------------------------------