Using the Visual Simulation Environment

Even though the simulation engine is just a service, MSRS provides an editor that you can use to create new entities and arrange them within a simulation scene. The graphical editor—named the Visual Simulation Environment (VSE)—operates in two basic modes: run and edit. Run mode will run the simulation but does not allow you to change any of the properties affecting the simulation scene. Edit mode (see Figure 4-1) allows you to alter the current scene by changing the properties of existing entities or adding new entities.

This section will include information you need to work with VSE. Because simulation is a heavily graphics-intensive process, you will need to make certain hardware considerations before starting out with VSE. You will also need to understand entities and know how to create new entities.

Simulation scenes can be modified and new entities added while in edit mode.

Figure 4-1. Simulation scenes can be modified and new entities added while in edit mode.

Hardware Considerations

To render simulations and use VSE, your development machine must include a compatible graphics card. The graphics card must support pixel and vertex shaders, but most laptops or desktop machines that are capable of running current graphics-based games will do this. Specifically, your graphics card must support the vertex shader VS_2_0 or higher and pixel shader PS_2_0 or higher. This means that the card must be compatible for DirectX version 9 or higher.

If you are not sure which of these shaders your graphics card uses and you have already installed MSRS, you can open one of the VSEs, such as the Basic Simulation Environment. Next, click on the Help menu, and then select About Microsoft Visual Simulation Environment (see Figure 4-2). If you scroll to the bottom of this dialog box, you will see what pixel and vertex shader versions your graphics card supports.

Tip

Tip

The following URL lists graphics cards that have been tested and approved by the MSRS team: http://channel9.msdn.com/wiki/default.aspx/Channel9.SimulationFAQ. Although this list does not include all graphics cards that may support VSE, it does cover some of the more commonly used ones. You can also check the following Web site to determine what pixel and vertex shaders your graphics card supports: http://www.techpowerup.com/gpudb/.

The About Microsoft Visual Simulation Environment dialog box displays information about which vertex and pixel shader versions the development machine is using.

Figure 4-2. The About Microsoft Visual Simulation Environment dialog box displays information about which vertex and pixel shader versions the development machine is using.

It is possible to install MSRS on a development machine, work with services and the robotics tutorials, and still not be able to access VSE. One way to tell if your graphics card supports simulation is to install MSRS and try to run one of the simulations provided. If only the frame and menu bar of the VSE window appear, your card does not support the DirectX 9 shaders. You will either have to upgrade your graphics card or use a different development machine that does have a compatible graphics card.

It is also possible that your graphics card will not support the required shaders but will still try to render the scene. This is because there are two ways to perform graphics functions: by using software or by using hardware. If the functions are performed by the hardware, then the graphic will render very quickly. If the hardware does not support the graphics function, then the simulation will run in software mode. In general, software performs much more slowly than the hardware, and thus you may see significant performance degradation. To find out which shader versions your graphics card supports, refer to About Microsoft Visual Simulation Environment from the Help menu.

Using the AGEIA PhysX Card

MSRS uses the AGEIA PhysX engine to provide physics for the simulation environment. The MSRS installation contains the installation for the AGEIA PhysX engine, but you can optionally purchase and install the add-in hardware physics processor made by AGEIA. Although the AGEIA Web site (http://www.ageia.com) lists the price of the PhysX processor as $299 U.S. dollars, you can find it for much cheaper at local retailers such as Radio Shack or Fry’s Electronics. You can also buy it online through several retailers. I was able to buy a card for only $145 U.S. dollars through TigerDirect.com.

Tip

Tip

Depending on the complexity of the simulation you are running, you may not notice any differences in the simulation itself. Before running out and buying a PhysX card, I would suggest you work with the simulation tool and see if it meets your needs without the additional hardware purchase.

If you decide to purchase and install the card, keep the following in mind. Prior to installing the PhysX processor, you should see the following message in the command window when you start a simulation: "No physics hardware present, using software physics." This message will go away after you install the processor. You will also have access to additional properties in the AGEIA properties dialog box. You can access this dialog box through Start, Control Panel, and AGEIA PhysX. (If you are using Windows Vista, switch Control Panel to Classic View first, and then double-click AGEIA PhysX.) The Settings tab allows you to reset the AGEIA PhysX card and to start extended diagnostics. These functions will be available only if you have installed the card on your development machine.

Tracking the Frames per Second

VSE allows you to track the frames rendered per second using an optional status bar. The frames per second (FPS) setting is highly dependent on the capabilities of the graphics card and system capabilities of the development machine. It is also dependent on the number of entities and complexity of the objects within the simulation. The exact number of objects that you can add to a simulation depends on things such as the number of polygons used in those objects. A simple shape entity may have only a handful of polygons, but a more complex entity such as a robot may have thousands.

When using VSE to render a simulation, the FPS setting will be limited to the refresh rate for your monitor. Even if you were to upgrade your graphics card and install more memory, your simulation would not render faster than approximately 58 frames per second. The only exception to this would be if you disabled rendering and produced no visible image.

Note

Note

You can see what refresh rate your monitor is using by opening the Display Settings dialog box and then clicking Advanced Settings. The Monitor tab lists the screen refresh rate, which is typically 59 Hertz for LCD monitors and 60 or more for CRT monitors.

If you were to run the simulation named "Basic Simulation Environment" (which is supplied with MSRS) and look at the FPS, you would see that it is close to 58 FPS. (You can view the FPS by choosing View, Status Bar, and then reviewing the contents of the Status Bar.) Alternatively, if you then were to run the simulation named "Simulation Environment with Terrain," you might see a drop in the FPS. Whether there would be a drop in FPS would depend on the type of graphics card you were using.

The terrain simulation (see Figure 4-3) includes numerous simply shaped objects such as spheres, boxes, and capsules. It also includes more complex objects such as tables, a robot, and even the terrain itself. To get an idea of how these objects are constructed, you can run the simulation and create a wireframe rendering using the Render menu item. The wireframe rendering shows the lines between all vertices but does not fill them in. This displays all the polygon shapes involved in forming the entity.

The Simulation Environment with Terrain, a simulation provided with MSRS, renders a variety of objects.

Figure 4-3. The Simulation Environment with Terrain, a simulation provided with MSRS, renders a variety of objects.

The only way to have the simulation run faster is to disable rendering by selecting the Render menu item and then selecting No Rendering. Even though you will not be able to see the rendered results, you could use the Log Messages feature from the simple dashboard service to record messages while controlling the simulated robot.

Running a Simulation

You can run a simulation and initiate VSE by executing DssNode and loading a manifest file that includes the simulation engine service. Recall from Chapter 2 that a manifest file provides a list of service contracts. These service contracts contain information that other services need to work with the target service. A manifest file that loads the simulation service will include a Partner node such as the following:

<Partner>         <Contract>http://schemas.microsoft.com/robotics/2006/04/simulationengine.html
</Contract>
<Service>IRobot.Create.Simulation.xml</Service>
<Name>StateService</Name>
</Partner>

Tip

Tip

If you want to see the contract information associated with the simulation service, you can use the DssInfo command from a DSS command prompt. This is done by accessing the Command Prompt from the Microsoft Robotics Studio menu and entering the following (assuming you are using MSRS, version 1.5):

DssInfo "C:Microsoft Robotics Studio (1.5)insimulationengine.proxy.dll"

This results in the listing of information about the service such as the service contract name and which PortSet operations are supported.

Alternatively, you can select Run Dss Node from the Microsoft Robotics Studio menu, which starts a DSS node and loads the System Services in an Internet browser window. You can then click Control Panel in the left pane and scroll to the Simulation Engine service. Clicking the link for that service displays the information in an Internet browser.

MSRS includes several simulations that you can find on the Microsoft Robotics Studio menu and in the Visual Simulation Environment folder. These simulations represent a variety of scenarios that demonstrate how to work with VSE and build simulations using the entity objects supplied with MSRS. The simulations included with MSRS 1.5 include the following:

  • Basic simulation environment. The basic simulation includes only a few entities, which include a large sphere that looks like the world and a small grey box. No robots are included with this simulation, which is meant to teach the fundamentals of working with VSE. Because the scene contains a few basic objects and includes sky and ground entities, it can be a useful starting point for readers wanting to create their own simulations. Readers can locate the source code for the simulation (which is Simulation Tutorial 1) in the samplesSimulationTutorialsTutorial1 subdirectory.

  • IRobot Create simulation. This simulation includes only one robot—the iRobot Create. The command line for this simulation loads two manifest files: iRobot.Create.Simulation.Manifest.xml and SimpleDashboard.Manifest.xml. The Simple Dashboard is a service included with MSRS that allows you to control robots using the services available with the simulation. Readers can locate the source code for the Simple Dashboard in the samplesmiscSimpleDashboard subdirectory.

  • KUKA LBR3 Arm simulation. This simulation (which is Simulation Tutorial 4) features the KUKA LBR3 articulated arm and several large boxes shaped like dominos. This six-axis robotic arm allows you to move the arm by using the Simple Dashboard to adjust the angles of each joint. The source code that accompanies the KUKA LBR3 Arm simulation included with MSRS is found in the samplesSimulationTutorial4 subdirectory.

Tip

Tip

KUKA provides access to additional tutorials that feature its robotic arms. Refer to the following URL for a listing of available tutorials, along with the source code: http://www.kuka.com/usa/en/products/software/educational_framework/. Readers interested in working with the KUKA arm should review the tutorials found on the KUKA Web site because they demonstrate the wide variety of capabilities for the multi-jointed robot.

  • LEGO NXT Tribot simulationThis simulation features the LEGO NXT Tribot and several simple objects such as spheres, capsules, and a yellow cone. Even though the source code for the simulation should be located in the samplesSimulationTutorials Tutorial6 subdirectory, this was not included with the MSRS 1.5 installation. You can access this tutorial by going to http://msdn2.microsoft.com/en-us/library/bb483043.aspx.

  • Multiple simulated robots. This simulation (which is Simulation Tutorial 2) features the Pioneer 3DX and LEGO NXT Tribot robots, along with a table. Using the Simple Dashboard and the drive services associated with each robot, you can drive the robots around the environment and even force them to collide. Readers can locate the source code for the simulation in the samplesSimulationTutorialsTutorial2 subdirectory.

  • Pioneer 3DX simulation. This simulation features the Pioneer 3DX and several basic entities such as boxes, capsules, and spheres. These additional entities act as obstacles, and you can use this simulation to see the effects of using the laser rangefinder device that comes with the Pioneer 3DX. While the simulation is running, obstacles within the laser rangefinder’s field of view will flash red, dotted lights across the surface of the obstacle. You can use the Simple Dashboard service to view data returned from the robot as it is being moved around the simulation scene.

  • Simulation environment with terrain. Rather than operating the robots on a flat surface as is done in the other simulations, this simulation features a hilly terrain. The simulation features a Pioneer 3DX robot, but it does not look like the same robot featured in other simulations because the mesh object file associated with the entity has been removed. The robot will still perform the same, but it will not look as realistic without the mesh file. Readers can locate the source code for this simulation in the samplesSimulationTutorialsTutorial5 subdirectory.

Note

Note

Even though the documentation that accompanies MSRS lists six simulation tutorials, the samplesSimulationTutorials directory contains directories for tutorials 1, 2, 4, and 5. There are also discrepancies between the simulations included in the MSRS menu item, the code available with the installation, and the help file included with MSRS.

When running a simulation, the first thing you notice is that an instance of the command window appears. The simulation uses the command window to start a DssNode and also to load one or more manifest files. This loads the simulation engine service and initiates VSE. By default, VSE starts the simulation in run mode and renders the scene as a solid 3D image. Alternatively, you could render the scene in a wireframe, physics, or a combined view. Because rendering of entities can be an expensive process when the scene involves a large number of entities, it is possible to turn rendering off.

Tip

Tip

If you encounter errors when trying to run any of the simulations provided with MSRS, open the solution file in Visual Studio and rebuild the solution. MSRS uses strong name signing, and it is possible for some services to be recompiled and for this to cause problems with other projects.

To see which files are associated with a simulation, click on the Start menu, All Programs, Microsoft Robotics Studio (1.5), and then Visual Simulation Environment. Right-click the icon for the simulation, and then choose Properties. The target should list all manifest files that are loaded for this simulation. There might be more than one manifest loaded, so you might have to recompile more than one solution. For example, the iRobot Create simulation loads two manifest files: IRobot.Create.Simulation.Manifest.xml and SimpleDashboard.manifest.xml.

Note that it might take a long time for some of the solution files to rebuild because they might contain several projects. Make sure the Visual Studio status bar states that the rebuild all was successful before attempting to run the simulation again.

Using the Simple Dashboard Service

MSRS provides a service that allows you to operate a variety of robotics hardware. The Simple Dashboard service initiates a Windows-based dialog box (see Figure 4-4) that allows you to connect to a DSS node and initiate one or more services running on that node. The dashboard appears automatically whenever you run a simulation that partners with the Simple Dashboard service. Most of the simulations provided with MSRS include the dashboard.

The Simple Dashboard service is one of the miscellaneous services offered with MSRS. This service initiates a Windows-based dialog box that allows you to control your physical or simulated robot.

Figure 4-4. The Simple Dashboard service is one of the miscellaneous services offered with MSRS. This service initiates a Windows-based dialog box that allows you to control your physical or simulated robot.

Tip

Tip

When you run a simulation that includes the dashboard, the dashboard form will not receive focus and might be lost behind other windows running on your desktop. You might have to move the VSE window before you can see the dashboard form.

To connect to a DSS node on your local development machine, enter localhost in the Machine text box for the Dashboard dialog box. You then click Connect, and a list of services running on that node should appear in the list box below Service Directory. These services would have been loaded by the manifest file when you initiated the simulation. Depending on the service selected, you can perform the following functions:

  • Drive the robot. For robots with a differential drive system, such as the iRobot Create and Pioneer 3DX, a simulated differential drive service can be used to drive the robot. To do this, you must first select the drive service from the list of available services. You must then click the Drive button on the left side of the dialog box. At this point, you can control the robot using the mouse, trackball, touchpad, or joystick.

    Tip

    Tip

    It is possible to use an Xbox 360 controller to drive robots in a simulation. Readers interested in doing this should refer to the documentation available with MSRS concerning the XInput controller service.

  • Move an articulated arm. For robots that feature an articulated arm, such as the KUKA LBR3, you can change the angles for each active joint to move the arm within the simulation. To control the arm using the Simple Dashboard dialog box and the KUKA LBR3 simulation, select the simulated LBR3 arm service from the list of available services. At this point, the Articulated Arm section should list all the joints for the simulated arm.

  • Monitor data from a laser rangefinder device. For robots that include a laser rangefinder, such as the Pioneer 3DX, you can view the results obtained from the device. The results are used to indicate whether the robot encounters an object and measures the distance from the robot to the obstacle.

  • Log messages. The Simple Dashboard allows you to log messages as the simulation is executing. To do this, you need to specify a path to a log file, and you must store the log file beneath the Store subdirectory, which is part of the MSRS installation. The resulting XML-based file will include state that is retrieved by performing DSS operations. Data will continue to be written to the log file as long as the simulation is running. Recording data to the log file allows you to go back and see precise values returned from robot sensors. For example, you can log messages while operating the laser rangefinder and then go back later to see the exact distance measurements obtained while the simulation was running.

Note

Note

Although you can view messages as the simulation is running, the file size for a newly created log file remains at zero bytes until the simulation ends.

Enhanced Version of the Simple Dashboard Service

Because MSRS includes code for services such as the Simple Dashboard service, it is possible for you to extend the functionality available in these services. Ben Axelrod (see the following profile sidebar), a developer for Coroware (http://www.coroware.com) has released an enhanced version of the Simple Dashboard service (see Figure 4-5) that he makes available as a free download on his Web site (http://www.benaxelrod.com/MSRS/index.html). Be sure to put "MSRS" in all capital letters as this URL is case-sensitive.

An enhanced version of the Simple Dashboard service, available on Ben Axelrod’s Web site.

Figure 4-5. An enhanced version of the Simple Dashboard service, available on Ben Axelrod’s Web site.

The enhanced Simple Dashboard service provides a few time-saving features, such as defaulting the localhost value for the machine name and removing the Drive and Stop buttons. The service also features many improvements to the Direct Input Device, which is used to drive robots with a differential drive system. The original dashboard service was limited to 60 percent power when using the joystick to drive the robot. The enhanced version allows you to drive the robot at 100 percent power and to control this using a slider control added to the dashboard form. In addition to controlling the robot with the mouse or joystick, you can use arrow keys on the keyboard.

Enhancements were also made to the laser rangefinder section, and the extended service features two views: a cylinder view and an overhead view. Green dots project the robot width forward, and red colored obstacles indicate objects directly in front of the robot.

Readers can use the enhanced dashboard by first downloading the zipped file from the following URL: http://www.benaxelrod.com/MSRS/index.html. Because the solution includes references to several projects that are available with MSRS, you should extract and store the contents of the downloaded file in the samplesmisc folder. The files available in the extracted folder should replace the files in the SimpleDashboard folder, which is already in the misc subfolder. Before replacing the contents of the SimpleDashboard folder, copy the original files to another folder.

After you copy the files to the correct location, you just need to open the solution file using Visual Studio and rebuild the solution. From this point on, whenever simulations involving the Simple Dashboard service are loaded, the enhanced version of the dashboard should appear.

Note

Note

Because of strong name binding, you may have to rebuild some of the dependency projects, such as the SickLRF project. To do this, you will need to open the dependency project in Visual Studio and do a rebuild of this project before returning the SimpleDashboard solution file.

Editor Settings

VSE allows you to modify graphics settings that will apply to multiple simulations. Although you can set additional settings using code in a DSS service, the graphics settings (see Figure 4-7) apply to commonly used settings such as the brightness or quality level of the scene. The graphics settings, which include the following, are accessible through the Render menu item:

  • Exposure. This affects the brightness of the simulation scene. By default, the exposure is set with a value of zero. Setting the value higher makes the scene lighter, and setting it to a negative value makes the scene darker.

  • AntialiasingDepending on the capabilities of your graphics card, you may not have any options for this setting. Alternatively, you could have multiple settings that control the level of antialiasing applied. Antialiasing controls how smoothly edges are rendered and, thus, can affect the quality of your simulation scene. Without any antialiasing, edges can appear jagged and not smooth. As long as the graphics card performs the antialiasing on the hardware itself, setting this to a higher value should have little or no impact on the rendering speed.

  • Rotation Movement Scale. This controls how sensitive the mouse or touchpad is when moving around a scene. By default, this is set to a value of one. Setting it higher will make the mouse move faster, and setting it to a negative value makes the mouse move slower.

  • Translation Movement Scale. Similar to the Rotation Movement Scale setting, this controls how sensitive the keyboard and joystick are when moving around a simulation scene. Setting it to a higher value makes the controls work faster, and setting it to a negative value makes them move slower.

  • Quality Level. This controls the overall quality of the rendered scene and can be set to Low, Medium, or High. By default, VSE will select the level most appropriate for your graphics card. Setting the value higher than the value recommended by VSE will likely affect the rendering speed of your simulation.

The Graphics Settings dialog box provides access to commonly used settings that apply to multiple simulations.

Figure 4-7. The Graphics Settings dialog box provides access to commonly used settings that apply to multiple simulations.

You can also modify physics settings through the Physics menu item. The Physics settings allow you to control how the physics engine applies principles such as gravity. The gravity setting, which defaults to a value of 9.81, controls how the physics engine will handle gravity within the simulation scene. Typically, you will want to keep this setting as the default, but you may want to turn it off by setting it to a value of zero while making changes to the entities in edit mode.

Working with Coordinates

Unless you have spent the last several years working intimately with vector maths and computer simulations, you may feel a bit overwhelmed by some of the terms and concepts used by the simulation engine. Do not worry about it too much. MSRS hides much of the complexity from you and acts as a wrapper for functions available in the Microsoft DirectX SDK, Microsoft XNA Framework, and AGEIA PhysX SDK. This section will give you a high-level overview of the things you need to understand when working with objects in 3D space.

To represent a physical object in 3D space, you must work with coordinates that represent the object’s position. These coordinates consist of points along the X, Y, and Z axis lines. The MSRS simulation engine uses what is known as a right-handed coordinate system. This affects which direction the positive Z-axis points in. Figure 4-8 is a diagram that indicates which direction the X, Y, and Z axis lines move toward. Lines moving in the opposite direction indicate points along the negative axis.

The simulation engine uses a right-handed coordinate system, which indicates the direction the positive Z-axis points toward.

Figure 4-8. The simulation engine uses a right-handed coordinate system, which indicates the direction the positive Z-axis points toward.

When creating or editing entities, you will be able to edit the coordinates to change things such as the entity’s position. By changing the Y-axis coordinate to a higher positive value, the entity will move farther up in the simulation scene. If the value is set to a lower value, the entity moves farther down.

Tip

Tip

For readers interested in running a robot through a simulated maze, you can refer to a maze simulation tutorial hosted on Trevor Taylor’s Web site (http://sky.fit.qut.edu.au/~taylort2/MSRS/MazeSimulator/MazeSimulator.htm). Taylor is a faculty lecturer in the Information Technology department at the Queensland University of Technology. He is also an enthusiastic roboticist and MSRS expert, especially in the area of simulation. Check out his MSRS Web page at the following URL for more interesting information: http://sky.fit.qut.edu.au/~taylort2/MSRS/.

What is an Entity?

An entity represents a physical object that is used within a simulation. This can include, not only robots, but obstacles within the environment such as tables and chairs. It can also include ground and sky objects, and simulations can take place either in outdoor or indoor environments.

An entity can be hierarchical and involve parent and child relationships. This is the case when dealing with most robotics hardware where the motor base object represents the parent entity. Child entities would be the robot’s sensors and actuators. For example, the Pioneer 3DX simulated robot entity has three child entities: the bumpers, a laser rangefinder, and a Web camera.

Even the most basic simulations may contain a dozen or more entities. Complex simulations could involve hundreds or even thousands of entities. All simulations require a ground entity—unless you happen to be simulating robots floating in space. They will also require a sky object, but they do not require entities such as the sun or other elements that might appear in the sky. If the simulation is done indoors, it will typically be rendered inside a box, and you generally do not need to include things like light fixtures.

If you want to see the effect of numerous objects on a simulation, you can use one of the simulation tutorials and a Web browser to quickly add table objects to the simulation. To do this, you need to run Simulation Tutorial 2, which is available in the Visual Simulation Environment folder as the Multiple Simulated Robots simulation. When you first run this simulation, a table and two robots will appear in the simulation scene. While the simulation is running, open a Web browser and enter the following URL: http://localhost:50000/simulationtutorial2.

Your Web browser should display the state for the simulation in the form of XML. The state should contain a variable that indicates the number of tables in the simulation. If you continue to hit the refresh button in your Web browser, this number will increase by one, and tables will fall down from the sky onto the simulation scene (see Figure 4-9).

As additional entities are added to a simulation, it can cause the simulation to slow down and render at lower FPS. For this reason, you should try to limit the number of entities included in a simulation. MSRS includes several entity types (refer to Table 4-2 for a listing of these entity types) that you can use to build most of the entities you will need. The exception to this is robotics hardware not supported by MSRS and complex obstacles.

Tip

Tip

By default, the status bar is not displayed in VSE. To see the FPS settings, you will need to click on the View menu and then select Status Bar. The FPS setting will continually change even if nothing is changing within the simulation scene. This is due to things such as the refresh rate for your monitor and available CPU resources. The status bar also displays the simulation time, camera position, and Look At position.

Effect of adding multiple table objects to Simulation Tutorial 2 using a Web browser.

Figure 4-9. Effect of adding multiple table objects to Simulation Tutorial 2 using a Web browser.

Create a New Entity

To create a new entity in VSE, you must be in edit mode within the simulation environment. While in edit mode, the top-left pane will display all of the entities that currently appear in the simulation scene. When you select an item, the properties for that entity appear in the bottom-left pane. Table 4-1 lists the basic properties available for an entity.

Depending on the type of entity, there may be additional properties available. For example, an entity representing the Pioneer 3DX robot will include a property named MotorTorqueScaling, which is used to set a scaling factor that applies to all motor torque requests. Obviously, this is a property that would have no use for a sky entity. A sky entity does, however, have use for properties related to fog, such as the fog color.

Table 4-1. Basic Entity Properties

Property Name

Description

EntityState

Associated with a set of additional properties that control how the entity appears and behaves. Refer to Table 4-2 for a listing of the properties associated with entity state.

ServiceContract

Used to specify the contract for a service. The contract is associated with an HTML file, and you would need to include the entire path to the contract. When an entity is associated with a service contract, it will be included in the manifest file that is generated when a scene is saved.

InitError

Contains a description of any errors that occurred during the initialization of the entity.

Flags

Controls how the entity is rendered and can be set with one of the following options:

  • None. No rendering properties set. This is the default setting.

  • UsesAlphaBlending. Allows for transparency and, thus, more realistic scenes. Depending on the capabilities of the graphics card, using alpha blending can degrade performance.

  • DisableRendering. Turns off rendering.

  • InitializedWithState. Indicates that the entity was built by modifying the XML associated with the simulation scene.

  • DoCompletePhysicsShapeUpdate. Forces an update of all physics shapes that are part of the entity.

  • Ground. Used to specify that this is a ground entity.

ParentJoint

Specifies the joint used to connect the entity to the parent entity. This is used when you are dealing with entities composed of other entities, such as a robot with legs and/or arms.

Position

Specifies the X, Y, and Z coordinates that control where the entity is located in the simulation scene. The coordinates are specified in meters.

Rotation

Based on Euler angles, this property specifies the radians or degrees that control the orientation of the entity.

Meshes

Specifies one or more meshes associated with the entity. Meshes will be added with the VisualEntityMesh collection editor. Materials are used to form physical objects, and entities can be associated with one or more materials. It is also possible for an entity to have no materials, but this will mean the entity is not visible.

MeshRotation

Specifies the yaw, pitch, and roll values (which are stored in X, Y, and Z coordinate points), which control how the mesh object is rotated. Typically, these will be set initially with 0 values.

MeshTranslation

Specifies the X, Y, and Z coordinates that control how the mesh object is translated, relative to the origin of the entity. Typically, these will be set initially with 0 values.

MeshScale

Specifies height, width, and length values (which are stored in X, Y, and Z coordinate points), which control how the mesh is scaled. Typically, you will initially set the coordinates with a value of 1. Higher values make the object appear larger, and negative values make the object appear smaller.

Shapes

The availability of this property depends on the type of entity. For some entities, this property will not be available at all. When the entity is based on a single shape, such as a cylinder, capsule, or box, you can specify what type of shape and set additional properties associated with that shape in a separate dialog box.

If the entity is based on a specialized type that can have more than one member, such as a bumper array or wheel, then a collection editor dialog box is used to specify properties associated with each member of the array.

While in edit mode, hold down the Ctrl key to see which entity is selected. The selected entity will appear with a circle surrounding it, as shown previously in Figure 4-1. You can then use the arrow keys to move the main camera around the object as it is zoomed in. This allows you to see all sides of the object clearly. For example, Figure 4-10 shows a close-up of the rear view for the LEGO NXT. You can also use the Ctrl key and mouse to change the entity’s position or rotation. This is done by selecting the object in edit mode and also selecting the position or rotation property. While you hold down the Ctrl key, use the mouse to move or rotate the entity.

Using the Ctrl and arrow keys, you can focus in on a selected entity and view all sides such as the rear view of the LEGO NXT.

Figure 4-10. Using the Ctrl and arrow keys, you can focus in on a selected entity and view all sides such as the rear view of the LEGO NXT.

To create a new entity, click on the Entity menu, and then select New. This brings up the New Entity dialog box (see Figure 4-11) and allows you to define a new entity. The entity can be added to either the current simulation or to another assembly. An entity type (see Table 4-2 for a list of available entity types) must be selected. The entity type acts as a template for an entity and, thus, assigns initial property values for a new entity.

While in edit mode, the New Entity dialog box is used to add new entities to a simulation scene.

Figure 4-11. While in edit mode, the New Entity dialog box is used to add new entities to a simulation scene.

Table 4-2. Entity Types Available in MSRS

Entity Type

Description

ArmLinkEntity

Used to model one link of an articulated robotic arm, such as the KUKA LBR3, which has six degrees of freedom. As opposed to the KukaLBR3Entity type, this type represents just one portion of the robotic arm, and the entire arm would consist of seven links.

BumperArrayEntity

Used to create an array of bumper sensors. The entity created from this type will act as a child for a robot that uses bumper contact sensors (such as the Pioneer 3DX and iRobot Create robots).

CameraEntity

Used to create a camera entity that has a 90-degree field of view. This affects how much of the simulation scene appears in a single frame. This entity will act as a child entity for a robot that hosts the Web camera (such as the Pioneer 3DX or iRobot Create robots).

HeightFieldEntity

Used to represent a ground object and can be used to represent a flat ground. By passing in an array of height samples, you can represent the surface or an uneven terrain.

iRobotCreate

Used to model an iRobot Create robot.

KukaLBR3Entity

Used to model a KUKA LBR3 robotic arm.

LaserRangeFinderEntity

Used to create a laser rangefinder entity, which will act as a child for a robot that uses a laser rangefinder (such as the Pioneer 3DX).

LegoNXTTribot

Used to model a LEGO NXT Tribot.

LightSourceEntity

Used to create light-based entities, such as the sky or a light fixture. Light sources can be either directional, in which the light rays come from one direction, or omni, in which the light comes from all directions (like the flame from a candle does).

MultiShapeEntity

Used to define entities that consist of multiple entities. For example, the table entity that is represented in several of the simulations is built using a MultiShapeEntity type. Each shape in a MultiShapeEntity has a fixed pose in relation to the other entities.

Pioneer3DX

Used to model a MobileRobots Pioneer 3DX robot.

SimplifiedConvexMeshEnvironmentEntity

Used to generate a convex hull mesh, which specifies the surrounding area for the entity. Even though the entities may appear the same visually because of the mesh object, the entity can appear different while rendered as a physics model. This will affect how collisions with other objects are handled. See the documentation for Simulation Tutorial 5 for an example of how to use this entity type when creating table- and cone-shaped entities.

SingleShapeEntity

Used to create an entity with a single shape, such as a sphere, box, or capsule.

SkyDomeEntity

Used to render a sky using a dome two-dimensional (2D) image, rather than the cube map, which is used to create a SkyEntity. Using a 2D image is less resource-intensive and should be used unless a finer level of detail is required.

SkyEntity

Used to render a sky using a cube map, which is a six-sided image file. Two cube maps can be used: one to draw the sky and the other to light the scene. See the Simulation Tutorial 5 documentation for more information about using the SkyEntity entity type. Because the SkyEntity type involves cube maps as opposed to a 2D image, it will consume more processing power to render. If possible, the SkyDomeEntity type should be used to render a sky entity.

TerrainEntity

Used to create a complex ground entity that uses a bitmap image.

TerrainEntityLOD

Also used to create a complex ground entity, this entity type renders a finer level of detail. See the documentation for Simulation Tutorial 5 for an example of using this and the TerrainEntity entity types.

TriangleMeshEnvironmentEntity

This entity type is similar to the SimplifiedConvexMeshEnvironmentEntity except that the entity will be concave in shape. This means that the physics engine will have to work harder when working with this entity, so, generally, you will only want to use this entity type when absolutely necessary. See the documentation for Simulation Tutorial 5 for an example of how to use this entity type.

WheelEntity

This represents an actuator and will be the child entity for a robotic motor base.

Table 4-3 lists the basic properties available when you select the ellipses next to the EntityState property. Depending on what type of entity it is, the properties that appear might be slightly different. These properties control both how the entity appears when rendered and how it behaves in relation to the physics engine.

When setting the properties listed in Table 4-3, consider that MSRS represents distance in terms of meters and weight in terms of kilograms. In case you do not remember, 1 meter equals 1.093 yards or 39.37 inches. Alternatively, 1 yard equals .0914 meters or 36 inches. If you want to compute the distance of an entity in meters, you could multiply the number of yards by .0914. If you only knew the number of inches, you could multiply the number of inches by .0254. Both calculations should give you a value in meters.

Also, 1 kilogram equals 1,000 grams, and 453.59 grams equals 16 ounces or 1 pound. If you want to compute the weight in kilograms of an object weighing 3 pounds, you would first need to multiply the number of pounds by 453.59 (3 * 453.59) to arrive at a value of 1,360.77. To get the number of kilograms, divide that number by 1,000 (1360.77 / 1,000) to arrive at a value of 1.36. This would be the value you would set for the approximate number of kilograms needed to represent 3 pounds.

Table 4-3. Basic Entity State Properties

Property Name

Description

DefaultTexture

Refers to a texture file that applies to all shapes for that entity. The texture file should be a DirectX texture file, which will have a .dds file extension. The texture file applied through the entity state is optional and is only needed if a mesh object is not specified.

Effect

Refers to a special graphics effect file (FX) that can be used to render the entity. The graphics effect file is a script that tells DirectX what shaders to load. MSRS comes with several effect files (each with an .fx file extension), which can be used to accomplish various rendering effects for entities such as the sky and the terrain. The FX files supplied with MSRS can be found in the storemedia subdirectory.

Mesh

Refers to an optional mesh file that can be used to render the entity. A mesh object file, which has an .obj file extension, is created with a 3D graphical editing tool capable of exporting to an alias object format. The mesh is what makes the entity appear realistic, and, without it, the entity would appear as just a basic shape(s). You can also specify an optimized binary file, which allows the entity to render more quickly. The binary file has a .bos file extension. MSRS provides a command-line converter tool named Obj2bos.exe that you can use to convert the mesh files to a binary format. The mesh files available with the MSRS installation are located in the storemedia folder.

Flags

Specifies a flag, which affects how the entity is rendered and how it behaves. It can be set with one of the following options:

  • Kinematic Indicates that the object has infinite mass and, therefore, will remain unmovable

  • IgnoreGravity Allows you to disable the effects of gravity for a single entity

  • DisableRotationX Prevents the entity from rotating along the X-axis

  • DisableRotationY Prevents the entity from rotating along the Y-axis

  • DisableRotationZ Prevents the entity from rotating along the Z-axis

Name

This is a unique name associated with the entity.

AngularVelocity

Used to specify the speed and direction at which an entity is rotating. This is specified through X, Y, and Z coordinates points.

Velocity

Used to set the X, Y, and Z coordinates associated with the entity’s linear velocity.

AngularDamping

Used to set an integer coefficient that is associated with how an entity rotates through space in relation to its mass. The default value of 0 indicates that no damping will take place.

Density

Used to specify the density of an object, which represents the mass of an object divided by its volume. This setting is calculated by the physics engine, so there is no need to set the value to anything other than the default value of 0.

InertiaTensor

Used to specify the X, Y, and Z coordinates that control how mass is distributed across an entity. This setting is calculated by the physics engine, so there is no need to set the value to anything other than the default value of 0 for the X, Y, and Z coordinates.

LinearDamping

Used to set an integer coefficient associated with the friction produced by an entity as it moves through space. The default value of 0 indicates that no damping will take place.

Mass

Used to specify the mass of an entity in kilograms. The value assigned to the mass property is important when considering simulations that involve potential collisions. Because mass and gravity affect how much an object weighs, the higher the value for mass, the more the object will weigh. What occurs when a robot collides with another robot depends a lot on how heavy both the robots are.

The values associated with the state of an entity will change as the simulation is running. For example, the robot’s position will be determined by the X, Y, and Z coordinate values set for the position property. The initial values set for this property will change as the robot is driven around the simulation scene. You can see this for yourself by running a simulation, such as the iRobot Create simulation, and switching into edit mode. Initially, the position of the Create robot is set with the following coordinate values: 2, 0, 0. If you switch back to run mode and use the Simple Dashboard to move the Create robot, you would find that the position values have changed when you return to edit mode.

Disabling and Enabling Physics Mode

When you select edit mode, VSE will automatically turn off the physics engine. Even though you can turn it back on by clicking Enable from the Physics menu, it is generally not advisable to do so. When physics is enabled, certain things are not possible, such as two objects occupying the same point in space at the same time. This type of conflict can occur when you copy and paste an entity because the pasted version of the entity will have the same position coordinates as the original.

If you use copy and paste to create a duplicate copy of an entity while in edit mode, the new entity will appear in the top-left list of entities but will not be immediately visible in the simulation. This is because the copied entity is located in the exact same position as the original, and, thus, only one is visible. If you were to turn physics back on, you would notice that the two entities quickly move apart as if they had suddenly been thrown together and were bouncing off each other.

Alternatively, if you were to try and perform the same copy and paste operation while physics mode is enabled, then the additional entity would immediately be thrown away from the original entity. The choice of whether to enable or disable physics while in edit mode is largely a matter of personal preference and depends on what you are trying to accomplish.

More Info

More information or additional information about how to work with the menu items in VSE, refer to the documentation for Simulation Tutorial 6 in the MSRS help file.

Editing the Simulator State File

VSE allows you to save simulation scenes by clicking on File and then selecting Save Scene As. This will create two XML-based files: one is a manifest file and will contain a list of service contacts that need to be loaded to run the simulation. The other file contains information about the state of the simulator and the entities that exist within the simulation scene.

The simulator state file is a snapshot of what the simulation looked like at an exact point in time. The information within this file can be useful for many purposes. While learning about simulation and the numerous properties available for each entity, it can be helpful to browse through the simulator state file and see what values are associated with each property. For example, the following XML is only a portion of the state associated with a single-shape entity named greybox:

<BoxShape>
 <phys:BoxState>
   <phys:Name>greybox</phys:Name>
   <phys:ShapeId>Box</phys:ShapeId>
   <phys:Dimensions>
     <physm:X>1</physm:X>
     <physm:Y>1.5</physm:Y>
     <physm:Z>0.5</physm:Z>
   </phys:Dimensions>
   <phys:Radius>0</phys:Radius>
   <phys:Material>
     <phys:Name>gbox</phys:Name>
     <phys:Restitution>0.5</phys:Restitution>
     <phys:DynamicFriction>0.4</phys:DynamicFriction>
     <phys:StaticFriction>0.5</phys:StaticFriction>
     <phys:MaterialIndex>2</phys:MaterialIndex>
   </phys:Material>
   <phys:MassDensity>
     <phys:Mass>10</phys:Mass>
     <phys:InertiaTensor>
       <physm:X>0</physm:X>
       <physm:Y>0</physm:Y>
       <physm:Z>0</physm:Z>
     </phys:InertiaTensor>
     <phys:CenterOfMass>
   <physm:Position>
         <physm:X>0</physm:X>
         <physm:Y>0</physm:Y>
         <physm:Z>0</physm:Z>
       </physm:Position>
       <physm:Orientation>
         <physm:X>0</physm:X>
         <physm:Y>0</physm:Y>
         <physm:Z>0</physm:Z>
         <physm:W>0</physm:W>
       </physm:Orientation>
     </phys:CenterOfMass>
     <phys:Density>0</phys:Density>
     <phys:LinearDamping>0</phys:LinearDamping>
     <phys:AngularDamping>0</phys:AngularDamping>
   </phys:MassDensity>
   <phys:LocalPose>
     <physm:Position>
       <physm:X>0</physm:X>
       <physm:Y>0</physm:Y>
       <physm:Z>0</physm:Z>
     </physm:Position>
     <physm:Orientation>
       <physm:X>0</physm:X>
       <physm:Y>0</physm:Y>
       <physm:Z>0</physm:Z>
       <physm:W>1</physm:W>
     </physm:Orientation>
   </phys:LocalPose>
   <phys:TextureFileName />
   <phys:DiffuseColor>
     <physm:X>0.5</physm:X>
     <physm:Y>0.5</physm:Y>
     <physm:Z>0.5</physm:Z>
     <physm:W>1</physm:W>
   </phys:DiffuseColor>
   <phys:EnableContactNotifications>false</phys:EnableContactNotifications>
 </phys:BoxState>
</BoxShape>

In addition to gathering information about the entities used in a simulation, the simulation state file can be useful when there is a need to quickly edit properties or add new entities. After you make changes to a simulation state file, use the File and Open Scene menu items to reload the changes into VSE.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.207.174