Skip to content

Commit

Permalink
feat: refactor mission items methods for better flexibility and control
Browse files Browse the repository at this point in the history
The existing AddNavMissionItem and AddRoiMissionItem methods have been removed and replaced by newly created methods in IMissionClientEx class. The new methods now include additional parameters allowing to define more attributes of the mission item thus providing richer control when creating mission items. These changes were made to address the need for better customization and control over mission items.
  • Loading branch information
asv-soft-u01 committed Dec 7, 2023
1 parent 08cb227 commit 23ff379
Showing 1 changed file with 76 additions and 32 deletions.
108 changes: 76 additions & 32 deletions src/Asv.Mavlink/Microservices/Missions/Client/Ex/IMissionClientEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,6 @@ public static MissionItem AddSplineMissionItem(this IMissionClientEx vehicle, Ge
item.Param4.OnNext(0);
return item;
}

public static MissionItem AddNavMissionItem(this IMissionClientEx vehicle, GeoPoint point)
{
var item = vehicle.Create();
item.Location.OnNext(point);
item.AutoContinue.OnNext(true);
item.Command.OnNext(MavCmd.MavCmdNavWaypoint);
item.Current.OnNext(false);
item.Frame.OnNext(MavFrame.MavFrameGlobalInt);
item.MissionType.OnNext(MavMissionType.MavMissionTypeMission);
item.Param1.OnNext(0);
item.Param2.OnNext(0);
item.Param3.OnNext(0);
item.Param4.OnNext(0);
return item;
}

public static MissionItem AddRoiMissionItem(this IMissionClientEx vehicle, GeoPoint point)
{
var item = vehicle.Create();
item.Location.OnNext(point);
item.AutoContinue.OnNext(true);
item.Command.OnNext(MavCmd.MavCmdDoSetRoiLocation);
item.Current.OnNext(false);
item.Frame.OnNext(MavFrame.MavFrameGlobalInt);
item.MissionType.OnNext(MavMissionType.MavMissionTypeMission);
item.Param1.OnNext(0);
item.Param2.OnNext(0);
item.Param3.OnNext(0);
item.Param4.OnNext(0);
return item;
}

/// <summary>
/// Change speed and/or throttle set points. The value persists until it is overridden or there is a mode change
Expand All @@ -94,4 +62,80 @@ public static MissionItem SetVehicleSpeed(this IMissionClientEx vehicle, float s
item.Param3.OnNext(throttle);
return item;
}

/// <summary>
/// Adds navigation waypoint to MissionClients collection
/// </summary>
/// <param name="vehicle">vehicle client</param>
/// <param name="point">item location</param>
/// <param name="holdTime">time in seconds</param>
/// <param name="acceptRadius">radius in meters</param>
/// <param name="passRadius">radius in meters</param>
/// <param name="yawAngle">angle in degrees</param>
/// <returns>MissionItem creation result</returns>
public static MissionItem AddNavMissionItem(this IMissionClientEx vehicle, GeoPoint point,
float holdTime = 0, float acceptRadius = 0, float passRadius = 0, float yawAngle = float.NaN)
{
var missionItem = vehicle.Create();
missionItem.Location.OnNext(point);
missionItem.AutoContinue.OnNext(true);
missionItem.Command.OnNext(MavCmd.MavCmdNavWaypoint);
missionItem.Current.OnNext(false);
missionItem.Frame.OnNext(MavFrame.MavFrameGlobalInt);
missionItem.MissionType.OnNext(MavMissionType.MavMissionTypeMission);
missionItem.Param1.OnNext(holdTime);
missionItem.Param2.OnNext(acceptRadius);
missionItem.Param3.OnNext(passRadius);
missionItem.Param4.OnNext(yawAngle);
return missionItem;
}

public static MissionItem AddTakeOffMissionItem(this IMissionClientEx vehicle, GeoPoint point, float pitch = 0, float yawAngle = float.NaN)
{
var missionItem = vehicle.Create();
missionItem.Location.OnNext(point);
missionItem.AutoContinue.OnNext(true);
missionItem.Command.OnNext(MavCmd.MavCmdNavTakeoff);
missionItem.Current.OnNext(false);
missionItem.Frame.OnNext(MavFrame.MavFrameGlobalInt);
missionItem.MissionType.OnNext(MavMissionType.MavMissionTypeMission);
missionItem.Param1.OnNext(pitch);
missionItem.Param2.OnNext(0.0f);
missionItem.Param3.OnNext(0.0f);
missionItem.Param4.OnNext(yawAngle);
return missionItem;
}

public static MissionItem AddLandMissionItem(this IMissionClientEx vehicle, GeoPoint point, float abortAltitude = 0,
PrecisionLandMode landMode = PrecisionLandMode.PrecisionLandModeDisabled, float yawAngle = float.NaN)
{
var missionItem = vehicle.Create();
missionItem.Location.OnNext(point);
missionItem.AutoContinue.OnNext(true);
missionItem.Command.OnNext(MavCmd.MavCmdNavLand);
missionItem.Current.OnNext(false);
missionItem.Frame.OnNext(MavFrame.MavFrameGlobalInt);
missionItem.MissionType.OnNext(MavMissionType.MavMissionTypeMission);
missionItem.Param1.OnNext(abortAltitude);
missionItem.Param2.OnNext((float)landMode);
missionItem.Param3.OnNext(0.0f);
missionItem.Param4.OnNext(yawAngle);
return missionItem;
}

public static MissionItem AddRoiMissionItem(this IMissionClientEx vehicle, GeoPoint point, MavRoi roiMode = MavRoi.MavRoiLocation, float wpIndex = 0, float roiIndex = 0)
{
var missionItem = vehicle.Create();
missionItem.Location.OnNext(point);
missionItem.AutoContinue.OnNext(true);
missionItem.Command.OnNext(MavCmd.MavCmdDoSetRoi);
missionItem.Current.OnNext(false);
missionItem.Frame.OnNext(MavFrame.MavFrameGlobalInt);
missionItem.MissionType.OnNext(MavMissionType.MavMissionTypeMission);
missionItem.Param1.OnNext((float)roiMode);
missionItem.Param2.OnNext(wpIndex);
missionItem.Param3.OnNext(roiIndex);
missionItem.Param4.OnNext(0.0f);
return missionItem;
}
}

0 comments on commit 23ff379

Please sign in to comment.