<?xml version='1.0' encoding='utf-8'?>
<root version="20190819">
    <world>
        <walls>
            <wall stroke="#ff000000" stroke-style="none" stroke-width="10" id="{a031e1ec-73c8-480a-b8d1-0eb812d22a2a}" fill="#ff000000" end="150:400" begin="150:250"/>
            <wall stroke="#ff000000" stroke-style="none" stroke-width="10" id="{04da9c64-ffcd-4124-b4d7-d8be7dee0eee}" fill="#ff000000" end="300:400" begin="150:400"/>
            <wall stroke="#ff000000" stroke-style="none" stroke-width="10" id="{0ee11790-2eac-4f00-87c8-f1036fcb39c6}" fill="#ff000000" end="300:400" begin="300:250"/>
        </walls>
        <skittles/>
        <balls/>
        <colorFields>
            <ellipse stroke="#ffff0000" fill-style="none" stroke-style="solid" stroke-width="6" id="{3e42264b-eb67-4ddf-a79a-ea2c11086852}" fill="#ffff0000" end="70:70" begin="-20:-20"/>
        </colorFields>
        <images/>
        <regions>
            <region type="rectangle" text="Start" filled="true" y="-50" color="#ff0000" height="150" textX="0" visible="false" width="150" x="-50" textY="0" id="start_zone"/>
            <region type="rectangle" text="Поле, которое нельзя покидать" filled="true" y="-200" color="#008000" height="600" textX="0" visible="true" width="150" x="150" textY="0" id="good_zone2"/>
            <region type="rectangle" text="Finish" filled="true" y="300" color="#0000ff" height="100" textX="0" visible="true" width="150" x="150" textY="0" id="finish"/>
            <region type="rectangle" text="Поле, которое нельзя покидать" filled="true" y="-50" color="#008000" height="150" textX="0" visible="true" width="200" x="-50" textY="0" id="good_zone1"/>
        </regions>
    </world>
    <robots>
        <robot position="0:0" direction="0" id="trikKitRobot">
            <sensors>
                <sensor type="kitBase::robotModel::robotParts::Motor" position="75:25" direction="0" port="M3###output###М3###"/>
                <sensor type="trik::robotModel::parts::TrikInfraredSensor" position="25:25" direction="180" port="A1###input###А1###sensorA1"/>
                <sensor type="kitBase::robotModel::robotParts::EncoderSensor" position="75:25" direction="0" port="E3###input###M3$$$Е3###encoder3"/>
                <sensor type="kitBase::robotModel::robotParts::EncoderSensor" position="75:25" direction="0" port="E4###input###M4$$$Е4###encoder4"/>
                <sensor type="kitBase::robotModel::robotParts::Motor" position="75:25" direction="0" port="M4###output###М4###"/>
            </sensors>
            <startPosition y="25" direction="0" x="25" id="{4aab4cbe-151c-46cb-b3cc-044822709134}"/>
            <wheels left="M4###output###М4###" right="M3###output###М3###"/>
        </robot>
    </robots>
    <settings realisticPhysics="false" realisticSensors="false" realisticMotors="false"/>
    <constraints>
        <timelimit value="20000"/>
        <!-- Провека, что нет датчиков-->
        <constraint failMessage="У робота не должно быть датчиков, кроме ИК датчика на порту А1" checkOnce="true">
            <conditions glue="and">
                <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>
        <!-- Проверка, что на порт А1 установлен датчик расстояния -->
        <constraint failMessage="У робота должен быть установлен датчик расстояния на порт А1" checkOnce="true">
            <conditions glue="and">
                <equals>
                    <typeOf objectId="robot1.A1"/>
                    <string value="twoDModel::robotModel::parts::RangeSensor"/>
                </equals>
            </conditions>
        </constraint>
        <!-- Зональное ограничение на начало езды. Проверяется один раз в начале программы-->
        <constraint failMessage="Робот должен находиться в красном круге перед запуском!" checkOnce="true">
            <inside objectId="robot1" regionId="start_zone"/>
        </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 timeout="1000" forceDropOnTimeout="true"/>
                <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"/>
				<setUp id="say something"/>
				<setUp id="robot say wrong words"/>
				<setUp id="robot say wrong empty"/>
            </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 400"/>
                <setUp id="color led 400 false"/>
                <setUp id="sensor checker"/>
                <setUp id="color led less false"/>
				<setUp id="color led less true"/>
            </triggers>
        </event>
        <!-- Событие, проверяющее, что робот сказал что-то -->
        <event id="say something">
            <conditions glue="or">
                <equals>
                    <objectState object="robot1.shell.lastPhrase"/>
                    <string value="Осторожно"/>
                </equals>
				<equals>
                    <objectState object="robot1.shell.lastPhrase"/>
                    <string value="Двигаюсь назад"/>
                </equals>
            </conditions>
            <triggers>
                <setter name="words">
                    <objectState object="robot1.shell.lastPhrase"/>
                </setter>
				<setUp id="robot say 600"/>
				<setUp id="robot say 600 false"/>
				<setUp id="robot say less true"/>
				<setUp id="robot say less false"/>
            </triggers>
        </event>

		<!-- Событие, проверяющее, что робот продолжает говорить каждые 600 мс -->
        <event id="robot say 600">
            <conditions glue="and">
                <timer timeout="600" forceDropOnTimeout="true"/>
                <notEquals>
                    <objectState object="robot1.shell.lastPhrase"/>
                    <variableValue name="words"/>
                </notEquals>
            </conditions>
            <triggers>
                <setter name="words">
                    <objectState object="robot1.shell.lastPhrase"/>
                </setter>
				<setUp id="robot say 600"/>
				<setUp id="robot say 600 false"/>
				<setUp id="robot say less true"/>
				<setUp id="robot say less false"/>
            </triggers>
        </event>
		<!-- Событие, которое выдает ошибку, если робот ничего не сказал через 600 мс -->
        <event id="robot say 600 false">
            <conditions glue="and">
                <timer timeout="600" forceDropOnTimeout="true"/>
                <equals>
                    <objectState object="robot1.shell.lastPhrase"/>
                    <variableValue name="words"/>
                </equals>
            </conditions>
            <triggers>
                <fail message="Робот должен произносить фразу каждые 600 мс"/>
            </triggers>
        </event> 
		<!-- Событие, которое проверяет, что робот говорит новую фразу не раньше, чем через 600 мс -->
        <event id="robot say less false">
            <conditions glue="and">
                <notEquals>
                    <objectState object="robot1.shell.lastPhrase"/>
                    <variableValue name="words"/>
                </notEquals>
            </conditions>
            <triggers>
                <fail message="Робот должен сказать новую фразу через 600 мс, а не раньше"/>
            </triggers>
        </event>
		<event id="robot say less true">
            <conditions glue="and">
				<timer forceDropOnTimeout="true" timeout="500"/>
            </conditions>
            <triggers>
                <drop id="robot say less false"/>
            </triggers>
        </event>
        <!-- Событие, которое проверяет, что цвет диода не изменился раньше, чем через 400 мс -->
        <event id="color led less false">
            <conditions glue="and">
                <notEquals>
                    <objectState object="robot1.led.color"/>
                    <variableValue name="led color"/>
                </notEquals>
            </conditions>
            <triggers>
                <fail message="Цвет диода должен измениться спустя 400 мс, а не раньше"/>
            </triggers>
        </event>
		<event id="color led less true">
            <conditions glue="and">
				<timer forceDropOnTimeout="true" timeout="300"/>
            </conditions>
            <triggers>
                <drop id="color led less false"/>
            </triggers>
        </event>
        <!-- Событие, проверяющее, что цвет диода изменился спустя 400 мс -->
        <event id="color led 400">
            <conditions glue="and">
                <timer timeout="400" forceDropOnTimeout="true"/>
                <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 400"/>
                <setUp id="color led 400 false"/>
				<setUp id="color led less false"/>
				<setUp id="color led less true"/>
            </triggers>
        </event>
        <!-- Событие, которое выдает ошибку, если цвет диода НЕ изменился спустя 400 мс -->
        <event id="color led 400 false">
            <conditions glue="and">
                <timer timeout="400" forceDropOnTimeout="true"/>
                <equals>
                    <objectState object="robot1.led.color"/>
                    <variableValue name="led color"/>
                </equals>
            </conditions>
            <triggers>
                <fail message="Спутя 400 мс цвет диода должен был измениться"/>
            </triggers>
        </event>
        <!-- Событие, проверяющее значение датчика расстояния -->
        <event id="sensor checker">
            <conditions glue="and">
                <less>
                    <objectState object="robot1.A1.value"/>
                    <int value="30"/>
                </less>
            </conditions>
            <triggers>
                <setUp id="finish checker"/>
            </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>
				<setter name="words">
                    <objectState object="robot1.shell.lastPhrase"/>
                </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>
				<equals>
                    <objectState object="robot1.shell.lastPhrase"/>
                    <variableValue name="words"/>
                </equals>
            </conditions>
            <triggers>
                <success/>
            </triggers>
        </event> 
		<!-- Событие, которое выдает ошибку, если после остановки робот НЕ перестал мигать диодом или говорить -->
	    <event id="stop task false">
            <conditions glue="or">
                <notEquals>
                    <objectState object="robot1.led.color"/>
                    <variableValue name="led color"/>
                </notEquals>
				<notEquals>
                    <objectState object="robot1.shell.lastPhrase"/>
                    <variableValue name="words"/>
                </notEquals>
            </conditions>
            <triggers>
                <fail message="Робот должен завершить задачи, отвечающие за мигание диодом и произношение фраз"/>
            </triggers>
        </event> 
		
		<!-- Событие, которое выдает ошибку, если робот произносит что-то, отличающееся от "осторожно" и "двигаюсь назад" -->
	    <event id="robot say wrong words">
            <conditions glue="and">
				<notEquals>
					<objectState object="robot1.shell.lastPhrase"/>
					<string value="Осторожно"/>
				</notEquals>
				<notEquals>
					<objectState object="robot1.shell.lastPhrase"/>
					<string value="Двигаюсь назад"/>
				</notEquals>
				<notEquals>
					<objectState object="robot1.shell.lastPhrase"/>
					<string value=""/>
				</notEquals>
            </conditions>
            <triggers>
                <fail message="Робот должен говорить только «Осторожно» или «Двигаюсь назад»"/>
            </triggers>
        </event> 
		<event id="robot say wrong empty">
            <conditions glue="and">
				<equals>
					<objectState object="robot1.shell.lastPhrase"/>
					<string value=""/>
				</equals>
            </conditions>
            <triggers>
                <fail message="Робот должен разговаривать и произносить фразы «Осторожно» и «Двигаюсь назад»"/>
            </triggers>
        </event>
    </constraints>
</root>
