<?xml version='1.0' encoding='utf-8'?>
<root version="20190819">
    <world>
        <walls>
            <wall begin="150:100" stroke-style="none" stroke="#ff000000" id="{a031e1ec-73c8-480a-b8d1-0eb812d22a2a}" fill="#ff000000" end="150:250" stroke-width="10"/>
            <wall begin="150:250" stroke-style="none" stroke="#ff000000" id="{04da9c64-ffcd-4124-b4d7-d8be7dee0eee}" fill="#ff000000" end="300:250" stroke-width="10"/>
            <wall begin="300:100" stroke-style="none" stroke="#ff000000" id="{0ee11790-2eac-4f00-87c8-f1036fcb39c6}" fill="#ff000000" end="300:250" stroke-width="10"/>
        </walls>
        <skittles/>
        <balls/>
        <colorFields>
            <ellipse fill-style="none" stroke-style="solid" fill="#ffff0000" id="{3e42264b-eb67-4ddf-a79a-ea2c11086852}" stroke-width="6" begin="-20:-20" end="70:70" stroke="#ffff0000"/>
        </colorFields>
        <images/>
        <regions>
			<region filled="true" y="-50" width="150" visible="false" id="start_zone" type="rectangle" textY="0" x="-50" text="Start" height="150" color="red" textX="0"/>
			<region filled="true" y="100" width="150" visible="true" id="finish" type="rectangle" textY="0" x="150" text="Finish" height="150" color="blue" textX="0"/>
			<region filled="true" y="-50" width="200" visible="true" id="good_zone1" type="rectangle" textY="0" x="-50" text="Поле, которое нельзя покидать" height="150" color="green" textX="0"/>
			<region filled="true" y="-200" width="150" visible="true" id="good_zone2" type="rectangle" textY="0" x="150" text="Поле, которое нельзя покидать" height="450" color="green" textX="0"/>

		</regions>
    </world>
    <robots>
        <robot position="0:0" id="trikKitRobot" direction="0">
            <sensors>
                <sensor position="75:25" port="E4###input###M4$$$Е4###encoder4" direction="0" type="kitBase::robotModel::robotParts::EncoderSensor"/>
                <sensor position="75:25" port="E3###input###M3$$$Е3###encoder3" direction="0" type="kitBase::robotModel::robotParts::EncoderSensor"/>
                <sensor position="75:25" port="M3###output###М3###" direction="0" type="kitBase::robotModel::robotParts::Motor"/>
                <sensor position="75:25" port="M4###output###М4###" direction="0" type="kitBase::robotModel::robotParts::Motor"/>
            </sensors>
            <startPosition x="25" id="{42cdab79-3498-4a55-858e-a24209f5ef7a}" direction="0" y="25"/>
            <wheels left="M4###output###М4###" right="M3###output###М3###"/>
        </robot>
    </robots>
    <settings realisticSensors="false" realisticPhysics="false" realisticMotors="false"/>
	<constraints>
        <timelimit value="20000"/>
		<!-- Провека, что нет датчиков-->
        <constraint failMessage="У робота не должно быть датчиков" checkOnce="true">
            <conditions glue="and">
				<equals>
                    <typeOf objectId="robot1.A1"/>
                    <string value="undefined"/>
                </equals>
				<equals>
                    <typeOf objectId="robot1.A2"/>
                    <string value="undefined"/>
                </equals>
                <equals>
                    <typeOf objectId="robot1.A3"/>
                    <string value="undefined"/>
                </equals>
                <equals>
                    <typeOf objectId="robot1.A4"/>
                    <string value="undefined"/>
                </equals>
                <equals>
                    <typeOf objectId="robot1.A6"/>
                    <string value="undefined"/>
                </equals>
                <equals>
                    <typeOf objectId="robot1.D1"/>
                    <string value="undefined"/>
                </equals>
                <equals>
                    <typeOf objectId="robot1.D2"/>
                    <string value="undefined"/>
                </equals>
                <equals>
                    <typeOf objectId="robot1.F1"/>
                    <string value="undefined"/>
                </equals>
            </conditions>
        </constraint>
		<!-- Зональное ограничение на начало езды. Проверяется один раз в начале программы-->
        <constraint checkOnce="true" failMessage="Робот должен находиться в красном круге перед запуском!">
            <inside regionId="start_zone" objectId="robot1"/>
        </constraint>
		
		<constraint failMessage="Робот покинул допустимую зону!">
			<conditions glue="or">
				<inside objectId="robot1" regionId="good_zone1"/>
				<inside objectId="robot1" regionId="good_zone2"/>
			</conditions>
        </constraint>
		<!-- Событие, которое выдает ошибку, если робот не тронулся с места в первую секунду -->
        <event settedUpInitially="true" id="Waiting for going forward too long">
            <conditions glue="and">
                <timer forceDropOnTimeout="true" timeout="1000"/>
                <settedUp id="We are alive, first move"/>
            </conditions>
            <trigger>
                <fail message="Робот так и не поехал в первую секунду"/>
            </trigger>
        </event>
        <!-- Событие, которое говорит о том, что робот начал двигаться. Мощность на одном из моторов больше 0. Запускается цепочка проверок -->
        <event settedUpInitially="true" id="We are alive, first move">
            <conditions glue="or">
                <notEquals>
                    <objectState object="robot1.M3.power"/>
                    <int value="0"/>
                </notEquals>
                <notEquals>
                    <objectState object="robot1.M4.power"/>
                    <int value="0"/>
                </notEquals>
            </conditions>
            <triggers>
                <setUp id="back way"/>
            </triggers>
        </event>
		<!-- Событие, проверяющее, что робот начал ехать назад -->
        <event id="back way">
            <conditions glue="and">
                <equals>
                    <objectState object="robot1.M3.power"/>
                    <objectState object="robot1.M4.power"/>
                </equals>
                <less>
                    <objectState object="robot1.M4.power"/>
                    <int value="0"/>
                </less>
            </conditions>
            <triggers>
                <setter name="led color">
                    <objectState object="robot1.led.color"/>
                </setter>
                <setUp id="color led change"/>
            </triggers>
        </event>
		
		<!-- Событие, проверяющее, что цвет диода изменился -->
        <event id="color led change">
            <conditions glue="and">
                <notEquals>
                    <objectState object="robot1.led.color"/>
                    <variableValue name="led color"/>
                </notEquals>
            </conditions>
            <triggers>
                <setter name="led color">
                    <objectState object="robot1.led.color"/>
                </setter>
                <setUp id="color led change true"/>
            </triggers>
        </event>
		
		<!-- Событие, проверяющее, что цвет диода изменился -->
        <event id="color led change true">
            <conditions glue="and">
                <notEquals>
                    <objectState object="robot1.led.color"/>
                    <variableValue name="led color"/>
                </notEquals>
            </conditions>
            <triggers>
                <setter name="led color">
                    <objectState object="robot1.led.color"/>
                </setter>
                <setUp id="finish checker"/>
            </triggers>
        </event>
		<!--  Событие, которое выдает ошибку, если робот в зоне финиша и остановился, но цвет диода не менялся -->
		<event id="color led change false" settedUpInitially="true">
            <conditions glue="and">
                <conditions glue="or">
					<settedUp id="color led change true"/>
					<settedUp id="color led change"/>
				</conditions>
				<inside regionId="finish" objectId="robot1"/>
                <equals>
                    <objectState object="robot1.M3.power"/>
                    <objectState object="robot1.M4.power"/>
                </equals>
                <equals>
                    <objectState object="robot1.M4.power"/>
                    <int value="0"/>
                </equals>
            </conditions>
            <triggers>
                <fail message="Робот должен мигать диодом"/>
            </triggers>
        </event>
		
		<!-- Событие, проверяющее, что робот остановился в зоне финиша -->
        <event id="finish checker">
            <conditions glue="and">
				<notGreater>
					<objectState object="robot1.rotation"/>
                    <int value="-85"/>
				</notGreater>
                <inside objectId="robot1" regionId="finish"/>
                <equals>
                    <objectState object="robot1.M3.power"/>
                    <objectState object="robot1.M4.power"/>
                </equals>
                <equals>
                    <objectState object="robot1.M4.power"/>
                    <int value="0"/>
                </equals>
            </conditions>
            <triggers>
                <setUp id="stop task true"/>
				<setUp id="stop task false"/>
				<setter name="led color">
                    <objectState object="robot1.led.color"/>
                </setter>
            </triggers>
        </event>
		<!-- Событие, проверяющее, что после остановки робот перестал мигать диодом -->
	    <event id="stop task true">
            <conditions glue="and">
				<timer forceDropOnTimeout="true" timeout="1900"/>
                <equals>
                    <objectState object="robot1.led.color"/>
                    <variableValue name="led color"/>
                </equals>
            </conditions>
            <triggers>
                <success/>
            </triggers>
        </event> 
		<!-- Событие, которое выдает ошибку, если после остановки робот НЕ перестал мигать диодом -->
	    <event id="stop task false">
            <condition>
                <notEquals>
                    <objectState object="robot1.led.color"/>
                    <variableValue name="led color"/>
                </notEquals>
            </condition>
            <triggers>
                <fail message="Робот должен завершить задачу, отвечающую за мигание диодом"/>
            </triggers>
        </event> 
	</constraints>
</root>
