MATLAB Answers

0

Outputting gyroscope data to array

Asked by Kimberly Savitsky on 7 Apr 2017
Latest activity Edited by Joseph Cheng
on 7 Apr 2017
I am trying to plot angles in the z-axis (angz) over time. I have a 1:10 sample rate, so I am able to send 10 samples at a time to an array. However, the code overwrites these 10 samples and sends only the last 10 anglez values to the array (p(n)).
I am trying to adjust the code so I can send all angz values to an array for data analysis.
while abs(angz) < 360
for n = 1:10
q = a.gyroRead('z') - dc_offsetz;
if abs(q) > threshold
dt = toc(timer);
angz = (angz + (q/32768)*sensitivityz*dt - gyro_driftz);
p(n) = angz;
end

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Joseph Cheng
on 7 Apr 2017
Edited by Joseph Cheng
on 7 Apr 2017

you're overwriting it with the p(n) as n only goes from 1 to 10 again and again. you'll have to increment p(#) beyond n or multiple of #*(1:10)
collectnum = 0;
while abs(angz) < 360
for n = 1:10
q = a.gyroRead('z') - dc_offsetz;
if abs(q) > threshold
dt = toc(timer);
angz = (angz + (q/32768)*sensitivityz*dt - gyro_driftz);
p(collectnum*10+n) = angz; %so you're increasing the index for every 10 points collected
end %added these end lines to show where you'll need to put the increment of 10 line
end
collectnum=collectnum+1; %need this after the end in your for loop to increment the multiple of 10.
end

  0 Comments

Sign in to comment.