User`s guide
3 Simulink Interface
3-24
nh = vrnode(wh, 'Grab_Sensor');
% synchronize the translation field
sync(nh, 'translation', 'on');
% 3 alternative ways to read the synchronized field value
setpoint = getfield(nh, 'translation');
setpoint = nh.translation;
setpoint = wh.Grab_Sensor.translation;
To use the setpoint value in a Simulink model, you can write an S-function or an
MATLAB Function block that reads the sensor output periodically. For an example of
such an S-function:
1
Right-click the VR Sensor Reader block of Magnetic Levitation Model (vrmaglev)
model and select Mask > Look Under Mask.
The vrmaglev/VR Sensor Reader model displays. This model contains the vrextin
block, which is an S-function block. The vrextin S-function synchronizes the sensor
field in the setup method and periodically reads its value in the mdlUpdate
method.
2
To examine the S-function parameters, right-click vrextin and select S-Function
Parameters.
The parameters defined in the mask supply the sample time, virtual world, and the
node/field to read.
Note the following about the vrextin S-function:
• Instead of setting its own block outputs, the vrextin S-function sets the value of the
adjacent Constant block value_holder. This setting makes the VR Sensor Reader
block compatible with Simulink Coder code generation so that the model can run on
Simulink Coder targets.
• The signal loop between user action (grabbing the ball to a desired position using
a mouse) closes through the associated Simulink model vrmaglev. As a result,
grabbing the ball to a new position works only when the model is running and when
the model sets the blue selection method switch to the virtual reality sensor signal
path. To experience the behavior of the PlaneSensor using the virtual scene only, save
the maglev.wrl file under a new name and remove the comment symbol (#) to enable
the last line of this file. This action activates direct routing of sensor output to a ball
translation. You can then experiment with the newly created scene instead of the
original maglev.wrl world.