How to record two IMU devices at the same time.
1 次查看(过去 30 天)
显示 更早的评论
I have two IMU devices.
Now I can record one IMU device.The code to record one is below.
I want to record two of these at the same time.
How do I need to change this code?
clear all;
close all;
% instrreset;
disp('Press Ctrl+C to stop collecting data!')
s=serial('com7','baudrate',9600);
fopen(s);%Open Com Port
%% set the graph
figure()
hx = animatedline('Color','r','LineWidth',1);
%hy = animatedline('Color','g','LineWidth',1);
%hz = animatedline('Color','b','LineWidth',1);
ax = gca;
ax.YGrid = 'on';
ax.YLim = [-270 270];
startTime = datetime('now');
%title(['Angle = ' num2str(A') 'deg']);
ylabel('deg');
%% set the parameter
f = 20;%DataFrequce
aa=[0 0 0];
ww=[0 0 0];
AA = [0 0 0];
tt = 0;
%a=[0 0 0]';
w=[0 0 0]';
A=[0 0 0]';
test_num = 1;
data_storage = [300000,5];
previous_sum = 0;
previous_data = 0;
%% get the angle
while(1)
Head = fread(s,2,'uint8');
if (Head(1)~=uint8(85))
continue;
end
switch(Head(2))
case 81
a = fread(s,3,'int16')/32768*16 ;
End = fread(s,3,'uint8');
case 82
w = fread(s,3,'int16')/32768*2000 ;
End = fread(s,3,'uint8');
case 83
A = fread(s,3,'int16')/32768*180;
AA = [AA;A'];
t = datetime('now') - startTime;
% Add points to animation
if AA(test_num,1) > 50
AA(test_num,1) = AA(test_num,1) - 360;
end
addpoints(hx,datenum(t),AA(test_num,1))
% Update axes
ax.XLim = datenum([t-seconds(15) t]);
datetick('x','keeplimits')
drawnow;
now = datevec(datetime('now'));
now_sum = now(1,4)*3600 + now(1,5)*60 + now(1,6);
%% we have to decide which axes we use
data = AA(test_num,1);
previous_data = data;
data_storage(test_num,1) = now_sum;
data_storage(test_num,3) = data;
test_num = test_num + 1;
End = fread(s,3,'uint8');
end
end
fclose(s);
%% get the callibration data
plot(data_storage(:,1),data_storage(:,3));
ext = ginput(3);
flex = ginput(3);
rest = ginput(3);
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!