Mirage Tips

From Tekkotsu Wiki

Jump to: navigation, search


This article is part of the Mirage collection.

Make An Object Movable/Immovable

To make an object movable, give it a non-zero mass. The larger the mass, the harder it will be to move the object. The default mass value is zero, which makes the object completely immovable.

cube scale=[100,100,100] location=[500,0,50] mass=5

Make An Object Non-Collidable

To prevent an object from generating collisions, give it an empty collision model. In the WorldBuilder you can do this by setting collision=false. The robot will pass right through the object as if the object didn't exist. This trick is particularly useful for "decorating" the ground with markings that we don't want the robot to stumble on.

cube scale=[100,100,100] location=[500,0,50] collision=false

Make a Ramp

You can make an immovable ramp from a cube that is rotated and partially buried in the ground.

cube scale=[1200,500,200] location=[1000,0,-60] material=Blue orientation=roty(-pi/32)


To get the robot to climb the ramp, you will need to use a high rate of speed. In the Pilot, set pilotreq.forwardSpeed=500.

Use Turtle Commands To Make A Maze

To draw a maze, use a series of relative motion ("turtle graphics") commands so you don't have to calculate explicit coordinates for every wall:

set dist=1000
set wallHeight=300
penheight wallHeight
pencolor RustySteel

moveto [-500, 500, wallHeight/2]
forward dist
turn 90
forward dist
turn -90
forward dist
turn 90
forward dist
turn 90
forward 2*dist
turn 90
forward 2*dist

light location=[500,1000,3000] pointat=[1000,-1500,0]

Note the addition of an extra light to better illuminate the interior of the maze.


Make Your Own Materials

The built-in materials can be found in /usr/local/Tekkotsu/tools/mirage/media. You can define your own materials by adding files to your ~/.mirage directory. You can use any filename, with "material" as the extension. Multiple materials can be placed in the same file.

Here is how to use a jpeg or png file as a material. Let's use the kitten image shown at right. Create a ~/.mirage/images directory, and download the file kitten.jpg to that directory.

Sample image

Now create the file ~/.mirage/MyStuff.material with the following contents:

material Kitten
        texture images/kitten.jpg
        rotate -90

Now you can use Kitten as a material in your Mirage worlds.

Mirage scans all the material files in your ~/.mirage directory on startup, so if you add or edit your material files you must restart Mirage for the changes to take effect; simply reloading the world is not sufficient.

Apply A Skin To An Object

You can use a jpeg or png file as a skin for an object by creating a material that uses that file (see previous item). Then use that material in your object definition. Example:

cube scale=[300,300,300] location=[500,0,150] material=Kitten


Attach Shapes To Make a Complex Object

Use the attachto keyword in a define command to rigidly attach one shape to another. For example, you can make a dumbbell by first defining Dumbell to be a cylinder. Then define two endcaps and attach them to the Dumbell. Use the moffset and mrotation parameters to control the positions of the attached shapes relative to the parent. When you instantiate the Dumbbell you'll get a complex shape. Because the shapes are rigidly attached, if a robot picks up the dumbbell by grasping the cylinder, the endcaps will move along with it.

define Dumbbell cylinder scale=[30,30,200] material=Blue mass=1

define Endcap cube scale=[100,100,10] mass=5
define Endcap1 Endcap attachto=Dumbbell moffset=[0,0,105] mrotation=rotz(45) material=Red
define Endcap2 Endcap attachto=Dumbbell moffset=[0,0,-105] material=Green

Dumbbell location=[500,500,110]

Instantiating Dumbbell instantiates all the shapes attached to it. Note: the attachto keyword has to be specified separately for Endcap1 and Endcap2. If you instead put it on Endcap, it would be inherited by EndCap1 and Endcap2 as you would expect, but the dumbbell would have three endcaps because Endcap is a shape in its own right.

Presently it is not possible to have nested/chained attachments, so one shape can only be attached to another if it has no attachments of its own.

Make A Robot-Shaped Object

The robot is drawn in Mirage using the mesh files in Tekkotsu/tools/mirage/media. If you want to populate your world with some objects that look like robots (but aren't functional), you can use these mesh files as model parameters. For example, to make a Create robot you could use the file media/Create/Body.mesh by typing:

cylinder model="Create/Body" location=[500,0,0]

If you want the robot to be able to engage in collisions, use the following. (The numerical values are taken from the Create.kin file; casterHeight is estimated. The collision model and center of mass must be offset because the casters extend below the origin of the Create/Base model and we don't want them to sink through the floor. Other robot models may require similar tricks.)

set casterHeight = 20
set zv = 61.2 + casterHeight
cylinder model="Create/Body" location=[500,0,0] mass=2.403 cmscale=[329.95,329.95,zv] cmoffset=[0,0,zv/2] centerofmass=[0,0,zv/2]

Press "h" in Mirage to see the collision model and center of mass.

Change The Initial Location of the Robot

By default the robot appears in the world at location [0,0,0]. You can change this by supplying InitialLocation parameters to the Mirage device driver on the command line. For example, to start the robot 500 mm in the air, you would write:

./tekkotsu-CALLIOPE -c mirage.plist Drivers.Mirage.InitialLocation.2=500

Change The Initial Orientation of the Robot

Tekkotsu uses quaternions to specify 3D orientations. By default the robot appears in the world in a level attitude, facing north. This is described by the unit quaternion [0,0,0]. To change the initial heading of the robot you will want to rotate it around the z axis. Rotation by an angle θ can be accomplished with the quaternion [0,0,cos(θ/2)]. So, for example, if you want the robot to start out facing west, you would use the quaternion [0, 0, 0.707], which you would specify on the command line as:

./tekkotsu-CALLIOPE -c mirage.plist Drivers.Mirage.InitialOrienation.2=0.707

Run Multiple Robots in Mirage

It is possible to run multiple robots in a single Mirage world. First you must give each robot a unique id by editing the robot's project/ms/config/tekkotsu.xml file and changing the "id" value in the "wireless" section at the end of the file. The default id is 1; any integer value is fine.

Then, to connect all the robots to a single Mirage server you simply tell each Tekkotsu instance to connect to the same host, rather than to localhost. For example, suppose Mirage is running on a host whose IP address is Start each Tekkotsu instance by writing:

./tekkotsu-CALLIOPE -c mirage.plist Drivers.Mirage.Host=