badfo1
Posts: 3
Joined: Wed Dec 05, 2018 12:57 am

Help: Automation Using GPS

Wed Dec 05, 2018 1:10 am

So I have been recently working on a progress where I ultimately want to make a robot autonomously follow gps waypoints. I have purchased a gps and have gotten it to output coordinates.

My current goal is to make it travel from its original location (A) to a point (B). The problem I am encountering is that the robot does not know what direction it is facing before it travels to point B. I was thinking of making it travel a few feet and measuring a new set of coordinates to create a bearing, so it knows what direction it is facing.

I am pretty new to python, and my largest issue is implementing this into python. My goal is: drive for a couple seconds -> make a reading -> correct course and drive for a couple more seconds -> make another reading -> drive for a couple more seconds, and so on until it is somewhere around five feet from point B. Ignoring any gps inaccuracies, how write a python code that could do this?

Thanks for any ideas/suggestions

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 21510
Joined: Sat Jul 30, 2011 7:41 pm

Re: Help: Automation Using GPS

Wed Dec 05, 2018 9:30 am

Solid state compass?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

scotty101
Posts: 3474
Joined: Fri Jun 08, 2012 6:03 pm

Re: Help: Automation Using GPS

Wed Dec 05, 2018 9:40 am

PID controller?

Use the position updates (or the heading field from the GPVTG message) to determine what your heading is and if it is not correct, apply an adjustment to the steering until the heading matches what you want.

A compass would be easier though as it would save you from having to correct the heading based on how far the robot has travelled whilst it has been moving to face the correct direction.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

gordon77
Posts: 3740
Joined: Sun Aug 05, 2012 3:12 pm

Re: Help: Automation Using GPS

Wed Dec 05, 2018 12:40 pm

What have you written so far? What motor hat are you using?

badfo1
Posts: 3
Joined: Wed Dec 05, 2018 12:57 am

Re: Help: Automation Using GPS

Wed Dec 05, 2018 4:12 pm

I am using a robopi hat. I have written a bunch of messy code that doesn't work, so I decided to restart writing it. I do have a compass that I can implement. I am trying to get it done as soon as possible, because I am in a bit of a rush to get it done for my engineering class (10 days).

scotty101
Posts: 3474
Joined: Fri Jun 08, 2012 6:03 pm

Re: Help: Automation Using GPS

Wed Dec 05, 2018 4:42 pm

badfo1 wrote:
Wed Dec 05, 2018 4:12 pm
I am using a robopi hat. I have written a bunch of messy code that doesn't work, so I decided to restart writing it. I do have a compass that I can implement. I am trying to get it done as soon as possible, because I am in a bit of a rush to get it done for my engineering class (10 days).
Robot with GPS way-point navigation is an ambitious project for such a short timescale. Best of luck.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
bensimmo
Posts: 3710
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Help: Automation Using GPS

Wed Dec 05, 2018 5:23 pm

Have you got the GPS code collecting from the GPS and printing to the screen?

Have you got the compass doing the same?

One flaw with a compass is you may need a calibration routing at the start.

Do you have the code to calculate a bearing from the GPS longitude and latitude to the target longitude and latitude?

gordon77
Posts: 3740
Joined: Sun Aug 05, 2012 3:12 pm

Re: Help: Automation Using GPS

Wed Dec 05, 2018 5:44 pm

badfo1 wrote:
Wed Dec 05, 2018 4:12 pm
I am using a robopi hat. I have written a bunch of messy code that doesn't work, so I decided to restart writing it. I do have a compass that I can implement. I am trying to get it done as soon as possible, because I am in a bit of a rush to get it done for my engineering class (10 days).
I would upload your existing code and see if you can get help with that if time is short.

badfo1
Posts: 3
Joined: Wed Dec 05, 2018 12:57 am

Re: Help: Automation Using GPS

Wed Dec 05, 2018 5:57 pm

I have the GPS code printing to the screen.

I have the compass doing the same. I am thinking of not using the compass right now because of time constraints. I would rather just write more code than implement the compass. I don't need to have a finished product by the end date, I just need something demonstrable (traveling from one point to another).

I am using a vector class to calculate the bearing from the original point to the intended destination.

User avatar
bensimmo
Posts: 3710
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Help: Automation Using GPS

Wed Dec 05, 2018 6:17 pm

Rereading you opening post, you cannot use the GNSS for your initial direction.
The compass will be needed, it tells you the direction on first read and you know the bearing, turn the robot in that direction.


I suggest you go and log a few walks and see how the GNSS responds (mine even smapling every second at 10mph will put me in drives or 3 or 4 meters out and that's with GPS/GLONASS/Beidou all being used on my back with line of sight to the sky. And it cuts through corners.

So log a journey, plot it and see how you can use that to get where you want. Use real data otherwise you don't actually know what you are working with.


Just like in orienteering, use the compass to get a bearing and travel along that, use GPS to know where along that bearing you are and correct as needed, you can compare after a bit RMC Track angle and there maybe another NMEA line with similar.
From you logging you will see if and when that can be used.

Return to “Automation, sensing and robotics”