The question has been asked before a long time ago but i havn't heard anything of it ever since. Is it possible to find out if a waypoint has been reached? Does dronekit implement this mavlink message? I'm programming a drone to stop for a few seconds once the waypoint is reached and havn't found a way to do so.

Views: 251

Reply to This

Replies to This Discussion

You could add a delay of 3 to 5 s in the command:

http://python.dronekit.io/automodule.html#dronekit.Command

Hope it helps!

Javier

Hi Javier,

As it did help quite a lot in part, see im trying to make the drone stop at the waypoint so it can execute a script from its computer companion. In order to do that in code i need something to tell me it reached it so it can execute. Think of it as if(waypoint_reached: Execute script.

Any ideas if that's possible?

Hi Melvin,

Check this guide and the source code in the bottom of that page. There is some code to execute some actions based on the waypoint the drone is currently heading to. You could store the next_waypoint in a variable and as soon as it changes, it means the waypoint has been reached.

# Monitor mission.  
# Demonstrates getting and setting the command number
# Uses distance_to_current_waypoint(), a convenience function for finding the  
# distance to the next waypoint.  
while True:
     nextwaypoint=vehicle.commands.next
     print 'Distance to waypoint (%s): %s' % (nextwaypoint, distance_to_current_waypoint())
     if nextwaypoint==3: #Skip to next waypoint
         print 'Skipping to Waypoint 5 when reach waypoint 3'
         vehicle.commands.next = 5
     if nextwaypoint==5: #Dummy waypoint - as soon as we reach waypoint 4 this is true and we exit.
         print "Exit 'standard' mission when start heading to final waypoint (5)"
         break;
     time.sleep(1)

Alternatively, you could try to add a listener for this variable (vehicle.commands.next), though I'm not sure it works, you have to test it first.

Observing parameter changes

Best,

Javier

Adding an observer/listener didnt work but your first idea did, thank you very much!
I got one more question, could you point me to somewhere regarding camera control via dronekit if possible? I read something about gimbal control but nothing around camera triggers.

Thanks,

-Melvin

Hi Melvin,

You can send commands in an Auto mission by using the camera commands:

http://ardupilot.org/copter/docs/common-camera-control-and-auto-mis...

Particularly, you should use DO_SET_CAM_TRIGG_DIST or DO_DIGICAM_CONTROL depending on your application. Again, I haven't tested it, but you should be able to send these commands with dronekit according to this guide:

http://python.dronekit.io/guide/auto_mode.html

Hope it helps!

Javier

I figured out how to do this with observers the other day.

    @vehicle.on_message('MISSION_ITEM_REACHED')
    def on_waypoint(self, name, message):
        print "Just reached item #{}".format(message.seq

Great find Evan, works like a charm.

Out of curiosity, how are you getting the quadcopter to stop at each waypoint?

Melvin said:

Great find Evan, works like a charm.

Ah, nevermind.  The first argument to MAV_CMD_NAV_WAYPOINT is the hold time.

Evidlo said:

Out of curiosity, how are you getting the quadcopter to stop at each waypoint?

Melvin said:

Great find Evan, works like a charm.
Yea, but i noticed that the "MISSION_ITEM_REACHED" message is thrown after the delay(atleast its like that in the simulation) and i need something to tell me when it has reached it at that exact moment. So im thinking of switchin to Loiter mode after the delay to see if it works just fine). Sadly i live in PR and still got no power to charge up my laptop(bless Irma) and test that.


Evidlo said:

Ah, nevermind.  The first argument to MAV_CMD_NAV_WAYPOINT is the hold time.

Evidlo said:

Out of curiosity, how are you getting the quadcopter to stop at each waypoint?

Melvin said:

Great find Evan, works like a charm.

I think the vehicle should come to a complete stop so long as the delay is nonzero.  Not sure what the minimum is though.

Melvin said:

Yea, but i noticed that the "MISSION_ITEM_REACHED" message is thrown after the delay(atleast its like that in the simulation) and i need something to tell me when it has reached it at that exact moment. So im thinking of switchin to Loiter mode after the delay to see if it works just fine). Sadly i live in PR and still got no power to charge up my laptop(bless Irma) and test that.


Evidlo said:

Ah, nevermind.  The first argument to MAV_CMD_NAV_WAYPOINT is the hold time.

Evidlo said:

Out of curiosity, how are you getting the quadcopter to stop at each waypoint?

Melvin said:

Great find Evan, works like a charm.

I figured this one out too.  Just use MAV_CMD_CONDITION_DELAY to add delay commands after each waypoint.

# hold position at current location for given seconds
def delay(time):
    return Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_CONDITION_DELAY, 0, 0, time, 0, 0, 0, 0, 0, 0)


Melvin said:

Yea, but i noticed that the "MISSION_ITEM_REACHED" message is thrown after the delay(atleast its like that in the simulation) and i need something to tell me when it has reached it at that exact moment. So im thinking of switchin to Loiter mode after the delay to see if it works just fine). Sadly i live in PR and still got no power to charge up my laptop(bless Irma) and test that.


Evidlo said:

Ah, nevermind.  The first argument to MAV_CMD_NAV_WAYPOINT is the hold time.

Evidlo said:

Out of curiosity, how are you getting the quadcopter to stop at each waypoint?

Melvin said:

Great find Evan, works like a charm.

Reply to Discussion

RSS

© 2017   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service