2D model tuning

Defines walls. Used as a container, has no attributes. In addition to creating a virtual world of robots in TRIK Studio, you can do more flexible customization by editing an XML file: specify the location of objects, color, width, and other parameters more precisely.

First, you need to create an XML file for the virtual model.

2D model coordinate system

In the 2D model window the axes located as follows:

Attention! One cell has dimensions of 17.5 × 17.5 centimeters or 50 × 50 pixels.

An XML file creation

To create an empty XML file you should use your OS' standard tools such as Notepad in Windows or whatever.

To save the world model created in TRIK Studio:

  1. Switch to the 2D model mode.

  2. Go to the "Debug mode".

  3. Specify the location and file name to save.

Editing an XML file

Open a saved XML file in a text editor. Notepad++, for example.

The XML file contains tags and attributes.

Tags

Tag is a markup language element. There is the start (opening) and end (closing) tags. The text contained between the start and end tags is displayed and placed according to the properties specified in the start tag.

Example:

<walls> <!-- start (opening) tag -->
     <wall begin="200:-200" id="{a3ede76b-1d7e-4c72-9ed4-08d8ea9af4bf}" end="200:150"/>
</walls> <!-- end (closing) tag -->

Attributes

Attributes are tag properties that provide additional text formatting capabilities. They are recorded as a combination of "attribute name-value". Text values are enclosed in quotation marks.

In the above example, the attributes are:

begin="200:-200" id="{a3ede76b-1d7e-4c72-9ed4-08d8ea9af4bf}" end="200:150"

The simplest virtual world model without objects in .xml the format is as follows:

The simplest virtual model
<?xml version='1.0' encoding='utf-8'?>
<root>
    <world>
        <background/>
        <walls/>
        <skittles/>
        <balls/>
        <colorFields/>
        <images/>
        <regions/>
    </world>
    <robots>
        <robot direction="0" id="trikKitRobot" position="0:0">
            <sensors/>
            <startPosition direction="0" id="{name}" y="25" x="25"/>
            <wheels left="M4###output###М4###" right="M3###output###М3###"/>
        </robot>
    </robots>
</root>

Robots

The following tags are available for describing robots:

<robots>...</robots>

Defines a robot on stage. Used as a container, has no attributes.

<robots>
     <robot id="trikKitRobot" position="0:0" direction="0">
</robots>

<robot>...</robot>

Adds a robot to the scene. Can be used as a container.

Attention! You can not add multiple robots to the scene.

Attributes

Example:

<robot id="trikKitRobot" position="0:0" direction="0">

<sensors>...</sensors>

Defines sensors on a robot. Used as a container, has no attributes.

<sensors>
     <sensor type="kitBase::robotModel::robotParts::Motor" direction="0" port="M4###output###JM4$$$D$$$4###" position="75:25"/>
</sensors>

<sensor/>

Sensors ports configuration.

Attributes

There are 5 types of sensors for TRIK and 9 types of sensors for EV3:

Example:

<sensor position="75:25" direction="0" port="A1###input###А1###sensorA1"
type="trik::robotModel::parts::TrikInfraredSensor"/>

<startPosition/>

Defines the starting position of the robot.

Attributes

Example:

<startPosition id="{7a326d25-82f4-4eb4-9b42-1e75576f35a4}" direction="0" x="25" y="25"/>

<wheels/>

Motor ports configuration.

Attributes

Example:

<wheels left="M4###output###М4###" right="M3###output###М3###"/>

Objects

The following tags are available for describing objects:

<wall>

Adds a wall to the scene.

Attributes

Example:

<wall id="{wall1}" begin="50:-50" end="250:-50"/>

<skittle>

Adds a skittle to the scene.

Attributes

Example:

<skittle rotation="0" id="{skittle1}" markerY="44" startRotation="0" x="220" y="44"
markerX="220"/>

<ball>

Adds a ball to the scene.

Attributes

Example:

<ball rotation="0" id="{ball1}" markerY="169" startRotation="0" x="-18" y="169" markerX="-18"/> 

<line>

Adds a line to the scene.

Attributes

Example:

<line stroke-width="6" fill-style="none" end="250:-50" id="{line1}" stroke-style="solid"
fill="#ff000000" stroke="#ff000000" begin="50:-50"/>

<cubicBezier>

Adds a Bezier curve.

Attributes

Example:

<cubicBezier id="{cubicBezier1}" fill-style="none" stroke-width="6" end="-106.577:134.894"
begin="-112.95:-192.25" fill="#ff000000" cp1="-142.95:-192.25" cp2="17.0502:-192.25"
stroke="#ff000000" stroke-style="solid"/>

<rectangle>

Adds a rectangle.

Attributes

Example:

<rectangle stroke-width="6" fill-style="none" end="344:511" id="{rectengle1}" 
stroke-style="solid" fill="#ff000000" stroke="#ff000000" begin="285:229"/>

<ellipse>

Adds an ellipse.

Attributes

Example:

<ellipse stroke-width="6" fill-style="none" end="-178:300" id="{ellipse1}" 
stroke-style="solid" fill="#ff000000" stroke="#ff000000" begin="-260:7"/>

<stylus>

Defines a stylus for drawing.

Attributes

Example:

<stylus stroke-width="6" fill-style="none" id="{stylus_name}" stroke-style="solid" 
fill="#ff000000" stroke="#ff000000">

<stylusLine>

Allows you to draw arbitrary shapes using the stylus. This block of code consists of many segments.

Attributes

Example:

<stylusLine stroke-width="6" fill-style="none" end="-334:259" id="{name1}" stroke-style="solid"
fill="#ff000000" stroke="#ff000000" begin="-334:260"/>
<stylusLine stroke-width="6" fill-style="none" end="-333:258" id="{name2}" stroke-style="solid"
fill="#ff000000" stroke="#ff000000" begin="-334:259"/>
<stylusLine stroke-width="6" fill-style="none" end="-333:254" id="{name3}" stroke-style="solid"
fill="#ff000000" stroke="#ff000000" begin="-333:258"/>

<region>

Allows you to add regions to the scene. There are 2 types of regions:

  • rectangle

  • ellipse

Attributes

Example:

<regions>
            <region filled="true" type="rectangle" height="300" width="300" textX="0" 
text="Finish" textY="0" x="1300" y="-200" visible="true" id="Start" color="#ff0000"/>
</regions>

2D model setup example

The "Barcode" task

You need to draw a barcode. The barcode consists of white and black lines of the same thickness. The black line specifies 1 in a binary number, and the white one 0. The first black line in the robot path is the first bit of the number.

The barcode lines order: 1001011011.

World creation

In this task, the lines should be the same thickness and length. It’s very difficult to draw lines by hand using the Line or Stylus tool, so edit the lines manually:

1. Draw 10 lines on the scene.

2. Save the model of the world.

3. Open the resulting XML file in any convenient editor. Pay attention to the code block with the<line...>tag.

4. For convenience, name each line black1-black5 and white1-white5. You can do this in the "id" attribute. Name the lines in the order shown above.

5. Specify the line thickness "50" in the stroke-widthattribute.

6. Assign the color to each line: #ff000000 is black, #ffffffff is white. You can do this in the attribute fill. Assign colors so that you get a barcode.

7. Set the position of each line in the beginand endattributes without gaps, so that you get a smooth barcode.

The result

Last updated