Toybox.Activity.Info.offCourseDistance is always null when Off Course Warnings is off

According to the API documentation, the attribute offCourseDistance in class Toybox.Activity.Info contains the distance to the nearest point on the current course in meters. I have tested the value of this attribute with a simple data field with the following code in the compute method of the View class:

function compute(info) {
if (info != null and info has :offCourseDistance) {
if (info.offCourseDistance == null) {
return "null";
} else {
return info.offCourseDistance;
}
} else {
return "-";
}


Next, I have uploaded a course on my Garmin Edge 1030, and started riding it. The Off Course Warnings setting on the Edge is off.

While I am not riding off course, the simple data field shows null (which indicates that info.offCoursedistance is null).

When I am riding deliberately off course, the simple data field still shows null. At the same time the native data field Dist. to Next, however, shows the distance between my current location and the nearest point on the course. (This behavior of this native data field is not documented, but from experience I have learned that this is the case.) Therefore, the Edge has detected that I am indeed off course.

When I repeat this test with the Off Course Warnings setting switched on, info.offCoursedistance is still null when I am not riding off course, but some value is showing in my simple data field when I ride off course. This value, however, is sometimes null, and sometimes a numeric value, but never a value that is equal to the value in the native data field Dist. to Next.

This is not at all what I expected. I would expect info.offCoursedistance to have the following value:
  • null when I am not riding a course
  • 0 when I am riding a course, and I am not off course
  • The same value shown in native data field Dist. to Next when I am riding a course and I am off course

I would expect these values to be independent from the Off Course Warnings setting. Specifically, if Off Course Warnings is off, info.offCoursedistance should still have a value when I am riding off course. Switching on Off Course Warnings has undesired side effects (buzzes, pop-ups). And what is more, there is no way in Connect IQ to check the value of the Off Course Warnings setting.

Some additional information:
  • Garmin Edge 1030, firmware version 3.90
  • Code sample created with Eclipse IDE for Java Developers Version: Oxygen.3a Release (4.7.3a) and Connect IQ SDK 3.0.7
  • Yes, that is exactly what I'm saying above. Dist. to Next is the distance from you to the next course point... the blue line in the graphic.


    I don't know about the distanceToNexPoint attribute, because I haven't tested that. But on my Edge 1030 (and also on my old Edge 800) the Dist. to Next data field does not show the distance of the blue line in your drawing, that is, the distance from the current location to the next course point when you are off course. Instead, Dist. to Next shows the distance from the current location to the nearest point on the course track, that is, the green line in your drawing. I have experienced this behavior very often. When I am riding on course, and the distance to the next course point is, say, 50 kms, Dist. to Next displays 50 kms. As soon as I go off course, Dist. to Next displays values like 10 meters, 20 meters, and so on, steadily increasing as I move away from the course. Obviously, the next course point is still approximately 50 kms away (blue line), and the values of 10 meters, 20 meters etc. are the distance from the current location to the nearest point on the course (green line). Therefore, my conclusion is that the Dist. to Next data field shows the off course distance when you are riding off course.

    I agree with your statement in my other post that info.offCourseDistance should contain the distance of the green line. Whether the value of the native data field Dist. to Next should show the distance of the green line or of the blue line is another (interesting) question.
  • Using the system I've outlined above, when you are on course, offCourseDistance could be null (you are not off course), or 0 (you are zero units from the course line). Personally, I feel like null makes sense, but neither seems wrong.

    Null indicates "no data". It should be used when off-course distance can't be determined (like when there is no GPS signal).

    And distanceToNext should be the length of the line segment from your current position to the next course point.

    No, it should be the amount of distance you need to ride on the course until the next course point.

    Yes, using the definition I've provided above, distanceToNext would be a reasonable estimate of the distance you'd have to ride to get to the next course point regardless of how far you are off course.

    No. Often, it would just be wrong. It's very rare that it would be possible to ride that straight path. So, in practice, we already know it's wrong.


    But we're not talking about an edge800. That device doesn't support ConnectIQ, and it most likely does not have any way to indicate the offCourseDistance.

    The devices tend to all work the same way for the same features. IQ is new stuff added to old stuff.

    If you're following a course and there is a detour it would seem useful to see how you are from the next course point.

    It's not that useful. It's likely that most people would not understand it. The distance people care about is how far they need to ride. The straight-line distance is almost always never the distance they need to ride (it's generally shorter).

    Certainly. And reporting the distanceToNext as the distance from the _nearest point on course_ to the _next point on course_ would be misleading as well.

    Nothing is perfect. The straight-line distance is almost always wrong (since it is rarely a path you can take).

    If you are a block off course and it reports that you are 0 meters off course, that would be very confusing.


    If you have not deviated from the course significantly (because the warning happens at a short distance) the distanceToNext number won't change by a lot, right? Only when you get off course by a significant amount would the difference even be noticeable.

    No. It depends on how close the course points are and how curvy the track is.

    A straight-line distance is a better estimate of how far you will need to go than no estimate at all.

    You always have a number. There's always an estimate. The straight-line distance is almost always wrong.

    There is no flipping. I'm suggesting that distanceToNext is always[/i] the hypotenuse of the triangle above.
    No, on the course, it's the track distance.

    If you are on course, the distanceToNext is going to be so close to the distance from the nearest point on course to the next point on course that you'd never be able to tell which is being used.

    No, that would only ever really be true for a straight track. If the track is curvy or if the course points were far apart, the straight-line distance would be wrong.
  • I don't know about the distanceToNexPoint attribute, because I haven't tested that. But on my Edge 1030 (and also on my old Edge 800) the Dist. to Next data field does not show the distance of the blue line in your drawing, that is, the distance from the current location to the next course point when you are off course. Instead, Dist. to Next shows the distance from the current location to the nearest point on the course track, that is, the green line in your drawing. I have experienced this behavior very often. When I am riding on course, and the distance to the next course point is, say, 50 kms, Dist. to Next displays 50 kms.

    When you are on course, the only reasonable thing is for the dist-to-next to indicate the track distance (the distance along the course you need to ride, taking all the curves into account).

    If you leave the track and return to it closer to the next course point, the distance is updated to reflect the point you return to.

    While you are on-course, the hypotenuse (straight-line) distance is a meaningless number.

    I agree with your statement should contain the distance of the green line.

    This is the only reasonable thing for the off-course distance to be.

    Whether the value of the native data field Dist. to Next should show the distance of the green line or of the blue line is another (interesting) question.

    If you are not very far off course, changing the value of this number to the straight line distance would sometimes, give a number that is much smaller than it was just an instance ago. That would just be confusing. Since it's only rarely possible to travel on the straight-line distance, for all practical purposes, it never indicates the distance you need to ride. In some cases, it would radically underestimate the distance.

    If you are way off-course, the dist-to-next becomes meaningless and there really isn't anyway to make it meaningful. Given that the straight-line distance is almost always wrong, it isn't a choice (it's meaningless too).


    => The distance-to-next number should decrease if you are going the right way.
    => Ideally, it should increase if you are going the wrong way.


    =====================

    The straight-line distance can be used for navigation but you also need the bearing for it to be useful. It's kind-of a specialized navigational skill. Hikers in places that don't have mapped trails (or with GPS's that don't have maps) use this method. For cycling (or driving) on roads, it's not that useful (and confusing to many people).

    Straight-line/bearing is one navigational technique.

    Track-following is a different navigational technique.

    No device should flip from one technique to another.
  • Again, this post shows my misunderstanding. It is not unreasonable to have a course with two course points and a track that has many turns.

    The course you've drawn doesn't make sense to me. If you assume that the start of the course is a course point, and the next point on the course is the X, the course is a straight line from the start to the X. If you assume that the black line is the path to follow, then:
    • The statistics will be completely wrong. The course distance will be significantly shorter than the trail the user is expected to follow, the elevation profile will be compressed..
    • Most of the trail will be off course. As soon as you leave the start heading east, you'd go off course. The distance to the course will increase until some point along the eastern edge of the bottom half of the S. As you head back toward the middle of the S, the distance to the course should decrease until you cross the middle of the S. At that point the off course distance would keep increasing until some point along the western edge of the top half of the S.
    Right?
  • Okay, I spent a few hours at the park with the edge1030 and a fenix5xplus.

    The fenix has separate Off Course and Distance To Next data fields, and the values shown in those data fields is consistent with the values in offCourseDistance and distanceToNext. The fenix does behave much like you are hoping, namely the offCourseDistance is 0 until you go off course. Once you are off course it jumps from 0 to whatever the distance is from the course line. Once you go off course though, the distanceToNext freezes until you get back on course. I verified this multiple times by walking a course, then leaving the course to walk a street parallel to the course but one block away. The distanceToNext value stuck at 130.377??? until I stepped onto the course.

    The edge1030 showed completely different behavior. When on course, the offCourseDistance would show how far you had deviated from the course. The displayed value was consistent with what I've described above (the off course distance is the distance along a line perpendicular to the course). If I left the course, I'd see offCourseDistance go to null. Occasionally I'd see it alternate between null and some bogus value. To remedy this situation, I'd have to reboot the device. Once off course, I was seeing distanceToNext go to zero. I do not believe I ever saw the edge1030 show Dist. to Next have a value that was different from the distanceToNext field (on course or off).

    Both devices, when on course, would appeared to show the distanceToNext as the distance from your current position to the next course point. I verified this by stopping at a point on a long straight stretch of the course, waiting for the GPS to settle, crossing the street, and waiting for the GPS to settle again. The last time I did this with the fenix5, it showed 166m before, and 168m after crossing the street.

  • You are right of course, I should have updated the firmware before posting. I did update the firmware to version 7.00 just now, and rode another test ride going deliberately off course, with the Off Course Warnings setting off. The results is the same: info.offCourseDistance is null.

    So if you could submit a ticket for this issue, that would be great



    I've created a ticket for this issue.
    Seeing as I was getting non-null output and you are getting null, are there any more details on what you are doing specifically might help me reproduce this problem? Anything might be usefull.
    I'm also curious what happens if you use the "navigate to start" functionality. On my device while traveling to start, if I go off course, I am getting non-null data from offCourseDistance with Off Course Warnings disabled. Is yours returning null if you go off course from the navigate to start path as well? or is it only from a course you've loaded
  • Okay, I spent a few hours at the park with the edge1030 and a fenix5xplus.

    Nice. Thanks!

    The fenix has separate Off Course and Distance To Next data fields, and the values shown in those data fields is consistent with the values in offCourseDistance and distanceToNext. The fenix does behave much like you are hoping, namely the offCourseDistance is 0 until you go off course. Once you are off course it jumps from 0 to whatever the distance is from the course line. Once you go off course though, the distanceToNext freezes until you get back on course. I verified this multiple times by walking a course, then leaving the course to walk a street parallel to the course but one block away. The distanceToNext value stuck at 130.377??? until I stepped onto the course.

    This is what I expected. (It matches what I've seen with the 800.)

    The edge1030 showed completely different behavior. When on course, the offCourseDistance would show how far you had deviated from the course. The displayed value was consistent with what I've described above (the off course distance is the distance along a line perpendicular to the course). If I left the course, I'd see offCourseDistance go to null. Occasionally I'd see it alternate between null and some bogus value. To remedy this situation, I'd have to reboot the device. Once off course, I was seeing distanceToNext go to zero. I do not believe I ever saw the edge1030 show Dist. to Next have a value that was different from the distanceToNext field (on course or off).

    This appears to be buggy behavior.

    Both devices, when on course, would appeared to show the distanceToNext as the distance from your current position to the next course point. I verified this by stopping at a point on a long straight stretch of the course, waiting for the GPS to settle, crossing the street, and waiting for the GPS to settle again. The last time I did this with the fenix5, it showed 166m before, and 168m after crossing the street.

    On a straight track, while on course, the track-distance and the straight-line distance will be the same. If the course point is around a bend, the distance-to-next (because it's the distance along the track) will be larger than the straight-line distance.

  • are there any more details on what you are doing specifically might help me reproduce this problem? Anything might be usefull.


    My use case is typically the following:
    • I create a course on a website like RideWithGPS and save it as a .tcx file or a .gpx file.
    • I upload the file to my Edge 1030 (in the NewFiles directory).
    • On the Edge, I select the course (Navigation > Courses > Saved Courses) and tap Ride.
    • If the Edge asks me whether I want to navigate to the start, I answer no.
    • I start the timer and start riding. I follow the course by looking at the map and making sure that the triangle denoting my position is on the purple line denoting the path of the course.
    • While I am riding on course, the native data field Dist. to Next displays the distance to the next course point.
      info.offCourseDistance is null.
    • When I ride off course, I see the value in the native data field Dist. to Next change from, say, 50 kms (the distance to the next course point) to a value like 10 meters, 20 meters, and so on, steadily increasing as I move away from the course, or remaining the same if I am riding parallel to the course. This value is obviously the distance of the straight line from my position to the nearest point on the path of the course.
      info.offCourseDistance is still null.
    • When I am back on course, the native data field Dist. to Next changes back to the distance to the next course point (e.g., 49 kms).
      info.offCourseDistance is still null.

    Any relevant settings that I can think of:
    • Navigation > Courses > Saved Courses > hamburger menu > Turn Guidance: off
    • Navigation > Courses > Saved Courses > hamburger menu > Off Course Warnings: off
    • Hamburger menu > Activity Profiles > select one > Navigation > Map > Guide Text: off
    • Hamburger menu > Activity Profiles > select one > Navigation > Routing > Recalculation: automatic


    I'm also curious what happens if you use the "navigate to start" functionality.


    I haven't tried that one yet, because I never use Navigate to Start. I will do a test and report back.
  • Any relevant settings that I can think of:
    • Navigation > Courses > Saved Courses > hamburger menu > Turn Guidance: off
    • Navigation > Courses > Saved Courses > hamburger menu > Off Course Warnings: off
    • Hamburger menu > Activity Profiles > select one > Navigation > Map > Guide Text: off
    • Hamburger menu > Activity Profiles > select one > Navigation > Routing > Recalculation: automatic



    It seems that "off course warnings" should be on to get a value for info.offCourseDistance to have a value.

    * Null -> off-course off (no data) -> the user isn't interested.
    * Zero -> on course (within +/- distance) -> don't bother the user by displaying small changes in a small number.
    * Number -> off course (and ~ how far you are from the track) -> the user has chosen to be warned when this happens, presumably, because they are interested in getting back on course.

    The other settings aren't relevant at all (they have nothing to do with off-course state (off-course warnings)).

    I haven't tried that one yet, because I never use Navigate to Start. I will do a test and report back.


    I believe the units only provide off course warnings when following a track. If that's the case, navigating-to-start wouldn't have off-course warnings since there is no track being followed.




  • It seems that "off course warnings" should be on to get a value for info.offCourseDistance to have a value.



    We expect that info.offCourseDistance will return non-null if you are off course regardless of the Off Course Warnings setting.

    I've been told that...
    "The distance to course value (corresponds to info.offCourseDistance) is always calculated as long as you are doing a course but not on the course at the time. The off_course_warnings_enabled flag is just used to determine if we send a notification when going into the off course case."

    So it doesn't look like that setting should have any impact.