Last active
July 5, 2016 18:51
-
-
Save rasor/7223f9db3fd8090d64708642425f2af2 to your computer and use it in GitHub Desktop.
Suunto app. Name: GPS Lapr 400, Activity: Running, Category: Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
V.B: http://www.movescount.com/apps/app11029302-GPS_Lapr_B | |
V.A: http://www.movescount.com/apps/app11022053-GPS_Lapr_400 | |
*/ | |
/* https://gist.github.com/rasor/7223f9db3fd8090d64708642425f2af2 */ | |
/* Suunto app. Name: GPS Lapr 400, Activity: Running, Category: Counter*/ | |
/* Description: | |
Header: | |
Count laps using your start GPS point. | |
Version: | |
B. | |
Overview: | |
When you reach the point once again the counter will automatically count a lap. | |
The counter is optimized for running and will work for laps from 200 meters and up. | |
It cannot increase the laps in the watch - e.g. press the lap button. | |
So what you get it only the number of laps run - not all the lap details. | |
Details: | |
To qualify for a lap 3 conditions must be met: | |
- 33 seconds must have past | |
- Runner must have been at least 75 meters from the startline in beeline | |
- Runner must have run 150 meters in distance from the startline | |
When the runner approaches the startline a lap will be counted if he enters a into an area with radius 30 meters from the start. | |
The lap will be counted, when the runner reaches the closest point to the center of that circle. | |
*/ | |
/* Initialize own vars - set in app | |
postfix = "laps"; | |
timerHasBeenStarted = 0; | |
startHasBeenSet = 0; | |
laps = 0; //No of laps | |
latStart = -90; | |
lonStart = -180; | |
lapDuration = 0; //sec. How long has the lap been so far? | |
lapDistance = 0; //sec. How long has been run on this lap so far? | |
lapStartDuration = 0; //sec. How long time passed, when this lap started? | |
lapStartDistance = 0; //m. How long was run, when this lap started? | |
lapStartDistanceBeeline = 0; //m. How far is it to start - beeline? | |
lapDurationNotCountingThreshold = 33; //800m time/3 = 100s/3. To avoid double counting of same lap | |
lapDistanceNotCountingThreshold = 150; //If runner has not been this distance away from start, then don't inc laps | |
lapDistanceBeelineNotCountingThreshold = 75; //If runner has not been this distance away from start, then don't inc laps | |
lapDurationThresholdOk = 0; //When lapDurationNotCountingTreshold then ok | |
lapDistanceThresholdOk = 0; //When lapDistanceNotCountingThreshold then ok | |
lapDistanceBeelineThresholdOk = 0; //When lapDistanceBeelineNotCountingThreshold then ok | |
lapThresholdOk = 0; //When all Tresholds ok then ok => listen for new lap | |
lapStartZone1Radius = 30; //m. Zone around start (start area), where lap will be counted | |
lapShortestToStart = lapStartZone1Radius + 1; //When within latStartZone1 then use this to see when runner gets closest to center | |
doCountLap = 0; //if 1 then increment lap | |
lapStartZone1Entered = 0; //Has Zone1 been entered in this lap? | |
*/ | |
/* While in sport mode do this once per second*/ | |
if (timerHasBeenStarted == 0) { | |
/* check if timer has been started*/ | |
if ((SUUNTO_DURATION > 0)){ /* || (SUUNTO_DISTANCE > 0)) {*/ | |
timerHasBeenStarted = 1; | |
/* set some constants */ | |
lapStartZone1Radius = 30; | |
lapDurationNotCountingThreshold = 33; | |
lapDistanceNotCountingThreshold = 150; | |
lapDistanceBeelineNotCountingThreshold = 75; | |
/* get start position if not read, yet */ | |
if ((startHasBeenSet == 0) && (SUUNTO_GPS_STATE > 4)) { | |
latStart = SUUNTO_GPS_LATITUDE; | |
lonStart = SUUNTO_GPS_LONGITUDE; | |
startHasBeenSet = 1; | |
} | |
} | |
else{ | |
/* read position continuesly until timerHasBeenStarted. In this way we have the startpos from before 1 sec had passed*/ | |
if (SUUNTO_GPS_STATE > 4) { | |
latStart = SUUNTO_GPS_LATITUDE; | |
lonStart = SUUNTO_GPS_LONGITUDE; | |
startHasBeenSet = 1; | |
} | |
} | |
} | |
/* only calculate laps, when GPS is on and timer is started */ | |
if ((timerHasBeenStarted == 1) && (SUUNTO_GPS_STATE > 4)) { | |
/* get start position if not read, yet */ | |
if (startHasBeenSet == 0) { | |
latStart = SUUNTO_GPS_LATITUDE; | |
lonStart = SUUNTO_GPS_LONGITUDE; | |
startHasBeenSet = 1; | |
} | |
if (startHasBeenSet == 1) { | |
/* reset lap data*/ | |
laps = 0; | |
lapStartDuration = SUUNTO_DURATION; | |
lapStartDistance = SUUNTO_DISTANCE * 1000; | |
lapStartDistanceBeeline = 0; | |
lapThresholdOk = 0; | |
lapShortestToStart = lapStartZone1Radius + 1; | |
lapStartZone1Entered = 0; | |
doCountLap = 0; | |
startHasBeenSet = 2; | |
} | |
/* calculate laps - start position is now known */ | |
if (startHasBeenSet == 2) { | |
/* look for start in decimal meters */ | |
lapStartDistanceBeeline = Suunto.distance(latStart, lonStart, SUUNTO_GPS_LATITUDE, SUUNTO_GPS_LONGITUDE); | |
if (lapThresholdOk == 0) { | |
/* get values for calculate lapThresholdOk */ | |
lapDuration = SUUNTO_DURATION - lapStartDuration; | |
lapDistance = SUUNTO_DISTANCE * 1000 - lapStartDistance; | |
if (lapDuration > lapDurationNotCountingThreshold) { | |
lapDurationThresholdOk = 1; | |
} | |
if (lapDistance > lapDistanceNotCountingThreshold) { | |
lapDistanceThresholdOk = 1; | |
} | |
if (lapStartDistanceBeeline > lapDistanceBeelineNotCountingThreshold) { | |
lapDistanceBeelineThresholdOk = 1; | |
} | |
if ((lapDurationThresholdOk == 1) && (lapDistanceBeelineThresholdOk == 1) && (lapDistanceThresholdOk == 1) ) { | |
lapThresholdOk = 1; | |
} | |
} | |
if (lapThresholdOk == 1) { | |
/* Thresholds has been met - look for Zone1 */ | |
/* detect if we entered Zone1 */ | |
if (lapStartDistanceBeeline < lapStartZone1Radius) { | |
/* If Zone1 has not yet been entered in this lap */ | |
if (lapStartZone1Entered == 0) { | |
lapStartZone1Entered = 1; | |
} | |
} | |
if (lapStartZone1Entered == 1) { | |
/* if within Zone1 */ | |
if (lapStartDistanceBeeline < lapStartZone1Radius) { | |
/* if passed shortest distance (with ½ m)- meaning going away from center | |
or if distance-to-center < 3 then count lap */ | |
if ((lapStartDistanceBeeline < 3) || ((lapStartDistanceBeeline + 1/2) > lapShortestToStart)) { | |
doCountLap = 1; | |
} | |
/* else set a shorter distance */ | |
if ((doCountLap == 0) && (lapStartDistanceBeeline < lapShortestToStart)){ | |
lapShortestToStart = lapStartDistanceBeeline; | |
} | |
} | |
/* we have exited Zone1 again */ | |
else{ | |
/* if we first entered zone1 then exited without counting then force counting*/ | |
doCountLap = 1; | |
} | |
/* doCountLap() */ | |
if (doCountLap == 1) { | |
/* inc lap data*/ | |
laps = laps + 1; | |
lapStartDuration = SUUNTO_DURATION; | |
lapStartDistance = SUUNTO_DISTANCE * 1000; | |
/* reset flags */ | |
lapDurationThresholdOk = 0; | |
lapDistanceThresholdOk = 0; | |
lapDistanceBeelineThresholdOk = 0; | |
lapThresholdOk = 0; | |
lapShortestToStart = lapStartZone1Radius + 1; | |
lapStartZone1Entered = 0; | |
doCountLap = 0; | |
Suunto.alarmBeep(); | |
} | |
} | |
} | |
} | |
} | |
RESULT = laps; | |
/* | |
RESULT = laps; | |
RESULT = (100000 * (lapDistanceBeelineThresholdOk+2*lapDistanceThresholdOk+4*lapStartZone1Entered)) + (10000 * laps) + (100 * lapShortestToStart) + Suunto.distance(latStart, lonStart, SUUNTO_GPS_LATITUDE, SUUNTO_GPS_LONGITUDE); | |
RESULT = (100000 * (lapDurationThresholdOk+2*lapDistanceBeelineThresholdOk+4*lapDistanceThresholdOk)) + (10000 * laps) + (100 * lapShortestToStart) + Suunto.distance(latStart, lonStart, SUUNTO_GPS_LATITUDE, SUUNTO_GPS_LONGITUDE); | |
RESULT = (100000 * lapStartZone1Entered) + (10000 * laps) + (100 * lapShortestToStart) + Suunto.distance(latStart, lonStart, SUUNTO_GPS_LATITUDE, SUUNTO_GPS_LONGITUDE); | |
RESULT = (100000 * (lapDurationThresholdOk+2*lapDistanceBeelineThresholdOk+4*lapDistanceThresholdOk)) + (10000 * laps) + (100 * lapShortestToStart) + Suunto.distance(latStart, lonStart, SUUNTO_GPS_LATITUDE, SUUNTO_GPS_LONGITUDE); | |
RESULT = (100000 * (lapDurationThresholdOk+2*lapDistanceBeelineThresholdOk+4*lapDistanceThresholdOk)) + (10000 * lapThresholdOk) + (1000 * laps) + Suunto.distance(latStart, lonStart, SUUNTO_GPS_LATITUDE, SUUNTO_GPS_LONGITUDE); | |
RESULT = (100000 * (lapDurationThresholdOk+2*lapDistanceBeelineThresholdOk+4*lapDistanceThresholdOk)) + (10000 * lapThresholdOk) + Suunto.distance(latStart, lonStart, SUUNTO_GPS_LATITUDE, SUUNTO_GPS_LONGITUDE); | |
RESULT = (100000 * startHasBeenSet) + (10000 * lapDurationThresholdOk) + (1000 * lapDistanceBeelineThresholdOk) + (100 * lapDistanceThresholdOk) + laps; | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment