Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sensor code with speed and filespace improvements. #3

Merged
merged 3 commits into from
Feb 19, 2019

Conversation

erichiggins
Copy link
Contributor

@erichiggins erichiggins commented Feb 15, 2019

Taking the advice offered in #1 , this updated version runs around 6x faster than before and trims down the output file.

Changes:

  • Changed accelerometer from 4G to 8G range.
  • Changed acceleration output from m/s² to G since it's metric/imperial agnostic.
  • Called lis.read() directly instead of lis.getEvent() for a very small speed boost (but mostly to avoid conversion from G to m/s².
  • Set accelerometer to faster data rate (unsure this has an effect due to issues in the library).
  • Use SDFat library to support long filenames.
  • Uses a full timestamp for the output filename (e.g. 201902171830.csv).
  • Set I2C speed to fast mode.
  • Define the column units (e.g. µs, G) in the header row to reduce disk usage.
  • Dropped millis() from output (same info provided by micros()).
  • Dropped battery voltage from output.
  • Dropped acceleration range from output (inconsequential).
  • Use unsigned long variables to reduce overhead.
  • Call the unixtime() just once at start up and use micros() to estimate time afterward (shaved off 30ms per loop).
  • Dropped the motion-detection aspect of data writing and simply write the data to the SD card every 800 loops.

Note: The process of writing to disk takes around 10 ms, which is still fairly slow. Ideally a buffered approach which only recorded movement would keep the output file significantly smaller. I hope to add that in a future iteration.

Chart Preview

Acceleration Chart

Output Data Format

Here's a quick comparison of what the output data looks like before and after this change.

Before

timestamp accel x accel y accel z accel unit sensor range millis micros voltage
1535376330 1.59 9.96 -1.53 m/s^2 4 128808 128808823 4.15
1535376330 2.26 11.90 -2.95 m/s^2 4 128817 128817310 4.14
1535376330 2.68 10.86 -2.09 m/s^2 4 128823 128823514 4.14
1535376330 2.39 9.46 -1.21 m/s^2 4 128829 128829672 4.15
1535376330 1.88 8.47 -1.23 m/s^2 4 128835 128835808 4.14
1535376330 1.28 7.68 -1.42 m/s^2 4 128841 128841962 4.14

After

timestamp (s) start (µs) delta (µs) accel x (G) accel y (G) accel z (G)
1547749706 123593 223 0.75 1.19 -0.19
1547749706 125917 251 0.80 1.19 -0.22
1547749706 126979 252 0.85 1.11 -0.21
1547749706 128040 252 0.85 1.09 -0.26
1547749706 129097 251 0.94 1.05 -0.22
1547749706 130158 252 0.97 1.02 -0.20

@erichiggins
Copy link
Contributor Author

@jveitchmichaelis Have any feedback on this before I merge it?

@jveitchmichaelis
Copy link

Looks good to me!

@erichiggins erichiggins merged commit f8a7a0d into master Feb 19, 2019
@erichiggins erichiggins deleted the performance branch February 19, 2019 18:44
@erichiggins
Copy link
Contributor Author

@jveitchmichaelis FYI, I posted an article to share the benefits of this update and gave you a shout out. Hope you don't mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants