"(Waiting for data)" and empty "InitialTimestamp" when executing the commands descriebed in "Stream Sensor Data with MATLAB Object Properties"

4 次查看(过去 30 天)
I try to read the sensor data from my phone with a MathLab script. The sensors work just fine when I read them in the "Sensors"-Tab in the MathLab-App on my phone.
Everything is set up according to the the description "Stream Sensor Data with MATLAB Object Properties" (https://de.mathworks.com/help/matlabmobile/ug/stream-sensor-data-with-mobiledev-logging-property.html)
When I execute the script in the MathLab-App on my phone the InitialTimestamp is empty (' ') and the arrays of the sensor data are empty (e. g. MagneticcField: [0x3 double] (Waiting for data))
This is the code is use:
% a script to test the sensor read out
disp('script started')
clear m
m = mobiledev
m.MagneticSensorEnabled = 1
m.PositionSensorEnabled = 1
m.Logging = 1
disp(m)
m.MagneticField
clear m
disp('script finished')
The output one my phone looks like this:
script started
m =
mobiledev with properties:
Device: 'Google - Pixel 6a(d89f)'
Connected: 1
Logging: 0
AvailableCameras: {'back' 'front'}
AvailableMicrophones: {'Pixel 6a-back' 'Pixel 6a-bottom'}
SelectedMicrophone: 'Pixel 6a-back'
InitialTimestamp: ''
AccelerationSensorEnabled: 0
AngularVelocitySensorEnabled: 0
MagneticSensorEnabled: 1
OrientationSensorEnabled: 0
PositionSensorEnabled: 1
MicrophoneEnabled: 0
Show all properties
m =
mobiledev with properties:
Device: 'Google - Pixel 6a(d89f)'
Connected: 1
Logging: 0
AvailableCameras: {'back' 'front'}
AvailableMicrophones: {'Pixel 6a-back' 'Pixel 6a-bottom'}
SelectedMicrophone: 'Pixel 6a-back'
InitialTimestamp: ''
AccelerationSensorEnabled: 0
AngularVelocitySensorEnabled: 0
MagneticSensorEnabled: 1
OrientationSensorEnabled: 0
PositionSensorEnabled: 1
MicrophoneEnabled: 0
Show all properties
m =
mobiledev with properties:
Device: 'Google - Pixel 6a(d89f)'
Connected: 1
Logging: 0
AvailableCameras: {'back' 'front'}
AvailableMicrophones: {'Pixel 6a-back' 'Pixel 6a-bottom'}
SelectedMicrophone: 'Pixel 6a-back'
InitialTimestamp: ''
AccelerationSensorEnabled: 0
AngularVelocitySensorEnabled: 0
MagneticSensorEnabled: 1
OrientationSensorEnabled: 0
PositionSensorEnabled: 1
MicrophoneEnabled: 0
Show all properties
m =
mobiledev with properties:
Device: 'Google - Pixel 6a(d89f)'
Connected: 1
Logging: 1
AvailableCameras: {'back' 'front'}
AvailableMicrophones: {'Pixel 6a-back' 'Pixel 6a-bottom'}
SelectedMicrophone: 'Pixel 6a-back'
InitialTimestamp: ''
AccelerationSensorEnabled: 0
AngularVelocitySensorEnabled: 0
MagneticSensorEnabled: 1
OrientationSensorEnabled: 0
PositionSensorEnabled: 1
MicrophoneEnabled: 0
Current Sensor Values:
MagneticField: [0x3 double] (Waiting for data)
Position Data:
Latitude: [0x1 double] (Waiting for data)
Longitude: [0x1 double] (Waiting for data)
Speed: [0x1 double] (Waiting for data)
Course: [0x1 double] (Waiting for data)
Altitude: [0x1 double] (Waiting for data)
HorizontalAccuracy: [0x1 double] (Waiting for data)
Show all properties
mobiledev with properties:
Device: 'Google - Pixel 6a(d89f)'
Connected: 1
Logging: 1
AvailableCameras: {'back' 'front'}
AvailableMicrophones: {'Pixel 6a-back' 'Pixel 6a-bottom'}
SelectedMicrophone: 'Pixel 6a-back'
InitialTimestamp: ''
AccelerationSensorEnabled: 0
AngularVelocitySensorEnabled: 0
MagneticSensorEnabled: 1
OrientationSensorEnabled: 0
PositionSensorEnabled: 1
MicrophoneEnabled: 0
Current Sensor Values:
MagneticField: [0x3 double] (Waiting for data)
Position Data:
Latitude: [0x1 double] (Waiting for data)
Longitude: [0x1 double] (Waiting for data)
Speed: [0x1 double] (Waiting for data)
Course: [0x1 double] (Waiting for data)
Altitude: [0x1 double] (Waiting for data)
HorizontalAccuracy: [0x1 double] (Waiting for data)
Show all properties
ans =
0×3 empty double matrix
script finished

采纳的回答

Suraj
Suraj 2023-6-21
Hey David,
I understand that you’re trying to collect and display sensor data using MATLAB mobile by following the steps mentioned in “Stream Sensor Data with MATLAB Object Properties”.
The reason that you’re seeing empty values for "InitialTimestamp" and other sensor data is probably because the first datapoint from the sensors is not yet received by “mobiledev” when the value of "m" is printed to the console.
A workaround to this is to wait for the first datapoint from the sensors to arrive and then perform your activity. Here is a code snippet that will work –
clear m % Clear any previous instances of mobiledev
m = mobiledev();
m.MagneticSensorEnabled = 1;
m.Logging = 1; % Start collecting sensor data
disp("Waiting for sensor data at: "+ string(datetime));
while(isempty(m.MagneticField)) % Wait for the first sensor readout
end
disp("Received sensor data at: "+ string(datetime));
m.Device
m.InitialTimestamp
m.MagneticField
m.Logging = 0; % Stop collecting sensor data
Hope this helps.
Regards,
Suraj.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sensor Data Collection 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by