Documentation

使用传感器

To interact with the simulation of a model based on user actions or events occurring in the virtual world, you can use virtual reality sensors.To move graphics objects around in a virtual world during simulation or to change their appearance, based on user actions or events, you can:

  1. 定义传感器节点,根据时间,导航和场景中的时间,导航和操作和距离发生变化,生成事件和输出值。例如,一个TouchSensor节点跟踪指向设备的位置和状态。传感器何时检测到您的几何形状TouchSensor节点父组。看将传感器添加到虚拟世界

  2. 添加A.VR来源块并选择要读取的传感器属性。看使用MATLAB读取传感器值

    Note

    而不是使用aVR来源block to read sensor values, you can write an S-function or use aMatlab功能block.

    如果您在Matlab工作®, you can read sensor values usingvrnode.object properties.

  3. 使用a读取传感器值VR来源块,其输出可用于驱动模拟行为。

将传感器添加到虚拟世界

You can set up an interface in a Simulink®框图到虚拟现实场景中的传感器。您还可以从虚拟世界以编程方式输入信号到仿真模型中。

虚拟现实场景可以包含传感器,这是根据时间,导航和场景中的时间,导航和操作和距离变化生成事件和输出值的节点。这些节点为虚拟世界添加了交互性。虚拟世界传感器类似于现实的世界传感器,如超声波,激光雷达和触摸传感器。您可以使用金宝appSimulink 3D动画™functions to read sensor field values into simulation models and control simulation based on the user interaction with the virtual scene.

您可以使用传感器的方式包括:

  • Use sensor data from a virtual world to control a simulation.

  • 提供虚拟世界中的用户导航和交互与模型的仿真之间的交互性。

  • Have a simulation react to virtual world events, such as time ticks or outputs from scripts.

  • Use static information from the virtual world, such as the size of a box, to control a simulation.

您可以使用collision detection to accurately model physical constraints of objects in the real world, where generally two objects cannot be in the same place at the same time. You can use collision detection node outputs to:

  • Change the state of other virtual world nodes.

  • Apply MATLAB algorithms to collision data.

  • 驱动Simu金宝applink模型。

For example, you can use geometric sensors for robotics modeling. For more information, seeDetect Object Collisions

You can define these sensors in a scene.

Sensors 描述
CylinderSensor 将指针运动(例如,鼠标)映射到与之对齐的无形圆柱体上的旋转中y-axis of the local coordinate system.
PlaneSensor Maps pointing device motion into two-dimensional translation in a plane parallel to thez= 0局部坐标系的平面。
ProximitySensor Generates events when the viewer enters, exits, and moves within a region in space (defined by a box)
Spheresensor Maps pointing device motion into spherical rotation about the origin of the local coordinate system
TimeSensor Generates events as time passes
TouchSensor 追踪指向设备的位置和状态,并检测到您的几何图形时TouchSensor节点父组。
VisibilitySensor Detects visibility changes of a rectangular box as you navigate the world.
PointPickSensor 使用c点louds to detect which of the points are inside colliding geometries
LinePickSensor Uses ray fans or other sets of lines that detect the distance to the colliding geometries
PrimitivePickSensor 检测碰撞几何形状的原始几何形状(如锥形,球体或盒子)

Read Sensor Values

You can read values from sensor nodes in a virtual world by using:

使用VR源块读取传感器值

您可以使用theVR来源block for interactivity between a user navigating the virtual world and the simulation of a Simulink model. TheVR来源block registers user interactions with the virtual world and passes that data to the model to affect the simulation of the model. TheVR来源块从“块参数”对话框中指定的虚拟世界字段中读取值,并将它们输入到模型中。

For example, you can specify setpoints (the desired positions) in the virtual world, so that a user can specify the location of a virtual world object interactively. The simulation then responds to the changed location of the object. TheVR来源块可以从虚拟世界读取到模型事件中,例如脚本的时间滴答或输出。这VR来源块还可以读取有关虚拟世界的模型静态信息(例如,虚拟世界3D文件中定义的框的大小)。

例如,使用a的例子VR来源block, seeVirtual Control PanelMagnetic Levitation Model

Read Sensor Values Using S-Functions

要在Simulink模型中使用设定值值,您可以编写S函数或一个金宝appMatlab功能block that reads the sensor output periodically. This example uses an S-function.

  1. 右键单击VR传感器阅读器block ofMagnetic Levitation Model(vrmaglev) model and select面具>Look Under Mask

    VRMAGLEV / VR传感器读卡器模型显示。此模型包含vrextin.block, which is an S-function block. The vrextin S-function synchronizes the sensor field in thesetupmethod and periodically reads its value in themdlupdate.方法。

  2. 检查S函数参数。右键点击vrextin.和selectS函数参数

    这parameters defined in the mask supply the sample time, virtual world, and the node and field to read.

关于VREXTIN S函数的注意事项

  • 而不是设置自己的块输出,而不是设置vrextin.S-function sets the value of the adjacent Constant blockvalue_holder.。这个设置使得VR传感器阅读器块兼容金宝appSimulink Coder™code generation so that the model can run on金宝appSimulink编码器targets.

  • 用户动作(使用鼠标移动到所需位置)之间的信号循环通过相关联的Simulink模型关闭金宝appvrmaglev。只有当模型运行时才能抓住球并将其移动到新位置,并且当模型将蓝色选择方法切换到虚拟现实传感器信号路径时,才能将其移动到新位置。仅使用虚拟场景才能体验到飞往飞机的行为,保存maglev.wrl文件下的新名称。删除注释符号(#)以启用此文件的最后一行。这些操作激活传感器输出的直接路由到球形转换。然后,您可以尝试新创建的场景而不是原始的maglev.wrl世界。

    将grab_sensor.translation_Changed向Ball.Translation
  • 您可以使用此方法从类型的所有节点字段中输入信息exposedField要么eventOut,不仅是传感器eventOut场地。看VRML数据类类型有关虚拟世界数据类类型的更多信息。

  • For fields of classexposedField, you can use an alternate name using the field name with the suffix,_加剧。For example,translationtranslation_changed是请求翻译字段值的替代名称Grab_Sensornode.

看Also

相关话题