----------------------------------------------------------------------------
-- Cell-Machine Interface
--
-- Feb, 1995   (Defined by RoadRobot Team
--		Written by Teresa Goncalves, Joao Paulo Pimentao - Uninova)
----------------------------------------------------------------------------

----------------------------------------------------------------------------
-- Cell-Machine Interface (messages) ---------------------------------------
----------------------------------------------------------------------------
ENTITY cell_to_machine_message
	ABSTRACT SUPERTYPE OF(
		ONEOF( cell_to_machine_command, cell_to_machine_task))
	SUBTYPE OF (message);
END_ENTITY;

ENTITY cell_to_machine_task
	ABSTRACT SUPERTYPE OF(
		ONEOF ( cell_to_paver_task, cell_to_excavator_task, 
			cell_to_lorryDriver_task ))
	SUBTYPE OF (cell_to_machine_message);
	start,
	finish:	GMTTime;
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (paver tasks) ------------------------------------
----------------------------------------------------------------------------
ENTITY cell_to_paver_task
	ABSTRACT SUPERTYPE OF (ONEOF (move_to, pave, complex_pave))
	SUBTYPE OF (cell_to_machine_task);
END_ENTITY;

ENTITY move_to
	SUBTYPE OF (cell_to_paver_task);
	location:	base_position; -- x, y, z, and orientation (degrees from north)
END_ENTITY;

ENTITY pave
	SUBTYPE OF (cell_to_paver_task);
	geometry:	road_geometry;
	work_rate:	working_rate;
	quality:	quality_parameters;
	paving_material:	asphalt_mixture;
	layer_def:	: asphalt_layer;
END_ENTITY;

ENTITY complex_pave
	SUBTYPE OF (cell_to_paver_task);
	geometry:	road_geometry_list;
	work_rate:	working_rate;
	quality:	quality_parameters;
	paving_material:	asphalt_mixture;
	layer_def:	: asphalt_layer;
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (excavator tasks) --------------------------------
----------------------------------------------------------------------------
ENTITY cell_to_excavator_task
	ABSTRACT SUPERTYPE OF (excavate)
	SUBTYPE OF (cell_to_machine_task);
END_ENTITY;

ENTITY excavate
	SUBTYPE OF (cell_to_excavator_task);
	profile:	excavating_surface_topography;
	aimed_profile:	excavating_final_profile;
	tool_type:	Machine_Tool;
	first_point:	base_position;
	second_point:	unload_point;
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (lorryDriver tasks) ------------------------------
----------------------------------------------------------------------------
ENTITY cell_to_lorryDriver_task
	ABSTRACT SUPERTYPE OF (ONEOF (fill, dump, dock, lorry_move_to))
	SUBTYPE OF (cell_to_machine_task);
END_ENTITY;

ENTITY fill
	SUBTYPE OF (cell_to_lorryDriver_task);
END_ENTITY;

ENTITY dump
	SUBTYPE OF (cell_to_lorryDriver_task);
END_ENTITY;

ENTITY dock
	SUBTYPE OF (cell_to_lorryDriver_task);
END_ENTITY;

ENTITY lorry_move_to
	SUBTYPE OF (cell_to_lorryDriver_task);
	location:	base_position; -- x, y, z, and orientation (degrees from north)
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (commands) ---------------------------------------
----------------------------------------------------------------------------
ENTITY cell_to_machine_command
	ABSTRACT SUPERTYPE OF ( ONEOF (cell_to_machine_applIndep_command,
		cell_to_paver_command, cell_to_excavator_command,
		cell_to_lorryDriver_command))
	SUBTYPE OF (cell_to_machine_message);
END_ENTITY;

ENTITY cell_to_machine_applIndep_command
	ABSTRACT SUPERTYPE OF ( ONEOF ( command_link_active,
		start_next_task, start_task, clear_all_tasks, fast_stop, 
		pause_task, resume_task, query_machine_status, query_tool_status, 
		grant_local_control, grant_remote_control, clear_task, 
		insert_task, modify))
	SUBTYPE OF (cell_to_machine_command);
END_ENTITY;

ENTITY cell_to_excavator_command
	SUBTYPE OF (cell_to_machine_command);
END_ENTITY;

ENTITY cell_to_lorryDriver_command
	SUBTYPE OF (cell_to_machine_command);
END_ENTITY;

ENTITY cell_to_paver_command
	ABSTRACT SUPERTYPE OF (foresee_lack_of_asphalt)
	SUBTYPE OF (cell_to_machine_command);
END_ENTITY;

ENTITY command_link_active
	SUBTYPE OF (cell_to_machine_applIndep_command);
END_ENTITY;

ENTITY start_next_task
	SUBTYPE OF (cell_to_machine_applIndep_command);
END_ENTITY;

ENTITY start_task
	SUBTYPE OF (cell_to_machine_applIndep_command);
	task_id: StepID;
END_ENTITY;

ENTITY clear_all_tasks
	SUBTYPE OF (cell_to_machine_applIndep_command);
END_ENTITY;

ENTITY fast_stop 
	SUBTYPE OF (cell_to_machine_applIndep_command);
END_ENTITY;

ENTITY pause_task
	SUBTYPE OF (cell_to_machine_applIndep_command);
END_ENTITY;

ENTITY resume_task
	SUBTYPE OF (cell_to_machine_applIndep_command);
END_ENTITY;

ENTITY query_machine_status
	SUBTYPE OF (cell_to_machine_applIndep_command);
END_ENTITY;

ENTITY query_tool_status
	SUBTYPE OF (cell_to_machine_applIndep_command);
	tool_id: StepID;
END_ENTITY;

ENTITY grant_local_control
	SUBTYPE OF (cell_to_machine_applIndep_command);
END_ENTITY;

ENTITY grant_remote_control
	SUBTYPE OF (cell_to_machine_applIndep_command);
END_ENTITY;

ENTITY clear_task
	SUBTYPE OF (cell_to_machine_applIndep_command);
	task_id:    StepID;
END_ENTITY;

ENTITY insert_task
	SUBTYPE OF (cell_to_machine_applIndep_command);
	after_task_id:	StepID;
	task_description: LIST [1:?] OF STRING; -- Strings in Neutral File Format
END_ENTITY;

ENTITY modify
	SUBTYPE OF (cell_to_machine_applIndep_command);
	object_modifications:	obj_mod;
	new_object_description: LIST [1:?] OF STRING; -- Strings in Neutral File Format
END_ENTITY;

ENTITY foresee_lack_of_asphalt
	SUBTYPE OF (cell_to_paver_command);
	within:	Time; -- Time till lack of asphalt
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (responses) --------------------------------------
----------------------------------------------------------------------------
ENTITY machine_to_cell_response
	ABSTRACT SUPERTYPE OF (
		ONEOF( machine_to_cell_applIndep_response, 
			paver_to_cell_applDep_response,
                        excavator_to_cell_applDep_response,
                        lorryDriver_to_cell_applDep_response))
	SUBTYPE OF (response);
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (application independent responses) --------------
----------------------------------------------------------------------------
ENTITY machine_to_cell_applIndep_response
	ABSTRACT SUPERTYPE OF ( ONEOF (task_completed,
                task_aborted, task_list_is_empty, task_already_being_executed,
                fast_stop_completed, no_task_being_executed,
                foresee_task_conclusion, task_is_paused, request_local_control,
                request_remote_control, machine_absent, machine_present,
		application_error, communication_link_down, in_local_control,
                in_remote_control, tool_status, tool_invalid, tool_error,
                task_description_unavailable, task_cleared,
                task_paused, task_resumed, no_task_suspended,
                task_inserted, object_modified, inconsistent_object,
                object_unavailable))

	SUBTYPE OF (machine_to_cell_response);
END_ENTITY;


ENTITY task_completed
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY task_aborted
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY task_list_is_empty
	SUBTYPE OF (machine_to_cell_applIndep_response);
END_ENTITY;

ENTITY task_already_being_executed
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY fast_stop_completed
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY no_task_being_executed
	SUBTYPE OF (machine_to_cell_applIndep_response);
END_ENTITY;

ENTITY foresee_task_conclusion
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
	estimated_duration:	Time;
END_ENTITY;

ENTITY task_is_paused
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
	estimated_duration:	Time;
END_ENTITY;

ENTITY request_local_control
	SUBTYPE OF (machine_to_cell_applIndep_response);
END_ENTITY;

ENTITY request_remote_control
	SUBTYPE OF (machine_to_cell_applIndep_response);
END_ENTITY;

ENTITY machine_absent
	SUBTYPE OF (machine_to_cell_applIndep_response);
	machine_id:	StepID;
END_ENTITY;

ENTITY machine_present
	SUBTYPE OF (machine_to_cell_applIndep_response);
	machine_id:	StepID;
	machine_type:	Machine;
END_ENTITY;

ENTITY application_error
	SUBTYPE OF (machine_to_cell_applIndep_response);
	error_code: INTEGER;
END_ENTITY;

ENTITY communication_link_down
	SUBTYPE OF (machine_to_cell_applIndep_response);
END_ENTITY;

ENTITY in_local_control
	SUBTYPE OF (machine_to_cell_applIndep_response);
END_ENTITY;

ENTITY in_remote_control
	SUBTYPE OF (machine_to_cell_applIndep_response);
END_ENTITY;

TYPE ToolStatus = ENUMERATION OF ( ok, error, off);
-- TYPE ToolStatus = ENUMERATION OF ( 1, 2, 3);
END_TYPE;

ENTITY tool_status
	SUBTYPE OF (machine_to_cell_applIndep_response);
	tool_id:	StepID;
	status:	ToolStatus;
	tool_parameters: STRING;
END_ENTITY;

ENTITY tool_invalid
	SUBTYPE OF (machine_to_cell_applIndep_response);
	tool_id:	StepID;
END_ENTITY;

ENTITY tool_error
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
	tool_id:	StepID;
	tool_error_code: INTEGER;
END_ENTITY;

		task_description_unavailable, task_cleared,
		task_paused, task_resumed, no_task_suspended,
		task_inserted, object_modified, inconsistent_object, 
		object_unavailable))
ENTITY task_description_unavailable
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY task_cleared
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY task_paused
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY task_resumed
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY no_task_suspended
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY task_inserted
	SUBTYPE OF (machine_to_cell_applIndep_response);
	task_id:	StepID;
END_ENTITY;

ENTITY object_modified
	SUBTYPE OF (machine_to_cell_applIndep_response);
	obj_id:	StepID;
END_ENTITY;

ENTITY inconsistent_object
	SUBTYPE OF (machine_to_cell_applIndep_response);
	list_id:	LIST [1:?] OF StepID;
END_ENTITY;

ENTITY object_unavailable
	SUBTYPE OF (machine_to_cell_applIndep_response);
	obj_id:	StepID;
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (paver responses) --------------------------------
----------------------------------------------------------------------------
ENTITY paver_to_cell_applDep_response
	ABSTRACT SUPERTYPE OF (asphalt_missing)
	SUBTYPE OF (machine_to_cell_response);
END_ENTITY;

ENTITY asphalt_missing
	SUBTYPE OF (paver_to_cell_applDep_response);
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (lorryDriver responses) --------------------------
----------------------------------------------------------------------------
ENTITY lorryDriver_to_cell_applDep_response
	SUBTYPE OF (machine_to_cell_response);
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (excavator responses) ----------------------------
----------------------------------------------------------------------------
ENTITY excavator_to_cell_applDep_response
 	ABSTRACT SUPERTYPE OF (ONEOF (location_inaccessible,
		orientation_unobtainable, inadequate_tool,
		answer_to_excavating_task))
	SUBTYPE OF (machine_to_cell_response);
END_ENTITY;

ENTITY location_inaccessible
	SUBTYPE OF (excavator_to_cell_applDep_response);
END_ENTITY;

ENTITY orientation_unobtainable
	SUBTYPE OF (excavator_to_cell_applDep_response);
END_ENTITY;

ENTITY inadequate_tool
	SUBTYPE OF (excavator_to_cell_applDep_response);
	tool_id:	StepID;
END_ENTITY;

ENTITY answer_to_excavating_task
	SUBTYPE OF (excavator_to_cell_applDep_response);
	operation_possible:     INTEGER;
	--operation_possible:     BOOLEAN;
END_ENTITY;

----------------------------------------------------------------------------
-- Cell-Machine Interface (tasks  commands )
----------------------------------------------------------------------------