1

I try to run an example script from dronekit. the code is looks like this :

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

def followme():
"""
followme - A DroneAPI example

This is a somewhat more 'meaty' example on how to use the DroneAPI.  It uses the
python gps package to read positions from the GPS attached to your laptop an
every two seconds it sends a new goto command to the vehicle.

To use this example:
* Run mavproxy.py with the correct options to connect to your vehicle
* module load api
* api start <path-to-follow_me.py>

When you want to stop follow-me, either change vehicle modes from your RC
transmitter or type "api stop".
"""
try:
    # First get an instance of the API endpoint (the connect via web case will be similar)
    api = local_connect()

    # Now get our vehicle (we assume the user is trying to control the first vehicle attached to the GCS)
    v = api.get_vehicles()[0]

    # Don't let the user try to fly while the board is still booting
    if v.mode.name == "INITIALISING":
        print "Vehicle still booting, try again later"
        return

    cmds = v.commands
    is_guided = False  # Have we sent at least one destination point?

    # Use the python gps package to access the laptop GPS
    gpsd = gps.gps(mode=gps.WATCH_ENABLE)

    while not api.exit:
        # This is necessary to read the GPS state from the laptop
        gpsd.next()

        if is_guided and v.mode.name != "GUIDED":
            print "User has changed flight modes - aborting follow-me"
            break

        # Once we have a valid location (see gpsd documentation) we can start moving our vehicle around
        if (gpsd.valid & gps.LATLON_SET) != 0:
            altitude = 30  # in meters
            dest = Location(gpsd.fix.latitude, gpsd.fix.longitude, altitude, is_relative=True)
            print "Going to: %s" % dest

            # A better implementation would only send new waypoints if the position had changed significantly
            cmds.goto(dest)
            is_guided = True
            v.flush()

            # Send a new target every two seconds
            # For a complete implementation of follow me you'd want adjust this delay
            time.sleep(2)
except socket.error:
    print "Error: gpsd service does not seem to be running, plug in USB GPS or run run-fake-gps.sh"

followme()

I try to run it in my Raspberry with Raspbian OS, but i got an error message like this :

Error : gpsd service does not seem to be running, plug in USB GPS or run run-fake-gps.sh

I get a feeling that my raspberry is needed a gps kind of device to be attached before i can run this script, but i dont really know. Please kindly tell me whats wrong with it..

the full path of instruction i got from here : http://python.dronekit.io/1.5.0/examples/follow_me.html

tkausl
  • 13,686
  • 2
  • 33
  • 50

1 Answers1

0

As the example says:

[This example] will use a USB GPS attached to your laptop to have the vehicle follow you as you walk around a field.

Without a GPS device, the code doesn't know where you are so it would not be possible to implement any sort of "following" behavior. Before running the example, you would need to:

  • Acquire some sort of GPS device (I use one of these, but there are lots of alternatives).
  • Configure gpsd on your laptop to interface with the GPS device.
larsks
  • 277,717
  • 41
  • 399
  • 399
  • How to configure gpsd and how to use gpsd in laptop?I am very difficult and the following I attached an error when the script example follow me run – yasir abdus Nov 03 '17 at 01:34