diydrones/ardupilot — pull request #8 by JochenABC (2013-01-13 13:45:02+00:00)
Title: Plane: Implement counter-clockwise loitering (issue 80)

This implements counter-clockwise loitering (issue 80 of the google-code project ardupilot-mega)

Files modified:
- libraries/AP_Common/AP_Common.h: Use bit 2 of Location.options to store
loiter direction
- ArduPlane/defines.h: New bitmask MASK_OPTIONS_LOITER_DIRECTION for struct
Location bit 2
- ArduPlane/ArduPlane.pde: New variable loiter_direction
- ArduPlane/GCS_Mavlink.pde: For mavlink loiter-commands use sign of param3 to
detemine direction. Set Location.option flag accordingly
- ArduPlane/commands.pde: Make sure loiter-directions get saved into EEPROM
correctly
- ArduPlane/commands_logic.pde: Set loiter_direction on all loiter-actions
as well as RTL/instant loiter
- ArduPlane/navigation.pde: Yield loiter_direction in update_loiter

Changes to the loitering algrotihm are trivial: Just change signs in two places. The hard part is how to store the loitering direction in the mission.

Mavlink docs say: param3 of loiter-command specifies radius. If radius is positive->clockwise. If negative->counter-clockwise. (https://pixhawk.ethz.ch/mavlink/#MISSION_ITEM).

However there is no place to store param3 from the mavilink-command in the Location struct. This is why I used the existing bitfield Location.options to store information about clockwise/counter-clockwise rotation.

(Of course I could also modify the Location struct to include a new variable p3 and store loiter radius there. Just let me know if you prefer it this way)

Side effect: Since we cannot store the loiter radius in the mission-format on apm2 the radius set in the mavlink-message will be overwritten by g.loiter_radius, only the sign will be preserved.

To use counter-clockwise loitering: Enter Loiter-Waypoint into in Arduplanner. Set Param3 to negative value. Loitering direction for this waypoint should be counter clockwise.

What I did already test:

- HIL-testing on master-Branch
- Verified it really loiters CCW for all 3 types of loiter-waypoints in case radius is negative
- Verified it still loiters CW for all 3 types of loiter-waypoints in case radius is positive
- Verified you can still can read and write those waypoints with APM planner
- Verified loiting on RTL and navigation-mode LOITER is CW