# how to move my robot to the assigned coordinates

I am working on an ground surveillance robot using an Arduino mega for programming, am using components like the HMC5883L compass, Adafruit GPS for assigning of coordinates (latitude and longitude) which are the way points, I have written up the code for both the compass and the GPS and am able to get information from them, but now what I want for my robot to move to those specified coordinates (latitude and longitude waypoints) which I don't know how to do if anyone could just write an example code for me or push me to the write place I could get a sample code please do pardon me for asking such question cause I am new to coding GPS and compass and I would appreciate it if anyone could help me out or explain a bit in details what I need to do please find my code here http://textuploader.com/drqwv

• what do loops like: while(!GPS.newNMEAreceived()) { character1=GPS.read(); } actually expecting to accomplish? It looks like it keeps throwing away a character from the GPS until some called function has received a complete NMEA sentence. Why would it be throwing away a character? Doesn't the current NMEA sentence need that char? – user3629249 Apr 24 '17 at 16:30

The GPS gives the actual coordinates. The compass gives the orientation. The waypoints also have coordinates, and as I see in your code, you have defined movement primitives for your robot.

From the actual and waypoint coordinates you cen compute the heading vector required. You can compare that with the current heading vector from the compass. Your goal is to match the required heading and then match the coordinates of the waypoints.

If you have a current measured value and a desired, waypoint value, in most cases you use a closed loop controller to make the actual value equal your desired value. PID controllers are used frequently for this. Arduino implementation here.

Your problem still is that you have defined discrete motion primitives for moving the robot, so either you go left or forward. It would help you to implement a more flexible motion submodule, which can take a direction vector and move in that direction. This direction vector should come from the unit vector of the difference for between the current position and the waypoint (desired, reference) position. The speed of the motion could (or should) be correlated with the distance between the current position and the waypoint with a threshold at the end.