# 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 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

• Do you remember your high school trigonometry lessons?
– Majenko
Apr 21, 2017 at 19:03
• @Majenko yes I do remember Apr 21, 2017 at 19:07
• Then you know where you are, and you know where you want to be. Between you is a right angle triangle. Calculate the angle of the hypotenuse turn to that angle, and drive to your destination.
– Majenko
Apr 21, 2017 at 19:08
• yes I am aware of how to do that cause I have already done it in my code (Turning Calculation) what I need to know is how to write the code that to move the robot in-respect to the coordinates Apr 21, 2017 at 19:33
• You have code to turn left and right already. How far to turn I guess is the question. You have the angle you want, and you have a compass. There's multiple ways of working out how long to turn for. Experimentation may give you a specific time-per-degree, or you could turn some amount and see how far it actually turned then use that to calculate how long to turn for the rest of the turn. Then just drive straight until you're there.
– Majenko
Apr 21, 2017 at 19:58

Due to my robot I have been thinking about this problem quite a few times but I never got to coding. So this is a purely my thinking no experience.

The problem is not only calculating where you are and where to go. The robot needs to move so it needs to know whether it needs to turn (left or right; slow or fast) to drive into the correct direction.
So basically you want a method that takes the compass direction the 2 gps locations and returns a speed and turn value.
The speed and turn value will be different for a waypoint and the final destination. I thought to do so by switching to the next waypoint before coming in the "slow down area". This should make that only one algorithm can handle both situations.
I think the algorithm is likely to look like this.
Given the 2 gps locations calculate the expected compass reading.
Given the 2 gps locations calculate the distance
Based on the distance and the difference between the expected and actual compass reading decide on the speed and turn.

As to the last step there is no "one size fits all" for instance a skid driven robot may opt to turn on the spot until it hits the expected compass reading.
If you have a slow turning robot and you are close to the waypoint you may opt to drive backwards first (like parking a car)

I hope this helps
{"ft_lang_label":"__label__en","ft_lang_prob":0.93357885,"math_prob":0.60678226,"size":3092,"snap":"2022-05-2022-21","text_gpt3_token_len":717,"char_repetition_ratio":0.11463731,"word_repetition_ratio":0.015706806,"special_character_ratio":0.2351229,"punctuation_ratio":0.0686901,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9532113,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-28T23:54:19Z\",\"WARC-Record-ID\":\"<urn:uuid:f006a69a-6a60-4a5e-aef2-c36848183fc5>\",\"Content-Length\":\"232896\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:fe4a7781-0382-48d9-9d40-3dd5ff84e3b4>\",\"WARC-Concurrent-To\":\"<urn:uuid:80fb4258-ec1f-4697-9029-ba3fa96270df>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://arduino.stackexchange.com/questions/37370/how-to-move-my-robot-to-the-assigned-coordinates\",\"WARC-Payload-Digest\":\"sha1:3KMUCOWNSF4KR5HGQM6NZJI3PA7O76WE\",\"WARC-Block-Digest\":\"sha1:UDBVKGDLOLPZIR47QOQAQXRU5TFFOLHO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652663021405.92_warc_CC-MAIN-20220528220030-20220529010030-00797.warc.gz\"}"}