tortuga DataLogging Library: battery, speed, time, average...
Fork of DataLogging by
Data.cpp@2:f3c2bf5521e5, 2016-04-30 (annotated)
- Committer:
- ptuytsch
- Date:
- Sat Apr 30 13:29:23 2016 +0000
- Revision:
- 2:f3c2bf5521e5
- Parent:
- 1:6e25c2b5c20c
- Child:
- 3:610ace66d7af
adding BikeData;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ptuytsch | 0:ec76b22829d5 | 1 | #include "mbed.h" |
ptuytsch | 0:ec76b22829d5 | 2 | #include "Data.h" |
ptuytsch | 1:6e25c2b5c20c | 3 | |
ptuytsch | 1:6e25c2b5c20c | 4 | #define PPR 1 // Pulses Per Rotation |
ptuytsch | 0:ec76b22829d5 | 5 | #define periphery 2.233168 //periphery of the wheel, in this example a 28" wheel. |
ptuytsch | 0:ec76b22829d5 | 6 | |
ptuytsch | 2:f3c2bf5521e5 | 7 | #define Period 1 //1000ms |
ptuytsch | 0:ec76b22829d5 | 8 | |
ptuytsch | 2:f3c2bf5521e5 | 9 | //CONSTRUCTOR |
ptuytsch | 2:f3c2bf5521e5 | 10 | Data::Data( float startDistance, uint32_t startTime) : |
ptuytsch | 2:f3c2bf5521e5 | 11 | //count(0), |
ptuytsch | 2:f3c2bf5521e5 | 12 | distance(startDistance), |
ptuytsch | 2:f3c2bf5521e5 | 13 | lastDistance(startDistance), |
ptuytsch | 2:f3c2bf5521e5 | 14 | StartTime(time(NULL)-startTime) |
ptuytsch | 2:f3c2bf5521e5 | 15 | { |
ptuytsch | 2:f3c2bf5521e5 | 16 | |
ptuytsch | 2:f3c2bf5521e5 | 17 | } |
ptuytsch | 2:f3c2bf5521e5 | 18 | |
ptuytsch | 2:f3c2bf5521e5 | 19 | void Data::interval(int count){ |
ptuytsch | 0:ec76b22829d5 | 20 | lastDistance = count * periphery / PPR; |
ptuytsch | 0:ec76b22829d5 | 21 | distance += lastDistance; |
ptuytsch | 0:ec76b22829d5 | 22 | lastCount = count; |
ptuytsch | 2:f3c2bf5521e5 | 23 | //count = 0; |
ptuytsch | 1:6e25c2b5c20c | 24 | printf("distance: %f \r\nTime Passed: %i:%i\nAverage: %f\nSpeed: %f\n\n",distance, (time(NULL) - StartTime)/60, (time(NULL) - StartTime)%60, (distance/(time(NULL) - StartTime) * 3.6),(lastDistance/Period * 3.6)); |
ptuytsch | 0:ec76b22829d5 | 25 | } |
ptuytsch | 0:ec76b22829d5 | 26 | |
ptuytsch | 2:f3c2bf5521e5 | 27 | /*void Data::pressed(){ |
ptuytsch | 0:ec76b22829d5 | 28 | count++; |
ptuytsch | 2:f3c2bf5521e5 | 29 | }*/ |
ptuytsch | 0:ec76b22829d5 | 30 | |
ptuytsch | 2:f3c2bf5521e5 | 31 | float Data::getDistance(void){ |
ptuytsch | 0:ec76b22829d5 | 32 | return distance; |
ptuytsch | 0:ec76b22829d5 | 33 | } |
ptuytsch | 0:ec76b22829d5 | 34 | |
ptuytsch | 2:f3c2bf5521e5 | 35 | uint32_t Data::getTime(void){ |
ptuytsch | 2:f3c2bf5521e5 | 36 | return (uint32_t)(time(NULL) - StartTime); |
ptuytsch | 0:ec76b22829d5 | 37 | } |
ptuytsch | 0:ec76b22829d5 | 38 | |
ptuytsch | 2:f3c2bf5521e5 | 39 | float Data::getSpeed(void){ |
ptuytsch | 0:ec76b22829d5 | 40 | return lastDistance/Period * 3.6; |
ptuytsch | 0:ec76b22829d5 | 41 | } |
ptuytsch | 0:ec76b22829d5 | 42 | |
ptuytsch | 2:f3c2bf5521e5 | 43 | float Data::getAverage(void){ |
ptuytsch | 0:ec76b22829d5 | 44 | return distance/(time(NULL) - StartTime) * 3.6; |
ptuytsch | 0:ec76b22829d5 | 45 | } |
ptuytsch | 0:ec76b22829d5 | 46 | |
ptuytsch | 0:ec76b22829d5 | 47 | int Data::getLastCount(void){ |
ptuytsch | 0:ec76b22829d5 | 48 | return lastCount; |
ptuytsch | 0:ec76b22829d5 | 49 | } |