MCPcopy
hub / github.com/dronekit/dronekit-python / goto

Function goto

examples/guided_set_speed_yaw/guided_set_speed_yaw.py:297–323  ·  view source on GitHub ↗

Moves the vehicle to a position dNorth metres North and dEast metres East of the current position. The method takes a function pointer argument with a single `dronekit.lib.LocationGlobal` parameter for the target position. This allows it to be called with different position-setting co

(dNorth, dEast, gotoFunction=vehicle.simple_goto)

Source from the content-addressed store, hash-verified

295
296
297def goto(dNorth, dEast, gotoFunction=vehicle.simple_goto):
298 """
299 Moves the vehicle to a position dNorth metres North and dEast metres East of the current position.
300
301 The method takes a function pointer argument with a single `dronekit.lib.LocationGlobal` parameter for
302 the target position. This allows it to be called with different position-setting commands.
303 By default it uses the standard method: dronekit.lib.Vehicle.simple_goto().
304
305 The method reports the distance to target every two seconds.
306 """
307
308 currentLocation = vehicle.location.global_relative_frame
309 targetLocation = get_location_metres(currentLocation, dNorth, dEast)
310 targetDistance = get_distance_metres(currentLocation, targetLocation)
311 gotoFunction(targetLocation)
312
313 #print "DEBUG: targetLocation: %s" % targetLocation
314 #print "DEBUG: targetLocation: %s" % targetDistance
315
316 while vehicle.mode.name=="GUIDED": #Stop action if we are no longer in guided mode.
317 #print "DEBUG: mode: %s" % vehicle.mode.name
318 remainingDistance=get_distance_metres(vehicle.location.global_relative_frame, targetLocation)
319 print "Distance to target: ", remainingDistance
320 if remainingDistance<=targetDistance*0.01: #Just below target, in case of undershoot.
321 print "Reached target"
322 break;
323 time.sleep(2)
324
325
326

Callers 1

Calls 2

get_location_metresFunction · 0.70
get_distance_metresFunction · 0.70

Tested by

no test coverage detected