INTEGRATIONS

Adding restrictions to the 2D Model

To prepare exercises for students, it is possible to add restrictions by editing the XML file.

There are three types of restrictions:

  1. Time restrictions. For example, the time limit for the task or a specific action in a specific time period.

  2. Spatial. For example, adding regions (“Start”, “Finish”) or prohibiting / forcing the robot, its sensor, or some moving object to be in certain places at certain intervals.

  3. Device restrictions. For example, a restriction on a set of sensors or on device behavior.

Constraint writing structure

The main tag <constraints>…</constraints> is used to describe the restrictions. Only 3 child tags can be entered in it at the first level of nesting:

Tag

Description

timelimit

Time limit.

constraint

A constraint with an arbitrary condition in violation of which a specified error will be generated.

event

The main tool for setting dynamic constraints. Used as a container.

The remaining tags can be added only to the three tags described above, at the second level of nesting:

Tag

Description

conditions

Compound condition comparison element. It can be used as a container.

inside

Allows you to set spatial constraints.

greater

Greater. The operation of comparing the values of functional symbols. It can be used as a container.

equals

Equals. The operation of comparing the values of functional symbols. It can be used as a container.

not equals

Not equals. The operation of comparing the values of functional symbols. It can be used as a container.

objectState

Get the object state.

int

Specifies an integer constant.

typeOf

Take the object metatype with the given ID.

string

Defining a string constant.

trigger

An action or group of actions that will be performed one or many times upon the fulfillment of an event condition. It can be used as a container.

fail

Show error, complete task verification.

success

A trigger showing a success message and completing a check.

<constraints>...</constraints>

The main tag containing all restrictions. Used as a container.

<constraints>
<timelimit value="30000"/>
<constraint checkOnce="true" failMessage="The robot must be at the start before starting!">
<inside objectId="robot1" regionId="start_zone"/>
</constraint>
</constraints>

<timelimit/>

Time limit.

Attributes

Attribute

Description

value="value"

Timeout in milliseconds when execution will be terminated and the "Time limit exceeded" error will be displayed.

Syntax:

<timelimit value="35000"/>

<constraint>...</constraint>

A constraint with an arbitrary condition in violation of which a given error will be generated. It can be used as a container. It has one child tag: <conditions>...</conditions>.

Attributes

Attribute

Description

checkOnce="true"

Boolean attribute. If the value is true, then the restriction will be checked once at program startup.

failMessage="Ошибка!"

An error message that will be displayed when a restriction is violated.

Syntax:

<constraint checkOnce="true" failMessage="Робот должен находиться на старте перед запуском!">

<event>...</event>

The main tool for setting dynamic constraints. Used as a container.

Attributes

Attribute

Description

settedUpInitially="true"

An attribute that allows you to indicate whether the event is set up at start. The event can be cocked or lowered. In the cocked state, the event fulfills its trigger to fulfill its condition; in the lowered state, it is ignored by the system. The default value is false.

id="finish checker"

Unique ID.

Syntax:

<event id="finish checker" settedUpInitially="false">
<condition>
<inside objectId="robot1" regionId="finish"/>
</condition>
<trigger>
<success/>
</trigger>
</event>

<conditions>...</conditions>

Compound condition comparison element. The bundle may be andor or. The negation of an expression is specified by the <not> tag with no attributes.

Attributes

Attribute

Description

glue="and"

Logical bond.

Syntax:

<conditions glue="and">
<!-- Condition1 -->
<!-- Condition2 -->
<!-- ... -->
<!-- ConditionN -->
</conditions>
<conditions glue="and">
<not>
<!-- Condition1 -->
</not>
</conditions>

<inside/>

Allows you to set spatial constraints.

Attributes

Attribute

Description

objectId="id"

ID of the object.

regionId="id"

ID of the region.

Syntax:

<inside objectId="robot1" regionId="start"/>

<greater>...</greater>

Greater. The operation of comparing the values of functional symbols. It can be used as a container.

Syntax:

<greater>
<objectState object="robot1.display.labels.size"/>
<int value="0"/>
</greater>

<equals>...</equals>

Equals. The operation of comparing the values of functional symbols. It can be used as a container.

Syntax:

<equals>
<objectState object="robot1.display.labels.first.text"/>
<string value="finish"/>
</equals>

<not><equals>...</equals></not>

Not equals. The operation of comparing the values of functional symbols. It can be used as a container.

Syntax:

<not><equals>
<objectState object="robot1.display.labels.first.text"/>
<string value="finish"/>
</equals></not>

<objectState/>

Get the state of the object.

Attributes

Attribute

Description

object="robot1.display.labels.size"

ID of the object.

Syntax:

<objectState object="robot1.display.labels.first.text"/>

<int/>

Specifies an integer constant.

Attributes

Attribute

Description

value="0″

The value of the given constant.

Syntax:

<int value="0"/>

<typeOf/>

Take the object metatype with the given identifier. For example: if we take the typeOf of the wall object with id = 777, it will return that the type of this object is wall.

Attributes

Attribute

Description

objectId="id"

ID of the object.

Syntax:

<typeOf objectId="robot1.A3"/>

<string/>

Defining a string constant.

Attributes

Attribute

Description

value="value"

Value of string constant.

Syntax:

<string value="finish"/>

<trigger>...</trigger>

An action or group of actions that will be performed one or many times upon the fulfillment of an event condition. It can be used as a container.

Syntax:

<trigger>
<success/>
</trigger>

<fail/>

Display an error, complete task verification.

Attributes

Attribute

Description

message="Wrong answer!"

Error text.

Syntax:

<fail message="Wrong answer!"/>

<success/>

The task was completed successfully.

Syntax:

<success/>

Example of adding restrictions

Starting in the blue square, you need to drive along the wall using the IR distance sensor to the red square.

<?xml version="1.0" encoding="UTF-8"?>
<root>
<world>
<background />
<walls>
<!-- Wall -->
<wall id="{wall1}" end="300:150" begin="0:100" />
<wall id="{wall2}" end="550:100" begin="300:150" />
<wall id="{wall3}" end="650:200" begin="550:100" />
<wall id="{wall4}" end="850:300" begin="650:200" />
<wall id="{wall5}" end="1200:300" begin="850:300" />
<wall id="{wall6}" end="1600:50" begin="1200:300" />
</walls>
<skittles />
<balls />
<colorFields />
<images />
<regions>
<!-- Regions -->
<region visible="true" id="finish" x="1300" color="#ff0000" text="Finish" type="rectangle" width="300" textX="0" textY="0" y="-200" filled="true" height="300" />
<region visible="true" id="start_zone" x="-50" color="#0000ff" text="Start" type="rectangle" width="150" textX="0" textY="0" y="100" filled="true" height="-150" />
<region visible="false" id="warzone_1" x="-50" color="#ffff00" text="warzone1" type="rectangle" width="650" textX="0" textY="0" y="-50" filled="true" height="200" />
<region visible="false" id="warzone_2" x="600" color="#ffff00" text="warzone2" type="rectangle" width="250" textX="0" textY="0" y="0" filled="true" height="250" />
<region visible="false" id="warzone_3" x="850" color="#ffff00" text="warzone3" type="rectangle" width="750" textX="0" textY="0" y="50" filled="true" height="250" />
</regions>
</world>
<robots>
<!-- Robot -->
<robot id="trikKitRobot" position="0:0" direction="0">
<sensors>
<sensor port="A1###input###А1###sensorA1" position="75:25" type="trik::robotModel::parts::TrikInfraredSensor" direction="45" />
<sensor port="M3###output###JM3$$$C$$$3###" position="75:25" type="kitBase::robotModel::robotParts::Motor" direction="0" />
<sensor port="M4###output###JM4$$$D$$$4###" position="75:25" type="kitBase::robotModel::robotParts::Motor" direction="0" />
</sensors>
<startPosition id="{ee2c46c1-23fc-4cda-98f4-77d9de775305}" x="25" y="25" direction="0" />
<wheels left="M3###output###М3###" right="M4###output###М4###" />
</robot>
</robots>
<constraints>
<!-- Time limit (30 seconds) -->
<timelimit value="30000" />
<!-- Spatial limit. Checks once at startup. -->
<constraint checkOnce="true" failMessage="The robot must be in the blue square before starting!">
<inside regionId="start_zone" objectId="robot1" />
</constraint>
<!-- Sensors restrictions -->
<constraint checkOnce="true" failMessage="Only the IR distance sensor on A1 port should be connected">
<conditions glue="and">
<equals>
<typeOf objectId="robot1.A1" />
<string value="trik::twoDModel::robotModel::parts::RangeSensor" />
</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.A5" />
<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>
</conditions>
</constraint>
<!-- Robot ride control -->
<constraint failMessage="The robot tried to move out of the permitted area!">
<conditions glue="or">
<inside regionId="warzone_1" objectId="robot1" />
<inside regionId="warzone_2" objectId="robot1" />
<inside regionId="warzone_3" objectId="robot1" />
</conditions>
</constraint>
<!-- An event that checks if the robot has entered the finish area -->
<event settedUpInitially="true">
<condition>
<timer timeout="100" forceDropOnTimeout="true" />
</condition>
<trigger>
<setUp id="finish checker" />
</trigger>
</event>
<!-- Event announcing the successful execution of the program -->
<event id="finish checker" settedUpInitially="false">
<condition>
<inside regionId="finish" objectId="robot1" />
</condition>
<trigger>
<success />
</trigger>
</event>
</constraints>
</root>