get real-time new coming sensor data from mobile phone, old sensor data is not include?
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to get real-time sensor data using mobile phone,
% Initialize the mobile device object
m = mobiledev;
% Enable the accelerometer sensor
m.AccelerationSensorEnabled = 1;
% Start logging accelerometer data
m.Logging = 1;
% Set the figure for real-time plotting
figure;
duration = 15; % Duration of data collection in seconds
startTime = tic; % Start the timer
% Loop to collect and display data in real-time for 15 seconds
while toc(startTime) < duration
[accelData, timeStamps] = accellog(m); % Retrieve accelerometer data and timestamps
if ~isempty(accelData)
% Plot X, Y, Z axis acceleration in different colors
plot(timeStamps, accelData(:, 1), 'r'); hold on;
plot(timeStamps, accelData(:, 2), 'g');
plot(timeStamps, accelData(:, 3), 'b');
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
legend('X-axis', 'Y-axis', 'Z-axis');
drawnow; % Update the plot in real-time
hold off;
end
pause(0.1); % Pause for smooth plotting
end
% Stop logging after the duration
m.Logging = 0;
% Optionally, retrieve all the logged data for further processing
[accelData, timeStamps] = accellog(m);
The function accellog(m) returns all logged accelerometer data from the start of the logging session, including both old and new data, in every call. It does not return only the new sensor data since the last call.
This means that in the code you provided, each time accellog(m) is called inside the loop, it will return the complete set of logged accelerometer data from the moment m.Logging = 1 was set, up to the current time.
How can I get the new coming sensor data? (logging=0 , logging=1 again is not a good way)
댓글 수: 1
Elena
2024년 9월 20일
Have you tried discardlogs(m) to achieve your goal, https://www.mathworks.com/help/matlab/ref/mobilesensor.internal.mobiledev.discardlogs.html? Thanks.
답변 (1개)
Shubham
2024년 9월 15일
Hey Jun,
I understand that when you use the function "accellog(m)", it returns the log data from pevious logging sessions as well. This is because the log functions are used to get the entire log of all the readings. Please check the 12th point from the following documentation of Sensor Data Streaming: https://www.mathworks.com/help/matlabmobile/ug/sensor-data-streaming-tutorial.html#:~:text=the%20entire%20log%20of%20all%20readings
While logging the data, you can access the current value of the sensor by accessing its properties such as:
m.Acceleration
I would recommend to first collect all the required data by enabling the logging session, do your processing upon it and then delete the object.
I hope this was helpful!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Sensor Data Collection에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!