How to command counter-clockwise loiter from companion computer

I’m working on software for a companion computer that connects to pixhawk/PX4 on a fixed-wing vehicle. At some point mid-flight, I want the companion computer to command the vehicle to loiter around it’s current position. I’m able to do this by sending these commands:

  1. SET_MODE
    main_mode = PX4_CUSTOM_MAIN_MODE_AUTO
    sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_LOITER
  2. COMMAND_LONG
    command = MAV_CMD_DO_REPOSITION
    param5 = (current latitude)
    param6 = (current longitude)

My question:
The above commands cause the vehicle to loiter in a clockwise direction. How can I make the vehicle loiter in a counter-clockwise direction?

The mavlink documentation suggests that param4 (yaw) controls the loiter direction. I’ve tried setting yaw to 0, and 1, but this always results in a clockwise loiter.

I’ve looked at the PX4/Firmware code on Github, and it appears that loiter_direction is hard-coded to 1 (meaning clockwise). Am I missing something, or is there a different sequence of commands to achieve this?

Thanks in advance!

what happens if you enter a negative loiter radius?

Thanks for the response!

The MAV_CMD_DO_REPOSITION command does not support a loiter radius parameter. There are other commands which support this - namely MAV_CMD_NAV_LOITER_UNLIM.

Using QGroundControl, I can use MAV_CMD_NAV_LOITER_UNLIM as part of a mission plan. In this context, providing a negative loiter radius yields the desired behavior. It causes the vehicle to orbit the waypoint in a counter-clockwise direction.

However, this doesn’t fit my use case, because I want to issue the command mid-flight. (Is it possible to modify the current mission mid-flight?)

I ran another test with my initial SET_MODE + COMMAND_LONG messages above, this time using LOITER_UNLIM instead of DO_REPOSITION. This caused the vehicle to loiter around its current position, but it always loitered in a clockwise direction, even if I specified a negative loiter radius.