WaypointReached = (current_position == waypoint_position); // yeah, this is clearly pseudocode
Next I tried detecting the missed/circling waypoint issue using trigonometry to determine if the position is "beyond" the waypoint. The downside here was that this approach uses a lot of math computation. And there were a lot of edge cases, especially when I tried to take shortcuts in the math.
Now, I think I have found a clever solution to the whole problem: don't look at how close the rover is to the waypoint, look at how far the rover is from the initial distance to the waypoint. In other words, when starting navigation to a waypoint, compute the distance to that waypoint; then drive that distance and assume that the waypoint was reached. Okay, the rover could get in trouble if it goes in a completely wrong direction, but if that is the case, it has bigger problems anyway. So, we can safely assume that the navigation code is at least trying to steer towards the waypoint. In which case, it is always getting closer to the waypoint, so we can assume that when it has driven the correct distance from the starting point, it has reached the waypoint, or close enough. This simplifies everything.
--
You received this message because you are subscribed to the Google Groups "diyrovers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+unsubscribe@googlegroups.com.
To post to this group, send email to diyr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diyrovers/CABTh0a1%3DCFzx3ABuxoTbO%2B5_VMty2mCOU2HurJK5djqiucVjMA%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+...@googlegroups.com.
To post to this group, send email to diyr...@googlegroups.com.
Pre-calculation each time I want to find a new waypoint:1) When determining the next waypoint (WP), calculate the vector from current position to next waypoint. This is only used when "switching to" the waypoint.2) Normalize this vector (VN), and remember the start point (SP).3) Calculate length along this vector between target waypoint and start point: D1 = dot(WP-SP, VN)
if ((GPSDistanceTo < nMinDistance) & (!bTooClose)){
// within Xm of waypoint...
sprintf(szTmp, "%.2f meters to waypoint %d (I'm at %f %f)", GPSDistanceTo, CurrentWaypoint, gps.latitude, gps.longitude);
LogFile(szTmp);
bTooClose = true;
fLastGoodCourse = GPSCourseTo;
}
// PID Input is delta from CourseTo.
PID_Input = CompassHeading - GPSCourseTo;
if (bTooClose){
// if within Xm
if ((PID_Input*PID_Input)>=2000) {
// if waypoint is more than 45 deg, then we've gone past it.
bTooClose = false;
CurrentWaypoint++; // next waypoint
sprintf(szTmp, "Next waypoint : %d (I'm at %f %f)", CurrentWaypoint, gps.latitude, gps.longitude);
LogFile(szTmp);
} else {
// if waypoint isn't more than 45 deg, keep going straight. Override PID_Input
PID_Input = CompassHeading - fLastGoodCourse;
}
}
--
You received this message because you are subscribed to the Google Groups "diyrovers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+...@googlegroups.com.
To post to this group, send email to diyr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diyrovers/16d544ea-6a2c-4aa5-a454-1b8b4d46a782%40googlegroups.com.
The waypoint threshold / transition magic is in updater.cpp, within update() which is called on an timer interrupt:
--
You received this message because you are subscribed to the Google Groups "diyrovers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+unsubscribe@googlegroups.com.
To post to this group, send email to diyr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diyrovers/c80b0de5-ca30-4fe3-9969-6bc8be3ced0a%40googlegroups.com.
The way I do it is that for any function that takes any significant amount of time to execute, I just periodically sprinkle in calls to update (and inside update is a time check that immediately returns if the time period since last called is too short). This is an annoying way to have to code, but it does work.
I'm curious how you are able to do the update on a timer interrupt? Maybe you do a lot less inside of your update?
In mine, I read sensors, check for collisions, update the PIDs, update the position and heading, update the pursuit point, calculate the steering and throttle, update the steering and throttle output, log data, check buttons and set status LEDs and LCDs (and I'm sure I missed something).
My concern is that other timers and interrupts need to also work, so you can't just disable them for the whole update (wheel encoders, PWM, etc)
And you have to deal with variable volatility and atomic operations.
So? Maybe these issues aren't as big a concern as I thought? Or more likely, you have a lot less in your update function and do the other stuff somewhere else?
The way I do it is that for any function that takes any significant amount of time to execute, I just periodically sprinkle in calls to update (and inside update is a time check that immediately returns if the time period since last called is too short). This is an annoying way to have to code, but it does work.
--
You received this message because you are subscribed to the Google Groups "diyrovers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+unsubscribe@googlegroups.com.
To post to this group, send email to diyr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diyrovers/02e4a9be-3cbd-49f0-af1a-25cfccb257ee%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diyrovers/CANqFZg3PQ5C7ifywNCmvFDzp_Q1sG%2Bp0fp4eF4iGtUUq-4D0kw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diyrovers/CADnZWKO5YiXB4CSWD8UOJ8yuY45Hc%3DskmWtwG7AC%2BNy7T%2B6B2g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diyrovers/CAJgyHGNgwPjgRcdSEp_0d_m%3DB2p7%3DzOwC%2B1YFEAOv4LOqPOT3g%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "diyrovers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+unsubscribe@googlegroups.com.
To post to this group, send email to diyr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diyrovers/508550c6-d93c-452a-af45-b5e2980d3eb2%40googlegroups.com.