Rover Follow Me

I successfully got my rover to follow me around the yard.  Right now the code tells the rover to come when you push the down arrow button. I plan to experiment with having it send a new location every x seconds and also be able to add some offset.  I would like the offset to be to the right or left and forward back so needs to take into account the direction I'm moving but shouldn't be too tough.  Here's what I have so far in case anyone finds it helpful.

ps. sorry to all who recieved emails this is my first post and I did it the wrong way. My apologies

Its python code that I run using droneapi and mavproxy.

import pygame
import gps
import socket
import time
from droneapi.lib import VehicleMode, Location

window = pygame.display.set_mode((800,

black = (0,0,0)

api = local_connect()
v = api.get_vehicles()[0]
#~ dest_lat_offset=0.0
#~ dest_lon_offset=0.0
altitude = 30  # in meters

def getGpsLoc():
        #returns list of lat,lon
        # Use the python gps package to access the laptop GPS
        gpsd = gps.gps(mode=gps.WATCH_ENABLE)

        # Once we have a valid location (see gpsd documentation) we can start moving our vehicle around
        # This is necessary to read the GPS state from the laptop
        while gotgps:
                if (gpsd.valid & gps.LATLON_SET) != 0:
                        loc = [gpsd.fix.latitude, gpsd.fix.longitude]
                        return loc

while gameloop:
        for event in pygame.event.get():
                        comloc = Location(gpsloc[0], gpsloc[1], altitude, is_relative=True)
                        roverloc = Location(, v.location.lon, v.location.alt, is_relative=True)
                        #~ print 'comloc', comloc
                        #~ print 'roverloc', roverloc
                        #~ print 'latoffset=',dest_lat_offset
                        #~ print 'lonoffset=',dest_lon_offset
                                print 'sending vehicle now!!!!!'
                                print 'comloc', comloc
                                print 'roverloc', roverloc

                        #~ if(event.key==pygame.K_UP):
                                #~ dest_lat_offset=round(,7)
                                #~ dest_lon_offset=round(v.location.lon-gpsd.fix.longitude,7)
                                #~ altitude=v.location.alt

                        #~ if(event.key==pygame.K_LEFT):

                                print 'sending vehicle west!!'
                                dest3=Location(, v.location.lon-.000084, altitude, is_relative=True)




You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –


  • Developer

    Hi Matthew.  Great work.

    Late last week I fixed the GUIDED mode for rover and that code is in master on github.  If you don't build your own code you can download the latest build from and it will be in there. 

    The instructions in the link below are for copter but they will now also work with a Rover.  So if you do the magic "ctrl+f" in Mission Planner and select Follow Me your rover should follow you around.

    I have some more work to do in this area shortly but I'll keep you posted.

    Let us know how  you go!

    Thanks, Grant.

    • That's great thanks! I tinkered a bit with the firmware but not being a programmer decided I could get up to speed on python quicker than C. I'm glad somebody's working on it though!

      My long term goal is to put this in a tractor on my farm, I'm hoping I can get all the functionality I need using python scripts, I think it will be possible but the accuracy of the gps is going to be problematic, I read that I should be able to use the gps off my tractor which is significantly better. However I also read the the coordinates that mavlink sends are truncated and only accurate to 1m?? Know anything about that? 

    • Developer

      Yes they are only accurate to about 1m.  There is an open issue on this in github if you search.  Its just a matter of priorities.  At the moment the accuracy is fine for almost all use cases.  Its only a handful of rover users who are keen to see it improved.  It will be fixed eventually.

      Thanks, Grant.

  • Always from MAVProxy. A MAVProxy startup script would be nice then it would just be one command from the terminal to get it going.
  • 3D Robotics

    This is great! Do you run it from the Linux command line, or from within MAVProxy with "api start [program name].py"?

This reply was deleted.