After you create a simulation scene, write VIs to control the components in the scene when you view it in the robotics simulator. You typically create a master simulation VI that performs the following tasks:
Use the Simulator Assistant to interactively configure the robotics simulator and interaction with robot components in a simulation scene. Drop the Simulator Assistant inside a loop and use the configuration dialog box that appears to specify the simulation instance, sensors, and actuators you want to control.
You can right-click the Simulator Assistant and select Convert to SubVI to convert the Simulator Assistant to a subVI. The subVI displays the VIs from the Simulator palette and sensors and actuator drivers for the simulation program. You can use this subVI to extend the robotics simulator architecture.
|Caution You cannot revert the subVI you convert from the Simulator Assistant back to the Simulator Assistant.|
Refer to the InvertPendulum.lvproj in the labview\examples\robotics\Simulator\InvertPendulum directory for an example of programming simulation applications using the Simulator Assistant.
You might find it useful to organize simulation programs in LabVIEW projects. Projects group files and allow you to deploy them to hardware. If you use the Robotics Environment Simulator Wizard to create a simulation scene, the wizard automatically generates a project that includes a master VI. You can add additional VIs and files to the same project. If you use the Offline Configuration VIs to create the scene, you do not need to develop the simulation VIs in a LabVIEW project.
The following block diagram shows a simple example of a master VI in a simulation program. In this example, the code between the Start Simulator Service and Stop Simulator Service VIs directs a simulated robot to travel through the environment in a straight line at the velocity the Desired Robot Velocity control specifies.
|VIs from the Simulator palette start and stop the simulator.|
|VIs from the Device I/O with Simulation palette communicate with simulated actuators on the robot.|
|The Get Simulator Reference VI returns a reference to the robot body in the simulation scene, using the robot ID to identify the correct robot.|
|An LVODE property reads the angular velocity of the robot body referenced by the Get Simulator Reference VI. The Angular Velocity indicator displays the values on the front panel.|
|LabVIEW code sets the motor speeds at which to move the robot.|
|Note To simulate a Starter Kit robot, you also can use the Starter Kit VIs to control the robot.|
Refer to the Simulated iRobot.lvproj in the labview\examples\robotics\Simulator\iRobot Create directory for an example of programming simulation applications.
Refer to the Robot Balance.lvproj in the labview\examples\robotics\Simulator\Robot Balance directory for an example of programming simulation applications.
To begin creating the master VI in a simulation program, add the Start Simulator Service and Stop Simulator Service VIs to the block diagram. The Start Simulator Service VI starts the simulator and initializes the simulation scene defined in the manifest file you wire to the manifest file input of the VI.
When you start a simulation with the Start Simulator Service VI, you must specify a value for the step size (ms) input. The step size in a simulation defines the amount of time that elapses in the simulation environment between updates the simulator makes to physical properties in the simulation. Large step sizes result in less accurate real-world behavior. Smaller step sizes result in a simulation that more accurately models real-world behavior, but they require more processor resources. National Instruments recommends step sizes of 5 to 20 ms.
After you start the simulator with the Start Simulator Service VI, use structures, VIs, functions, and other LabVIEW nodes to control the simulation. An important part of the master VI is manipulating components in the simulation scene. The simulator pairs components you define in a manifest file with LabVIEW code you write to manipulate those components.
The process you use to manipulate a component depends on the type of the component.
In simulation VIs, you manipulate robots, the environment, and obstacles with LVODE properties and methods. The following list contains examples of how you can use these properties and methods to get and set attributes of components and perform actions on the components:
Complete the following steps to manipulate a component on the block diagram.
The following block diagram shows an example of reading data from a component.
When you access components through Property Nodes and Invoke Nodes, you can control the components programmatically at run time. For example, you can set the velocity at which a robot travels by passing values to a Property Node on the block diagram through a user interface.
Use Device I/O with Simulation drivers in a simulation application to communicate with simulated sensors and actuators. The drivers on the Device I/O with Simulation palette are organized like traditional LabVIEW drivers. However, these drivers allow you to communicate with both real and simulated devices.
When you initialize communication with a simulated sensor or actuator, you must find and specify the component ID of the device with which you want to communicate.
The front panel of the master simulation VI serves as the user interface if you want to manually control any parameters at run time or display values from the scene. Add controls to the front panel to pass values into the simulation. Add indicators to display values from the simulation on the front panel. For example, you might add a numeric control to the front panel that allows you to adjust the speed at which you want a robot to travel while the simulation runs.
If you use the Robotics Environment Simulator Wizard to generate a simulation project, the master VI in the project contains a ManifestFile control that identifies the manifest file the wizard created. When you run the master VI, the manifest file must be located in the same directory as the .lvproj file.
When you run the Start Simulator Service VI, the simulation displays in a 3D picture control within a new window by default. Complete the following steps to display the simulation on the front panel of a VI rather than in a new window.