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
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.
A function with the header:
void move_robot(Vector2 dir, float speed)
would make it possible to use a PID controller for the heading and another PID controller for the velocity. One takes care of the heading ant the other one of the speed. Both run in the same interrupt.