What should I change in this code for me to get in the command window a 10 data of acceleration with 1 data for 1 second?

조회 수: 1 (최근 30일)
a = arduino();
imu = mpu6050(a,'SampleRate',50,'SamplesPerRead',10,'ReadMode','Latest');
figure;
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Acceleration values from mpu6050');
x_val = animatedline('Color','r');
y_val = animatedline('Color','g');
z_val = animatedline('Color','b');
stop_time = 10; % time in seconds
count = 1;
tic;
while(toc < stop_time)
data = read(imu);
addpoints(x_val,count:(count+imu.SamplesPerRead-1),data.Acceleration(:,1));
addpoints(y_val,count:(count+imu.SamplesPerRead-1),data.Acceleration(:,2));
addpoints(z_val,count:(count+imu.SamplesPerRead-1),data.Acceleration(:,3));
count = count + imu.SamplesPerRead;
pause(0.001);
end
release(imu);

채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 31일
imu = mpu6050(a,'SampleRate',1,'SamplesPerRead',1,'ReadMode','Latest');
  댓글 수: 8
Walter Roberson
Walter Roberson 2021년 2월 1일
The code plots the first row out of each group. The groups are taken at 10 Hz and 10 are read at one time, so one second of data is read at a time, but you do not bother to plot the data corresponding to .1,.2,.3,.4,.5,.6,.7,.8,.9 of the second, just the .0 of each second.
WAN NOR NAZIRA MUSTAPA KAMAL
WAN NOR NAZIRA MUSTAPA KAMAL 2021년 2월 1일
I see. But why I observed that the graph is not compatible compare with the data in the table obtained? I meant the value in table is not the same as in the graph

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by