Mitchell Pang / Regrind
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Regrind.cpp Source File

Regrind.cpp

00001 #include "mbed.h"
00002 #include "Regrind.h"
00003 
00004 Regrind::Regrind (){
00005     timeSeen = 0;
00006     location = 0;
00007     velocity = 0;
00008     acceleration = 0;
00009     divert = 0;
00010     pastDiverter = 0;
00011     
00012     t = Timer();
00013 };
00014 
00015 Regrind::Regrind (double tS, int l, double v, double a, int d, int pD){
00016     timeSeen = tS;
00017     location = l;
00018     velocity = v;
00019     acceleration = a;
00020     divert = d;
00021     pastDiverter = pD;
00022     
00023     t.start();
00024 };
00025 
00026 void Regrind::setVelocity(double distance){
00027     int timePassed_us = t.read_us();
00028     velocity = 2*distance/timePassed_us/1e6;
00029     location = 2;
00030 };
00031 
00032 void Regrind::setAcceleration(double distance){
00033     t.stop();
00034     int timePassed_us = t.read_us();
00035     acceleration = (2*distance)/((timePassed_us/1e6)*(timePassed_us/1e6));
00036     location = 3;
00037 };
00038 
00039 void Regrind::clearRegrind(){
00040     timeSeen = 0;
00041     location = 0;
00042     velocity = 0;
00043     acceleration = 0;
00044     divert = 0;
00045     pastDiverter = 0;
00046     t.reset();
00047 };