Guest User

Untitled

a guest
Jul 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. int get_vel(void){
  2. //vel_per has the most recent velocity, measured in # of 100us's
  3. int i = 0;
  4. int vel_avg = 0;
  5. float vel_avg_f = vel_per;
  6.  
  7. for(i=0;i<10;i++){
  8. vel_avg_f += vel_pers[i]; //add each value to the total
  9. }
  10. vel_avg_f = vel_avg_f/vel_samples; //average the array
  11. vel_avg_f = vel_avg_f * ppr; //velocity period in ms for 1 rev
  12. vel_avg_f = 10000 / vel_avg_f; //vel freq in rev/ms *1000ms / 1s
  13. vel_avg_f = 60*vel_avg_f; //(60s / 1min) this is the rpm
  14. vel_avg = (int)vel_avg_f; //convert back to an integer
  15. return vel_avg;
  16. }
Add Comment
Please, Sign In to add comment