• 沒有找到結果。

Robot

在文檔中 Webots User Guide (頁 44-54)

3.5 Citing Webots

4.1.3 Robot

44 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT

4.1. MY FIRST WORLD: KIKI.WBT 45 4. In thechildrenfield, first introduce aTransformnode that will contain a shape with a box. In the newchildrenfield,Insert afteraShapenode. Choose a color, as described previously. In thegeometryfield,insertaBoxnode. Set the size of the box to [0.08 0.08 0.08]. Now set thetranslationvalues to [ 0 0.06 0 ] in theTransformnode (see figure 4.6)

Figure 4.6: Body of the kiki robot: a box To model the left wheel of the robot:

1. Select the Transform node corresponding to the body of the robot and Insert after a Solidnode in order to model the left wheel. Type ”left wheel” in thenamefield, so that thisSolid node is recognized as the left wheel of the robot and will rotate according to the motor command.

2. The axis of rotation of the wheel is x. The wheel will be made of a Cylinder rotated of pi/2 radians around the z axis. To obtain proper movement of the wheel, you must pay attention not to confuse these two rotations. Consequently, you must add aTransform node to thechildrenof theSolidnode.

3. After adding thisTransform node, introduce inside it a Shapewith a Cylinderin its geometryfield. Don’t forget to set an appearance as explained previously. The dimen-sions of the cylinder should be 0.01 for the heightand 0.025 for the radius. Set the rotationto [ 0 0 1 1.57 ]. Pay attention to the sign of the rotation; if it is wrong, the wheel will turn in the wrong direction.

4. In theSolidnode, set the translation to [-0.045 0.025 0] to position the left wheel, and set the rotation of the wheel around the x axis: [1 0 0 0].

46 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT 5. Give aDEF name to your Transform: WHEEL; notice that you positioned the wheel in translation at the level of theSolidnode, so that you can reuse theWHEEL Transform for the right wheel.

6. Close the tree window, look at the world and save it. Use the navigation buttons to change the point of view.

To model the right wheel of the robot:

1. Select the left wheelSolidnode andinsert afteranotherSolidnode. Type ”right wheel”

in the name field. Set the translation to [0.045 0.025 0] and the rotation to [1 0 0 0].

2. In thechildren,Insert afterUSE WHEEL. PressReturn, close the tree window and save the file. You can examine your robot in the world editor, move it and zoom in on it.

The robot and its two wheels are shown in figure 4.7 and figure 4.8.

Figure 4.7: Wheels of the kiki robot

The two infra-red sensors are defined as two cylinders on the front of the robot body. Their diameter is 0.016 m and their height is 0.004 m. You must position these sensors properly so that the sensor rays point in the right direction, toward the front of the robot.

4.1. MY FIRST WORLD: KIKI.WBT 47

Figure 4.8: Body and wheels of the kiki robot

1. In thechildren of theDifferentialWheelsnode, insert aftera DistanceSensor node.

2. Type the name ”ir0”. It will be used by the controller program.

3. Let’s attach a cylinder shape to this sensor: In thechildrenlist of theDistanceSensor node,Insert afteraTransformnode. Give aDEFname to it: INFRARED, which you will use for the second IR sensor.

4. In thechildrenof theTransformnode,insert afteraShapenode. Define an appearance andinsertaCylinderin thegeometryfield. Type 0.004 for the height and 0.008 for the radius.

5. Set the rotation for the Transform node to [0 0 1 1.57] to adjust the orientation of the cylinder.

6. In theDistanceSensornode, set the translation to position the sensor and its ray: [0.02 0.08 -0.042]. In theFilemenu,Preferences,Rendering, check theDisplay sensor raysbox.

In order to have the ray directed toward the front of the robot, you must set the rotation to [0 1 0 1.57].

48 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT 7. In theDistanceSensornode, you must introduce some values of distance measurements

of the sensors to thelookupTablefield, according to figure 4.9. These values are:

lookupTable [ 0 1024 0, 0.05 1024 0, 0.15 0 0 ]

Measured value

Distance to the wall 1024

0

0.05 0.15

Figure 4.9: Distance measurements of the kiki sensors.

8. To model the second IR sensor, select theDistanceSensornode andInsert aftera new DistanceSensor node. Type ”ir1” as a name. Set its translation to [-0.02 0.08 -0.042]

and its rotation to [0 1 0 1.57]. In the children, insert after USE INFRARED. In the lookupTablefield, type the same values as shown above.

The robot and its two sensors are shown in figure 4.10 and figure 4.11.

Note: A texture can only be mapped on an IndexedFaceSet shape. The texCoord and texCoordIndexentries must be filled. The image used as a texture must be a.pngor a.jpg file, and its size must be (2n) * (2n) pixels (for example 8x8, 16x16, 32x32, 64x64, 128x128 or 256x256 pixels). Transparent images are not allowed in Webots. Moreover, PNG images should use either the 24 or 32 bit per pixel mode (lowerbppor gray levels are not supported). Beware of the maximum size of texture images depending on the 3D graphics board you have: some old 3D graphics boards are limited to 256x256 texture images while more powerful ones will accept 2048x2048 texture images.

To paste a texture on the face of the robot:

1. Select the lastDistanceSensornode andInsert afteraShapenode.

4.1. MY FIRST WORLD: KIKI.WBT 49

Figure 4.10: The DistanceSensor nodes of the kiki robot

2. Create anAppearancenode in theappearancefield. Create anImageTexturenode in thetexturefield of this node, with the following URL:"kiki/kiki.png". This refers to an image file lying in theworldsdirectory.

3. In thegeometry field, create anIndexedFaceSet node, with a Coordinate node in thecoordfield. Type the coordinates of the points in thepointfield:

[ 0.015 0.05 -0.041, 0.015 0.03 -0.041, -0.015 0.03 -0.041, -0.015 0.05 -0.041 ]

andInsert afterin thecoordIndexfield the following values: 0, 1, 2, 3, -1. The optional -1 value is there to mark the end of the face. It is useful when defining several faces for the sameIndexedFaceSetnode.

4. In thetexCoordfield, create aTexureCoordinatenode. In thepointfield, enter the coordinates of the texture:

50 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT

Figure 4.11: The kiki robot and its sensors

[ 0 0 1 0 1 1 0 1 ]

and in thetexCoordIndex field, type 3, 0, 1, 2. This is the standard VRML97 way to explain how the texture should be mapped to the object.

5. The texture values are shown in figure 4.12.

To finish with theDifferentialWheelsnode, you must fill in a few more fields:

1. In thecontrollerfield, type the name ”simple”. It is used to determine which controller program controls the robot.

2. The boundingObject field can contain a Transform node with a Box, as a box as a bounding object for collision detection is sufficient to bound the kiki robot. Create a Transform node in the boundingObject field, with the translation set to [0 0.05 -0.002] and aBoxnode in itschildren. Set the dimension of theBoxto [0.1 0.1 0.084].

4.1. MY FIRST WORLD: KIKI.WBT 51

Figure 4.12: Defining the texture of the kiki robot

3. In theaxleLength field, enter the length of the axle between the two wheels: 0.09 (ac-cording to figure 4.5).

4. In thewheelRadiusfield, enter the radius of the wheels: 0.025.

5. Values for other fields are shown in figure 4.13 and the finished robot in its world is shown in figure 4.14.

52 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT

Figure 4.13: The other fields of the DifferentialWheels node

4.1. MY FIRST WORLD: KIKI.WBT 53

Figure 4.14: The kiki robot in its world

54 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT Thekiki.wbtis included in the Webots distribution, in theworldsdirectory.

在文檔中 Webots User Guide (頁 44-54)

相關文件