Off board control using set position target global int

I am using a pixhawk to write position target_global_int setpoints.
When I try and transition to offboard from manual it rejects my attempts.
If I send messages in the local coordinate (set_position_target_local_ned) frame it allows.
I stream messages at 10Hz.

Does this seem correct or am I missing some minor detail.

One more question

Is there some better way to send setpoints via a companion computer?

In order for the drone to stay in offboard mode, it needs to receive a regular stream of position or attitude targets, as described here. There is a timeout in the commander module that will switch the drone to another control mode if one of those messages is not received. You should also check out the flight modes page, there is a graphic that illustrates how the commander switches between flight modes.

Got it thanks,

I have been able to successfully transition to offboard control, using only the local coord system. But my project requires that I navigate dynamically to setpoint using the global_coordinate system.

E.g @10Hz
publish mavlink_msg_set_position_target_global_int

which doesn’t seem to be supported.

Why not publish a local position setpoint based on the current local position and the delta between the current global position and your target global position?

Also there are mavlink messages that I think are used for setting global position waypoints. See the messages mav_msg_command_int, mav_msg_global_position_int, and mav_msg_mission_item. Might still require you to publish attitude setpoints. I can’t say much more than that.

Someone else surely knows better - my application does not involve global position waypoints.

Thats a thought,

I could certainly find several workarounds but my concern is that I may use the system as it was not intended to be used yielding undesired results.

I noticed that dronekit uses the mavlink_msg_set_position_target_global_int in something called GUIDED mode.

I have yet to find a relationship to GUIDED Mode and any mode the pixhawk has to offer Closest thing is using
MAV_MODE_GUIDED_ARMED with the mav_set_mode message. However the system rejects these transition immediately without any feedback (status text message)

Try the AUTO_MISSION flight mode, which is one of the modes shown in the flight modes diagram. I bet that one uses the mavlink_msg_mission* messages.

Thanks for your help Joseph.

I may try this but my understanding is that a mission has to be predefined and cannot be adjusted dynamically.

Hopefully I am wrong. But I have also had trouble transitioning to AUTO or Even POS_CTL Modes without a RC Transmitter.

Personally I would recommend getting an RC transmitter so that you can implement a kill-switch and manual override anyway!

Didn’t mean to mislead, I do have a transmitter, but I am trying to implement a high-level API which can perform certain tasks without a transmitter.
Move to Waypoint

It is possible this is attainable using some other modes, but I have gotten lost in related threads and yet to find a concrete answer or documentation on the subject.

As you’ve already found out is that PX4 currently only implements local position setpoints for offboard, meaning you have to keep your own reference when navigating global coordinates. This is not wrong. However, it would be simple to implement the handling of global coordinates (SET_POSITION_TARGET_GLOBAL_INT) and PX4 would certainly welcome a PR :slight_smile:

If you need takeoff and landing, have a look at the type mask for local position setpoints here:
It allows you to tell the system that it should follow takeoff or landing logic together with the position you’re sending.

Thanks for the advice,

I wish I had more time to add it to the firmware but I don’t at the moment. I have begun restructuring my project with the anticipation of keeping my own reference and applying transformations to convert everything into the lcoal coordinate system. Maybe in the future I would consider contributing to the firmware.

One thing I continuously found confusing is that dronekit supports this form of travel with APM but PX4 does not,therefore I initially thought the modes I was attempting to achieve were possible under the PX4 flight stack. It was finally revealed to me when I looked into how dronekit is used with the Pixhawk.

I think before I write into the PX4 Firmware I would rather write support documentation and a complete wiki, to avoid other people making the same mistakes I have made.

But again, time is of the essence.

Thanks everybody for clarifying

I also need to convert the global coordinate into local coordinate.But I’m confusing how to do it. I use a Raspberry Pi to control the pixhawk with px4 flight stack. What I can obtain in my project is a waypoints list (global coordinate).Can you give me some advice?
Thank you very much!

I am trying to achieve the same, guiding with global coordinates instead of local ones.
This is an old thread, has situation changed since then?
What is the best approach currently?

Hello @danividanivi
I also encountered such problem. I want to control the drone to a global position with lat and lon in offboard mode.
And here is what I found.
Based on this issue, the branch global_to_local is working on this problem.
But it seems not work yet.
To do it in offboard mode, it might need some steps(besides translate global to local first in companion laptop side)

  1. Send mavlink_position_target_global_int_t message(or hide the global target setpoints in mavlink_position_target_local_int_t ) via mavlink.
  2. Implement a function in mavlink_receiver.cpp to decode and publish position_setpoint_triplet topic.
  3. in control module, parse the gps into local position to control mc or fw.
    However, in current code, there seems no such tendency to implement this in offboard mode at all.
    I think the designer just wants all to use such function all in the auto mode.
    To do this in auto mode, means you have to send a mavlink_mission_item_t message with target gps.
    After mavlink_mission.cpp decodes, it would write the mission info via dataman module. In mission_item, you can customize any action type you want with next target.
    Then after input all the mission point, we have to send a MAV_CMD_MISSION_START command from mavlink trigger such mission.
    I guess directly setting a gps target is not suggested, because MAV_CMD_NAV_WAYPOINT command is not implemented in commander module. If so, this is another faster way to do this.
1 Like