/// <summary> /// Returns command for tracking target. /// </summary> /// <returns>Returns command for tracking target if any.</returns> private CommandSetTrackingTargets GetTrackCmd() { int count = 0; CommandSetTrackingTargets ret = null; foreach (Command command in m_Commands) { // find all commands for tracking targets (can be only one!!!) if (command is CommandSetTrackingTargets) { ++count; ret = command as CommandSetTrackingTargets; } } if (count > 1) { throw new Exception("More than one command for tracking targets in mission!"); } else if (count == 0) { // No tracking command, add it ret = new CommandSetTrackingTargets(Commands.CommandSetTrackingTargets); m_Commands.Add(ret); } return(ret); }
/// <summary> /// Starts planning this mission for all assigned drones to this mission. /// Even if the drone is already on another mission. /// </summary> public void Start() { // Create all waypoint commands // foreach drone add new command // Remove all waypoint commands //for (int i = 0; i < m_Commands.Count; ++i) //{ // if (m_Commands[i] is CommandSetWaypoints) // { // m_Commands.RemoveAt(i); // --i; // } //} CommandSetTrackingTargets tcmd = GetTrackCmd(); m_Commands.Clear(); m_Commands.Add(tcmd); // For each drone add new command foreach (string droneName in m_AssignedDrones) { CommandSetWaypoints cmd = new CommandSetWaypoints(Commands.CommandSetWaypoints); foreach (int index in m_WaypointsKeysOrder) { cmd.Waypoints.Add(m_Waypoints[index]); } //cmd.Waypoints = m_Waypoints.Values.ToList(); cmd.UAVId = droneName; m_Commands.Add(cmd); // Assign drones on mission AgentManager.Instance.DroneOnMission(droneName, m_MissionName); } // Add zones tracking foreach (string zone in m_Zones) { SurveyRectangleAreaNoStop(zone); } // Assign/Reassing mission in simulator Network.SimulatorClient.Instance.SendMission(this); m_IsPlaying = true; }
/// <summary> /// Removes ground target from being monitored. Stops mission execution and requests redraw on gui when removed. /// </summary> /// <param name="targetName">ground target to stop monitoring</param> public void RemoveTarget(string targetName) { Debug.Log("Removing target " + targetName); bool hasTarget = false; foreach (Command command in m_Commands) { // find all commands for tracking targets and remove this target if (command is CommandSetTrackingTargets) { CommandSetTrackingTargets cmd = command as CommandSetTrackingTargets; cmd.Targets.Remove(targetName); hasTarget = true; } } if (hasTarget) { StopActions(); ValuesChanged(); } }
/// <summary> /// Creates or adds targets to CommandSetTrackingTargets. Stops mission execution and requests redraw on gui. /// </summary> /// <param name="targets"></param> public void TrackTargets(List <string> targets) { StopActions(); // Find or create command for tracking targets CommandSetTrackingTargets cmd = GetTrackCmd(); foreach (string target in targets) { GroundTarget groundTarget = AgentManager.Instance.GetTrackableTarget(target); if (groundTarget != null) { // If such target exists, add it to command (only if unique) if (!cmd.Targets.Contains(target)) { Debug.Log("Adding " + target); cmd.Targets.Add(target); } } } ValuesChanged(); }