<taskModel about="urn:cessna172" xmlns="http://ce.org/cea-2018">
	
	<task id="Fly">
		<subtasks id="flying" ordered="true">
			<step name="conductPreflight" task="ConductPreflight"/>
			<step name="startEngine" task="StartEngine"/>
			<step name="prepareForTakeoff" task="PrepareForTakeoff"/>
			<step name="takeOff" task="TakeOff"/>
			<step name="cruise" task="Cruise"/>
		</subtasks>
	</task>
				
	<task id="ConductPreflight">
		<subtasks id="conductingPreflight">
			<step name="sayBefore" task="Say"/>
			<step name="conductPreflightInspection" task="ConductPreflightInspection"/>
			<step name="briefPassengers" task="BriefPassengers"/>
			<step name="sayAfter" task="Say"/>
			<binding slot="$sayBefore.toSay" value="'We are beginning the pre-flight procedures.'"/>
			<binding slot="$sayAfter.toSay" value="'Great, we just completed our pre-flight procedures.'"/>
		</subtasks>
	</task>
	
	<task id="Say">
		<input name="toSay" type="string"/>
		<script>
			notifyUser($this.toSay);
		</script>
	</task>
	
	<task id="ConductPreflightInspection"/>
	
	<task id="BriefPassengers">
		<script>
			var brief = "Welcome aboard everyone, please buckle your safety belts before we take off.";
		    OrvilleGuide.notifyTaskDoneFromModel("BriefPassengers", brief, "Orville briefed passengers");
		</script>
	</task>
	
	<task id="StartEngine">
		<subtasks id="startingEngine">
			<step name="sayBefore" task="Say"/>
			<step name="adjustMixture" task="AdjustMixture"/>
			<step name="adjustCarbHeat" task="AdjustCarbHeat"/>
			<step name="manipulateIgnition" task="ManipulateIgnition"/>
			<step name="adjustThrottle" task="AdjustThrottle"/>
			<step name="sayAfter" task="Say"/>
			<binding slot="$adjustMixture.percentOxygen" value="10"/>
			<binding slot="$adjustCarbHeat.percentMaxCarbHeat" value="10"/>
		    <binding slot="$adjustThrottle.rpm" value="1000"/>
		    <binding slot="$sayBefore.toSay" value="'We are about to start the engine.'"/>
			<binding slot="$sayAfter.toSay" value="'Good job, we completed starting the engine.'"/>
		</subtasks>
	</task>
	
	<task id="AdjustMixture">
		<output name = "percentOxygen" type="number"/>
		<script>
			var controlCommand = "I sent a " + $this.percentOxygen + " percent oxygen mixture to the control system.";
			var history = "Orville adjusted the mixture to %" + $this.percentOxygen + " oxygen";
		    OrvilleGuide.notifyTaskDoneFromModel("AdjustMixture", controlCommand, history);
		</script>
	</task>
	
	<task id="AdjustCarbHeat">
		<output name="percentMaxCarbHeat" type="number"/>
		<script>
		    var controlCommand = "I sent a " + $this.percentMaxCarbHeat + " percent maximum carb heat setting to the control system.";
			var history = "Orville adjusted max carb heat to %" + $this.percentMaxCarbHeat;
		    OrvilleGuide.notifyTaskDoneFromModel("AdjustCarbHeat", controlCommand, history);
		</script>
	</task>
	
	<task id="ManipulateIgnition">
		<input name="on" type="boolean"/>
	</task>
	
	<task id="AdjustThrottle">
		<output name="rpm" type="number"/>
		<script>
		    var controlCommand = "I sent a " + $this.rpm + " rpm throttle setting to the control system.";
			var history = "Orville adjusted throttle to " + $this.rpm + " rpms";
		    OrvilleGuide.notifyTaskDoneFromModel("AdjustThrottle", controlCommand, history);
		</script>
	</task>

	<task id="AdjustFlaps">
		<output name="flapAngle" type="number"/>
		<script>
		    var controlCommand = "I sent a " + $this.flapAngle + " degree flap angle to the control system.";
			var history = "Orville adjusted the flap angle to " + $this.flapAngle + " degrees";
		    OrvilleGuide.notifyTaskDoneFromModel("AdjustFlaps", controlCommand, history);
		</script>
	</task>
	
	<task id="PrepareForTakeoff">
		<subtasks id="preparingForTakeoff">
			<step name="sayBefore" task="Say"/>
			<step name="adjustThrottle" task="AdjustThrottle"/>
			<step name="checkInstruments" task="CheckInstruments"/>
			<step name="adjustFlaps" task="AdjustFlaps"/>
			<step name="contactAirTrafficControl" task="ContactAirTrafficControl"/>
			<step name="sayAfter" task="Say"/>
			<binding slot="$adjustThrottle.rpm" value="1800"/>
			<binding slot="$adjustFlaps.flapAngle" value="5"/>
			<binding slot="$sayBefore.toSay" value="'We are starting to prepare for takeoff.  We will increase the engine power, and check our instruments.'"/>
			<binding slot="$sayAfter.toSay" value="'Excellent, we are finished preparing for takeoff.'"/>
		</subtasks>
	</task>
	
	<task id="CheckInstruments"/>
	
	<task id="ContactAirTrafficControl">
		<script>
			var contactString = "Air traffic control, this is Orville flying aircraft niner bravo alpha whiskey. We are ready for takeoff.";
		    OrvilleGuide.notifyTaskDoneFromModel("ContactAirTrafficControl", contactString, "Orville contacted air traffic control");
		</script>
	</task>
	
	<task id="TakeOff">
		<subtasks id="conductingTakeOff">
			<step name="sayBefore" task="Say"/>
			<step name="adjustTrim" task="AdjustTrim"/>
			<step name="adjustThrottle" task="AdjustThrottle"/>
			<step name="adjustElevator" task="AdjustElevator"/>
			<step name="sayAfter" task="Say"/>
			<binding slot="$adjustThrottle.rpm" value="5000"/>
			<binding slot="$adjustTrim.trimAngle" value="10"/>
			<binding slot="$adjustElevator.elevatorAngle" value="45"/>
			<binding slot="$sayBefore.toSay" value="'We are about to take off.'"/>
			<binding slot="$sayAfter.toSay" value="'We are looking good, we are up in the air.'"/>
		</subtasks>
	</task>
	
	<task id="AdjustTrim">
		<output name="trimAngle" type="number"/>
		<script>
		    var controlCommand = "I sent a " + $this.trimAngle + " degree trim angle to the control system.";
			var history = "Orville adjusted the trim angle to " + $this.trimAngle + " degrees";
		    OrvilleGuide.notifyTaskDoneFromModel("AdjustTrim", controlCommand, history);
		</script>
	</task>
	
	<task id="AdjustElevator">
		<output name="elevatorAngle" type="number"/>
		<script>
		    var controlCommand = "I sent a " + $this.elevatorAngle + " degree elevator angle to the control system.";
			var history = "Orville adjusted elevator angle to " + $this.elevatorAngle + " degrees";
		    OrvilleGuide.notifyTaskDoneFromModel("AdjustElevator", controlCommand, history);
		</script>
	</task>

	<task id="Cruise">
		<subtasks id="cruising" ordered="false">
			<step name="sayBefore" task="Say"/>
			<step name="adjustElevator" task="AdjustElevator"/>
			<step name="adjustThrottle" task="AdjustThrottle"/>
			<step name="adjustTrim" task="AdjustTrim"/>
			<step name="adjustMixture" task="AdjustMixture"/>
			<binding slot="$adjustElevator.elevatorAngle" value="10"/>
			<binding slot="$adjustThrottle.rpm" value="3000"/>
			<binding slot="$adjustTrim.trimAngle" value="5"/>
			<binding slot="$adjustMixture.percentOxygen" value="25"/>
			<binding slot="$sayBefore.toSay" value="'Everything is going great, we are about to adjust the aircraft controls for cruising.'"/>
		</subtasks>
	</task>
	
	<script init="true">

		importClass(Packages.orville.guide.OrvilleGuide);
		
		function notifyUser(notification){
			OrvilleGuide.getInstance().informUserFromModel(notification);
		}

	</script>
	
</taskModel>