Planning missions via Mavlink

The parameter to activate it has already been set, SR1_EXT_STAT. But there’s more than one way to do this so maybe this other way will work.

You could try sending the following near the start of your code:

// mavlink_msg_request_data_stream_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint8_t target_system, uint8_t target_component, uint8_t req_stream_id, uint16_t req_message_rate, uint8_t start_stop)
mavlink_msg_request_data_stream_pack(255, 190, &msg, 1, 1, MAV_DATA_STREAM_EXTENDED_STATUS, 2, 1);

This will tell the APM to send GPS_RAW_INT at 2Hz.

I tried the previous command (REQUEST_DATA_STREAM) with no success. Once I run this command I start receiving new telemetry messages but there’s no trace of GPS_RAW_INT. I’ve tried to change the req_stream_id argument to MAV_DATA_STREAM_ALL and MAV_DATA_STREAM_RAW_SENSORS. With this change I receive different messages but not the one I’m waiting for. Also I’ve read REQUEST_DATA_STREAM is deprecated so I’ve tried SET_MESSAGE_INTERVAL instead, which seems to be the substitute. I didin’t get the thing working.

This is what I’ve tried: (Should it work?)

  //mavlink_msg_message_interval_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,uint16_t message_id, int32_t interval_us)

  mavlink_msg_message_interval_pack(255, 190, &msg, 24, 500000);

message_id = 24 (GPS_RAW_INT)

Thank you for your help!

REQUEST_DATA_STREAM is the proper way to request data from the APM. SET_MESSAGE_INTERVAL is not supported (yet?).

Maybe it’s worth seeing if GPS is working properly by connecting your ground station (over USB)? If you see the number of satellites and/or HDOP data then it should be working. In mission planner, this info is at the lower left corner of the map window.

I would also try turning on MAV_DATA_STREAM_POSITION or MAV_DATA_STREAM_ALL and seeing if GLOBAL_POSITION_INT (id=33) messages come through.

YES! It’s working! Thank you so much jmack!

There’s no trace of GPS_RAW_INT but GLOBAL_POSITION_INT. I checked the coordinates and they are correct. So strange the GPS_RAW_INT issue.

An other question, can a mission be planned on the flight time? I think that’s possible as GUIDED MODE let’s you control the Copter on the flight time, but I wanna be sure not to crash it and throw away all the work.

You’ve been so useful to me.

Yeah, that GPS_RAW_INT issue is worth tracking down eventually but GLOBAL_POSITION_INT should work for now. The drawback to GLOBAL_POSITION_INT is that you won’t know how good the GPS fix is, so you may use bad coordinates if you grab them prior to getting a good GPS lock.

A mission may be planned at flight time. Just note that in AUTO, you cannot change the current waypoint, only future ones. So you’ll need to send waypoint 1 before switching to AUTO mode, and send all other waypoints before they become active. This should also apply to the HOME waypoint, you’d want to set it before reaching waypoint 3 (RTL) if you were to change it mid flight.

If you do need to change a waypoint while it’s active, you’d need to toggle another waypoint active and then switch back to the intended waypoint using MISSION_SET_CURRENT after you update the waypoint. If you want to update the current waypoint frequently during flight, it’s best to use GUIDED (and you can switch between AUTO and GUIDED mid-flight if that’s what you need).

I can tell you’re becoming a pro at this now. :slight_smile:

Thank you so much jmack!

I’ll have to try the GUIDED mode and use MISSION_SET_CURRENT. I’ll take that into account.

I’m really grateful for your help. You are worth much. :slight_smile:

Last doubt I promise (well, I can’t promise that). I will receive automatically MISSION_ITEM_REACHED once a mission item is done? It needs to be activated?

Also, I’ve just checked that lat and lon variables of GLOBAL_POSITION_INT messages are zero until I get the GPS lock. Enough for me!

You should get MISSION_ITEM_REACHED. You’ll also get a STATUSTEXT when reaching a waypoint. Neither of those needs to be activated, they are automatic.

Be careful using zeroes to check for good GPS. Zeros indicate bad GPS, but non-zeroes don’t indicate good GPS. In particular, when you first start acquiring, it will go from zeroes to values hundreds of km away before finally giving good values. If nothing else, wait for 10-20 seconds of non-zero values before using the data, as the first non-zero GPS values are almost surely bad.

That’s what’s good about GPS_RAW_INT, it has a fix_type flag that tells you if the data is valid.

I forgot to mention, you will probably also get MISSION_CURRENT messages regularly. Definitely check for those if MISSION_ITEM_REACHED doesn’t work.

(Just a quick suggestion @sergi_torrabadella: whenever you quote code or logfiles, you might want to quote it as `pre-formatted text` by enclosing it with ``, or as a

> blockquote by prepending it with > ,

just to make things more readable…)

Sergi, I am hitting the same issue as you were with updating waypoints using an arduino to a pixhawk. Can you share the code you used to get the flight plan updated to the APM using an arduino?