主要内容

传感器数据流演示

控制传感器并获取数据

This example assumes that you have already installed and set upMATLAB®Mobile™on your Android™ device and connected it to the MathWorks Cloud. For information about these steps, see在您的Android设备上安装MATLAB手机Sign In to the Cloud

  1. StartMATLAB Mobileon your Android device.

  2. Sign in to the Cloud, if prompted.

  3. On theSensors屏幕MATLAB Mobile, tap the sensors that you want to send data from.

  4. Place the device where you want to acquire the sensor data, if a remote location.

  5. In MATLAB, create amobiledev目的,m

    m = mobiledev
    具有属性的MobileDev:连接:1个可用摄像机:{'Back'''''}记录:0初始timestamp:'cascelerationsEnsorenabled:1 AngularVelocitySensorEnabled:1 MagneticSEnsorEnabled:1 MagnEticSEnsorEnabled:1 entrientationsEnientationsEncomEnabled:1 entrientationsensorenabled:1个位置功能:1个支持的功能:1万博1manbetx个支持功能:1

    In the display, a value of1means enabled or on, and0means not enabled or off. In this example, you can see that the device and the Cloud are connected, and all the sensors are enabled (from the Sensors screen), but data is not being logged yet. This device contains all five sensors, but your device may not. If your device does not have a particular sensor, that sensor will always show a0in the display. The timestamp is empty because no data has been logged yet.

  6. Begin logging data from the selected sensors by enabling theLoggingproperty.

    m.Logging = 1

    This action starts the transmitting of data from all selected sensors. You can also start transmission by tapping theStartbutton inMATLAB Mobileon the device.

  7. Look at the object now that you have started logging data, using thedispfunction.

    disp(m)
    mobiledev with properties: Connected: 1 Available Cameras: {'back' 'front'} Logging: 1 InitialTimestamp: '06-08-2014 13:45:56.529' AccelerationSensorEnabled: 1 AngularVelocitySensorEnabled: 1 MagneticSensorEnabled: 1 OrientationSensorEnabled: 1 PositionSensorEnabled: 1 Current Sensor Values: Acceleration: [0.27 0.23 -10.19] (m/s^2) AngularVelocity: [-0.22 0.07 0.06] (rad/s) MagneticField: [3.56 1.56 -48.19] (microtesla) Orientation: [85.91 -27.1 0.35] (degrees) Position Data: Latitude: 41.29 (degrees) Longitude: -72.35 (degrees) Speed: 25 (m/s) Course: 83.6 (degrees) Altitude: 200.1 (m) HorizontalAccuracy: 9.0 (m) Supported functions

    在此显示中,您可以看到设备和云已连接,并且数据正在记录。您现在也可以看到InitialTimestampproperty value, and the sensor values are displayed, indicating the current measurement value when you created the object.

  8. While you are logging data, you can display the current value of any sensor using the sensor reading properties. The加速度,AngularVelocity,Orientation, 和MagneticFieldproperties display the current readings from their respective sensors. If the Position sensor is logging, you can get individual position readings using theLatitude,Longitude,水平出现,高度,Course, 和Speed特性。

    To get the current value from a sensor, use.。例如,要获取加速度读数,对于对象m:

    m.Acceleration
    ANS = 0.6945 -0.2579 9.9338

    To get the longitude reading from the Position sensor:

    大小
    ANS = -71.3517
  9. 您可以使用MATLAB中的传感器控制属性打开和关闭传感器。这与选择或取消选择传感器按钮相同MATLAB Mobileon the device, as you did in step 2. Each control property has two possible values:1用于ON或启用,以及0for off or disabled. For example, to turn the Acceleration sensor off from MATLAB:

    m.AccelerationSensorEnabled = 0

    To turn the Acceleration sensor back on:

    m.AccelerationSensorEnabled = 1
  10. Stop logging sensor data.

    m.Logging = 0
  11. You can use the sensor reading properties to get the current value of a sensor while you are logging, as shown in step 7. If you want to see the entire log of all readings, use the log functions. You can use these functions while you are still logging, or after you stop logging. Each sensor type has a log function, for example,Accellog从加速度传感器返回已记录的加速度数据。

    To get the logged acceleration data from objectm, assign the variableafor the logged acceleration data andtfor the timestamps.

    [a, t] = accellog(m);

    You can then plot the data or do other processing of the data.

  12. When you are done with the session, delete the object.

    清除m

相关话题