<?xml version='1.0' encoding='utf-8'?>
<root version="20190819">
    <world>
        <walls>
            <wall stroke-style="none" fill="#ff000000" id="{a031e1ec-73c8-480a-b8d1-0eb812d22a2a}" stroke-width="10" begin="150:100" end="150:250" stroke="#ff000000"/>
            <wall stroke-style="none" fill="#ff000000" id="{04da9c64-ffcd-4124-b4d7-d8be7dee0eee}" stroke-width="10" begin="150:250" end="300:250" stroke="#ff000000"/>
            <wall stroke-style="none" fill="#ff000000" id="{0ee11790-2eac-4f00-87c8-f1036fcb39c6}" stroke-width="10" begin="300:100" end="300:250" stroke="#ff000000"/>
        </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 y="-50" height="150" width="150" text="Start" filled="true" visible="false" id="start_zone" textX="0" textY="0" type="rectangle" x="-50" color="#ff0000"/>
            <region y="-200" height="450" width="150" text="Поле, которое нельзя покидать" filled="true" visible="true" id="good_zone2" textX="0" textY="0" type="rectangle" x="150" color="#008000"/>
            <region y="150" height="100" width="150" text="Finish" filled="true" visible="true" id="finish" textX="0" textY="0" type="rectangle" x="150" color="#0000ff"/>
            <region y="-50" height="150" width="200" text="Поле, которое нельзя покидать" filled="true" visible="true" id="good_zone1" textX="0" textY="0" type="rectangle" x="-50" color="#008000"/>
        </regions>
    </world>
    <robots>
        <robot direction="0" id="trikKitRobot" position="0:0">
            <sensors>
                <sensor direction="0" position="75:25" port="E3###input###M3$$$Е3###encoder3" type="kitBase::robotModel::robotParts::EncoderSensor"/>
                <sensor direction="0" position="75:25" port="E4###input###M4$$$Е4###encoder4" type="kitBase::robotModel::robotParts::EncoderSensor"/>
                <sensor direction="180" position="25:25" port="A1###input###А1###sensorA1" type="trik::robotModel::parts::TrikInfraredSensor"/>
                <sensor direction="0" position="75:25" port="M4###output###М4###" type="kitBase::robotModel::robotParts::Motor"/>
                <sensor direction="0" position="75:25" port="M3###output###М3###" type="kitBase::robotModel::robotParts::Motor"/>
            </sensors>
            <startPosition y="25" direction="0" id="{f12d7f44-ea35-449c-914e-4827a12d1ed0}" x="25"/>
            <wheels right="M3###output###М3###" left="M4###output###М4###"/>
        </robot>
    </robots>
    <settings realisticMotors="false" realisticPhysics="false" realisticSensors="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>
