Beispiel #1
0
 private void updateMissionTool_Click(object sender, EventArgs e)
 {
     try
     {
         if (RemoraCommon.Communicator.ArbiterRemote != null)
         {
             if (RemoraCommon.RoadNetwork != null && RemoraCommon.Mission != null)
             {
                 bool   b = RemoraCommon.Communicator.ArbiterRemote.UpdateMission(RemoraCommon.Mission);
                 string s = b ? "Mission set successfully" : "Mission Update Failed";
                 RemoraOutput.WriteLine("s", OutputType.Remora);
             }
             else
             {
                 RemoraOutput.WriteLine("Mission needs to have value for update", OutputType.Remora);
             }
         }
         else
         {
             RemoraOutput.WriteLine("Arbiter Remote needs to be initialized", OutputType.Remora);
         }
     }
     catch (Exception ex)
     {
         RemoraOutput.WriteLine(ex.ToString(), OutputType.Remora);
     }
 }
Beispiel #2
0
 private void jumpstartAiTool_Click(object sender, EventArgs e)
 {
     try
     {
         if (RemoraCommon.Communicator.ArbiterRemote != null)
         {
             if (RemoraCommon.RoadNetwork != null && RemoraCommon.Mission != null)
             {
                 RemoraCommon.Communicator.ArbiterRemote.JumpstartArbiter(RemoraCommon.RoadNetwork, RemoraCommon.Mission);
             }
             else
             {
                 RemoraOutput.WriteLine("Road and Mission need to have value for jumpstart", OutputType.Remora);
             }
         }
         else
         {
             RemoraOutput.WriteLine("Arbiter Remote needs to be initialized", OutputType.Remora);
         }
     }
     catch (Exception ex)
     {
         RemoraOutput.WriteLine(ex.ToString(), OutputType.Remora);
     }
 }
        /// <summary>
        /// Sets the road network
        /// </summary>
        /// <param name="roads"></param>
        private void SetRoadNetwork(ArbiterRoadNetwork roads)
        {
            // set network
            RemoraCommon.RoadNetwork = roads;

            // clean out display
            this.roadDisplay1.RemoveDisplayObjectType(this.roadDisplay1.RoadNetworkFilter);

            // add to display
            this.roadDisplay1.AddDisplayObjectRange(roads.DisplayObjects);

            // notify
            RemoraOutput.WriteLine("Set Road Network", OutputType.Remora);

            // test mission
            if (RemoraCommon.Mission != null)
            {
                RemoraOutput.WriteLine("Testing Previously Loaded Mission aginst new Road Network, Removing and Reloading", OutputType.Remora);
                ArbiterMissionDescription tmp = RemoraCommon.Mission;
                RemoraCommon.Mission = null;
                this.SetMission(tmp);
            }

            // redraw
            this.roadDisplay1.Invalidate();
        }
        /// <summary>
        /// Remove the client selected in the list view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RemoveClientButtons_Click(object sender, EventArgs e)
        {
            try
            {
                System.Windows.Forms.ListView.SelectedListViewItemCollection slvic = this.ClientListView.SelectedItems;
                ListViewItem toRemove = null;

                if (slvic != null)
                {
                    foreach (ListViewItem lvi in slvic)
                    {
                        System.Windows.Forms.ListViewItem.ListViewSubItemCollection lvsic = lvi.SubItems;

                        if (this.clientHandler.AvailableClients.ContainsKey(lvsic[1].Text))
                        {
                            this.clientHandler.Remove(lvsic[1].Text);
                            toRemove = lvi;
                        }
                    }
                }

                if (toRemove != null)
                {
                    this.ClientListView.Items.Remove(toRemove);
                }
            }
            catch (Exception ex)
            {
                RemoraOutput.WriteLine("Removal of Client Failed: \n " + ex.ToString(), OutputType.Remora);
            }
        }
        /// <summary>
        /// What to do on load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Remora_Load(object sender, EventArgs e)
        {
            if (!this.DesignMode)
            {
                // set output
                RemoraOutput.SetTextBox(this.RemoraTextBox);
                RemoraOutput.RemoraMain = this;

                // comms
                RemoraCommon.Communicator = new Communicator(this);
                RemoraCommon.Communicator.BeginCommunications();

                // update!
                updateThread = new Thread(UpdateThread);
                updateThread.IsBackground = true;
                updateThread.Priority     = ThreadPriority.Normal;
                updateThread.Start();

                // client
                this.clientHandler = new ClientHandler();

                // event for machine name updates
                RemoraCommon.Communicator.ManchineNameUpdate += new Communicator.MachineEventHandler(Communicator_ManchineNameUpdate);
            }
        }
 /// <summary>
 /// Called when message sent to us
 /// </summary>
 /// <param name="channelName"></param>
 /// <param name="message"></param>
 public void MessageArrived(string channelName, object message)
 {
     if (channelName == "ArbiterSceneEstimatorPositionChannel" + RemoraCommon.Communicator.RemotingSuffix &&
         message is VehicleState)
     {
         // cast and set
         vehicleState = (VehicleState)message;
     }
     else if (channelName == "ObservedObstacleChannel" + RemoraCommon.Communicator.RemotingSuffix &&
              message is SceneEstimatorUntrackedClusterCollection)
     {
         // cast and set
         observedObstacles = (SceneEstimatorUntrackedClusterCollection)message;
     }
     else if (channelName == "ObservedVehicleChannel" + RemoraCommon.Communicator.RemotingSuffix &&
              message is SceneEstimatorTrackedClusterCollection)
     {
         // cast and set
         observedVehicles = (SceneEstimatorTrackedClusterCollection)message;
     }
     else if (channelName == "VehicleSpeedChannel" + RemoraCommon.Communicator.RemotingSuffix &&
              message is double)
     {
         // cast and set
         vehicleSpeed = (double)message;
     }
     else if (channelName == "ArbiterOutputChannel" + RemoraCommon.Communicator.RemotingSuffix &&
              message is string)
     {
         // output
         RemoraOutput.WriteLine((string)message, OutputType.Arbiter);
     }
     else if (channelName == "ArbiterInformationChannel" + RemoraCommon.Communicator.RemotingSuffix &&
              message is ArbiterInformation)
     {
         // set info
         RemoraCommon.aiInformation.information = (ArbiterInformation)message;
     }
     else if (channelName == "SideObstacleChannel" + RemoraCommon.Communicator.RemotingSuffix &&
              message is SideObstacles)
     {
         SideObstacles sideSickObstacles = (SideObstacles)message;
         if (sideSickObstacles.side == SideObstacleSide.Driver)
         {
             this.sideSickObstaclesDriver = sideSickObstacles;
         }
         else
         {
             this.sideSickObstaclesPass = sideSickObstacles;
         }
     }
 }
Beispiel #7
0
 /// <summary>
 /// Connects to the Arbiter and Sets it up for Remote Control
 /// </summary>
 public void ConnectToArbiter()
 {
     RemoraOutput.WriteLine("Connecting to Arbiter");
     try
     {
         this.arbiterRemote = (ArbiterRemote)objectDirectory.Resolve("ArbiterRemote");
         RemoraOutput.WriteLine("Bind Successful...");
     }
     catch (Exception e)
     {
         RemoraOutput.WriteLine(e.ToString() + "\n\n" + "Error Binding Arbiter");
     }
 }
Beispiel #8
0
        /// <summary>
        /// Sets the rndf and mdf network data
        /// </summary>
        public void RetrieveNetworkData()
        {
            RemoraOutput.WriteLine("Retrieving Rndf, Mdf");

            try
            {
                this.remora.SetRndf(this.arbiterRemote.Rndf());
                this.remora.SetMdf(this.arbiterRemote.Mdf());
                RemoraOutput.WriteLine("Set Rndf, Mdf");
            }
            catch (Exception e)
            {
                RemoraOutput.WriteLine(e.ToString() + "\n\n" + "Error Retrieving Rndf, Mdf");
            }
        }
 /// <summary>
 /// Sync road and mission with ai
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SyncWithAi_Click(object sender, EventArgs e)
 {
     try
     {
         if (RemoraCommon.Communicator.ArbiterRemote != null)
         {
             this.SetRoadNetwork(RemoraCommon.Communicator.ArbiterRemote.GetRoadNetwork());
             this.SetMission(RemoraCommon.Communicator.ArbiterRemote.GetMissionDescription());
         }
     }
     catch (Exception ex)
     {
         RemoraOutput.WriteLine("Error in road network, mission sync: \n" + ex.ToString(), OutputType.Remora);
     }
 }
Beispiel #10
0
        public void ResgisterWithClient()
        {
            try
            {
                // get vehicle state channel
                vehicleStateChannel      = channelFactory.GetChannel("ArbiterSceneEstimatorPositionChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
                vehicleStateChannelToken = vehicleStateChannel.Subscribe(messagingListener);

                // get observed obstacle channel
                observedObstacleChannel      = channelFactory.GetChannel("ObservedObstacleChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
                observedObstacleChannelToken = observedObstacleChannel.Subscribe(messagingListener);

                // get observed vehicle channel
                observedVehicleChannel      = channelFactory.GetChannel("ObservedVehicleChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
                observedVehicleChannelToken = observedVehicleChannel.Subscribe(messagingListener);

                // get vehicle speed channel
                vehicleSpeedChannel      = channelFactory.GetChannel("VehicleSpeedChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
                vehicleSpeedChannelToken = vehicleSpeedChannel.Subscribe(messagingListener);

                // get output channel
                arbiterOutputChannel      = channelFactory.GetChannel("ArbiterOutputChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
                arbiterOutputChannelToken = arbiterOutputChannel.Subscribe(messagingListener);

                // get information channel
                arbiterInformationChannel      = channelFactory.GetChannel("ArbiterInformationChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
                arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(messagingListener);

                // get side obstacle channel
                sideObstacleChannel      = channelFactory.GetChannel("SideObstacleChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
                sideObstacleChannelToken = sideObstacleChannel.Subscribe(messagingListener);

                // get ai
                this.arbiterRemote = (ArbiterAdvancedRemote)objectDirectory.Resolve("ArbiterAdvancedRemote" + this.RemotingSuffix);

                // get the operational layer
                this.operationalFacade = (OperationalFacade)objectDirectory.Resolve("OperationalService" + this.RemotingSuffix);

                // register
                RemoraOutput.WriteLine("Resgistered To Client with suffix: " + this.RemotingSuffix, OutputType.Remora);
            }
            catch (Exception e)
            {
                RemoraOutput.WriteLine("Error registering with client: " + e.ToString(), OutputType.Remora);
            }
        }
Beispiel #11
0
 /// <summary>
 /// Stop the Arbiter dead and remove the Rndf, Mdf
 /// </summary>
 public void StopArbiter()
 {
     if (arbiterRemote != null)
     {
         try
         {
             this.arbiterRemote.Stop();
         }
         catch (Exception e)
         {
             RemoraOutput.WriteLine(e.ToString());
         }
     }
     else
     {
         RemoraOutput.WriteLine("Arbter Remote does not exist");
     }
 }
 private void pauseVehicleFromAi_Click(object sender, EventArgs e)
 {
     try
     {
         if (RemoraCommon.Communicator.ArbiterRemote != null)
         {
             RemoraCommon.Communicator.ArbiterRemote.PauseFromAi();
         }
         else
         {
             RemoraOutput.WriteLine("Arbiter Remote needs to be initialized", OutputType.Remora);
         }
     }
     catch (Exception ex)
     {
         RemoraOutput.WriteLine(ex.ToString(), OutputType.Remora);
     }
 }
 private void beginNewLogTool_Click(object sender, EventArgs e)
 {
     try
     {
         if (RemoraCommon.Communicator.ArbiterRemote != null)
         {
             RemoraCommon.Communicator.ArbiterRemote.BeginNewLog();
         }
         else
         {
             RemoraOutput.WriteLine("Arbiter Remote needs to be initialized", OutputType.Remora);
         }
     }
     catch (Exception ex)
     {
         RemoraOutput.WriteLine(ex.ToString(), OutputType.Remora);
     }
 }
 private void shutdownAiTool_Click(object sender, EventArgs e)
 {
     try
     {
         if (RemoraCommon.Communicator.ArbiterRemote != null)
         {
             RemoraCommon.Communicator.ArbiterRemote.SetAiMode(UrbanChallenge.Arbiter.Core.Common.ArbiterMode.Stop);
         }
         else
         {
             RemoraOutput.WriteLine("Arbiter Remote needs to be initialized", OutputType.Remora);
         }
     }
     catch (Exception ex)
     {
         RemoraOutput.WriteLine(ex.ToString(), OutputType.Remora);
     }
 }
Beispiel #15
0
 public void RestartArbiter(RndfNetwork rndfNetwork, Mdf mdf)
 {
     if (arbiterRemote != null)
     {
         try
         {
             this.arbiterRemote.Restart(rndfNetwork, mdf, UrbanChallenge.Arbiter.ArbiterCommon.ArbiterMode.Debug);
         }
         catch (Exception e)
         {
             RemoraOutput.WriteLine(e.ToString());
         }
     }
     else
     {
         RemoraOutput.WriteLine("Arbter Remote does not exist");
     }
 }
        /// <summary>
        /// Opens files
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            // create a new open file dialog
            this.openFileDialog1 = new OpenFileDialog();

            // settings for openFileDialog
            openFileDialog1.InitialDirectory = "Desktop\\";
            openFileDialog1.Filter           = "Arbiter Road Network (*.arn)|*.arn|Arbiter Mission Description (*.amd)|*.amd|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;

            // check if everything was selected alright
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    // switch over the final index
                    switch (openFileDialog1.FilterIndex)
                    {
                    // open a road network
                    case 1:

                        // open network from a file
                        this.SetRoadNetwork(this.OpenRoadNetworkFromFile(openFileDialog1.FileName));

                        // end case
                        break;

                    // open mission
                    case 2:

                        // open mission
                        this.SetMission(OpenMissionFromFile(openFileDialog1.FileName));

                        // end case
                        break;
                    }
                }
                catch (Exception ex)
                {
                    RemoraOutput.WriteLine("Error in [private void openToolStripButton_Click(object sender, EventArgs e)]: " + ex.ToString(), OutputType.Remora);
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// On loading, we want to load up the readme file located in the top-level remora directory
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Readme_Load(object sender, EventArgs e)
        {
            // path to readme
            string relativePath = "..\\..\\Readme.txt";

            try
            {
                using (StreamReader sr = new StreamReader(relativePath))
                {
                    this.readmeTextBox.Text = sr.ReadToEnd();
                    sr.Dispose();
                    sr.Close();
                }
            }
            catch (Exception ex)
            {
                RemoraOutput.WriteLine(ex.ToString());
            }
        }
 /// <summary>
 /// Track the ai vehicle
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void TrackAiVehicleButton_Click(object sender, EventArgs e)
 {
     if (this.roadDisplay1.aiVehicle.State != null)
     {
         if (this.TrackAiVehicleButton.CheckState == CheckState.Checked)
         {
             this.roadDisplay1.tracked = this.roadDisplay1.aiVehicle;
         }
         else
         {
             this.roadDisplay1.tracked = null;
         }
     }
     else
     {
         RemoraOutput.WriteLine("Cannot track vehicle, as we have no vehicle state update", OutputType.Remora);
         this.TrackAiVehicleButton.CheckState = CheckState.Unchecked;
     }
 }
Beispiel #19
0
        /// <summary>
        /// Registers with the correct services
        /// </summary>
        public void Register()
        {
            // "Activate" the NameService singleton.
            objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

            // Retreive the directory of messaging channels
            channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

            // Notify user of success
            RemoraOutput.WriteLine("Connection to Name Service Successful", OutputType.Remora);

            // get simulation if supposed to
            if (global::RemoraAdvanced.Properties.Settings.Default.SimMode)
            {
                this.simulatorFacade = (SimulatorFacade)objectDirectory.Resolve("SimulationServer");

                // Notify user of success
                RemoraOutput.WriteLine("Connection to Simulation Service Successful", OutputType.Remora);
            }
        }
Beispiel #20
0
        /// <summary>
        /// Prints speeds of the current mdf
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printMdfSpeeds_Click(object sender, EventArgs e)
        {
            if (RemoraCommon.Mission != null)
            {
                foreach (ArbiterSpeedLimit asl in RemoraCommon.Mission.SpeedLimits)
                {
                    RemoraOutput.WriteLine("SpeedLimit: " + asl.Area.ToString() + ", Max: " + asl.MaximumSpeed.ToString() + ", Min: " + asl.MinimumSpeed.ToString(), OutputType.Remora);
                }

                ArbiterCheckpoint[] acs = RemoraCommon.Mission.MissionCheckpoints.ToArray();
                for (int i = 0; i < acs.Length; i++)
                {
                    RemoraOutput.WriteLine(i.ToString() + ": Checkpoint Number: " + acs[i].CheckpointNumber.ToString() + ", Waypoint: " + acs[i].WaypointId.ToString(), OutputType.Remora);
                }
            }
            else
            {
                RemoraOutput.WriteLine("Mission cannot be null to print speeds", OutputType.Remora);
            }
        }
Beispiel #21
0
        public Mdf RetrieveMdf()
        {
            if (arbiterRemote != null)
            {
                try
                {
                    return(this.arbiterRemote.Mdf());
                }
                catch (Exception e)
                {
                    RemoraOutput.WriteLine(e.ToString());
                }
            }
            else
            {
                RemoraOutput.WriteLine("Arbter Remote does not exist");
            }

            return(null);
        }
Beispiel #22
0
 public bool PingArbiter()
 {
     if (arbiterRemote != null)
     {
         try
         {
             return(this.arbiterRemote.Ping());
         }
         catch (Exception e)
         {
             RemoraOutput.WriteLine(e.ToString());
             return(false);
         }
     }
     else
     {
         RemoraOutput.WriteLine("Arbter Remote does not exist");
         return(false);
     }
 }
Beispiel #23
0
        public bool UpdateMdf(Mdf mdf)
        {
            if (arbiterRemote != null)
            {
                try
                {
                    return(this.arbiterRemote.SetMdf(mdf));
                }
                catch (Exception e)
                {
                    RemoraOutput.WriteLine(e.ToString());
                }
            }
            else
            {
                RemoraOutput.WriteLine("Arbter Remote does not exist");
            }

            return(false);
        }
Beispiel #24
0
        /// <summary>
        /// Forces the ai to reconnect to the shits
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ForceReconnectTool_Click(object sender, EventArgs e)
        {
            if (RemoraCommon.Communicator.ArbiterRemote != null)
            {
                RemoraOutput.WriteLine("Forcing ai to reconnect to the shits", OutputType.Remora);

                try
                {
                    RemoraCommon.Communicator.ArbiterRemote.Reconnect();
                }
                catch (Exception ex)
                {
                    RemoraOutput.WriteLine("Error reconnecting: \n" + ex.ToString(), OutputType.Remora);
                    RemoraCommon.Communicator.CommunicationsReady = false;
                }
            }
            else
            {
                RemoraOutput.WriteLine("Remora not connected to ai", OutputType.Remora);
            }
        }
        private void pointAnalysisTool_Click(object sender, EventArgs e)
        {
            if (this.pointAnalysisTool.CheckState == CheckState.Checked)
            {
                if (RemoraCommon.RoadNetwork != null)
                {
                    this.roadDisplay1.SecondaryEditorTool = new PointAnalysisTool(RemoraCommon.RoadNetwork.PlanarProjection, false, RemoraCommon.RoadNetwork, this.roadDisplay1.WorldTransform);
                }
                else
                {
                    RemoraOutput.WriteLine("Road network cannot be null for point analysis tool", OutputType.Remora);
                }
            }
            else
            {
                if (this.roadDisplay1.SecondaryEditorTool != null && this.roadDisplay1.SecondaryEditorTool is PointAnalysisTool)
                {
                    this.roadDisplay1.SecondaryEditorTool = null;
                }
            }

            this.roadDisplay1.Invalidate();
        }
        private void rulerTool_Click(object sender, EventArgs e)
        {
            if (this.rulerTool.CheckState == CheckState.Checked)
            {
                if (RemoraCommon.RoadNetwork != null)
                {
                    this.roadDisplay1.CurrentEditorTool = new RulerTool(false, RemoraCommon.RoadNetwork, this.roadDisplay1.WorldTransform);
                }
                else
                {
                    RemoraOutput.WriteLine("Road network cannot be null for ruler tool", OutputType.Remora);
                }
            }
            else
            {
                if (this.roadDisplay1.CurrentEditorTool != null && this.roadDisplay1.CurrentEditorTool is RulerTool)
                {
                    this.roadDisplay1.CurrentEditorTool = null;
                }
            }

            this.roadDisplay1.Invalidate();
        }
        /// <summary>
        /// Connect to a client
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConnectClientButton_Click(object sender, EventArgs e)
        {
            try
            {
                System.Windows.Forms.ListView.SelectedListViewItemCollection slvic = this.ClientListView.SelectedItems;

                if (slvic != null && slvic.Count == 1)
                {
                    ListViewItem lvi = slvic[0];

                    System.Windows.Forms.ListViewItem.ListViewSubItemCollection lvsic = lvi.SubItems;

                    this.clientHandler.SetMachine(lvsic[1].Text);

                    RemoraCommon.Communicator.Shutdown();
                    RemoraCommon.Communicator.ResgisterWithClient();
                }
            }
            catch (Exception ex)
            {
                RemoraOutput.WriteLine("Connection to Client Failed: \n " + ex.ToString(), OutputType.Remora);
            }
        }
        /// <summary>
        /// Sets mission
        /// </summary>
        /// <param name="mission"></param>
        private void SetMission(ArbiterMissionDescription mission)
        {
            // set mission
            RemoraCommon.Mission = mission;

            // set speeds if can
            if (RemoraCommon.RoadNetwork != null)
            {
                try
                {
                    RemoraCommon.RoadNetwork.SetSpeedLimits(mission.SpeedLimits);
                }
                catch (Exception e)
                {
                    RemoraOutput.WriteLine("Error setting road network speed limits from inputted mission: " + e.ToString(), OutputType.Remora);
                }

                RemoraOutput.WriteLine("Successfully loaded mission, passed speed limit set check", OutputType.Remora);

                int numAreas  = RemoraCommon.RoadNetwork.ArbiterSegments.Count + RemoraCommon.RoadNetwork.ArbiterZones.Count;
                int numSpeeds = RemoraCommon.Mission.SpeedLimits.Count;

                if (numAreas != numSpeeds)
                {
                    RemoraOutput.WriteLine("Warning: Number of Speed Limits: " + numSpeeds.ToString() + " not equal to number of network Areas: " + numAreas.ToString(), OutputType.Remora);
                }
                else
                {
                    RemoraOutput.WriteLine("Number of Speed Limits: " + numSpeeds.ToString() + " equal to number of network Areas: " + numAreas.ToString(), OutputType.Remora);
                }
            }
            else
            {
                RemoraOutput.WriteLine("Cannot load Mission before Road Network", OutputType.Remora);
            }
        }
Beispiel #29
0
        /// <summary>
        /// Initializes communications with the outside world by means of remoting
        /// </summary>
        public void InitializeRemotingCommunications()
        {
            // try to shut down in case we have already been active
            this.ShutDown();

            try
            {
                // Read the configuration file.
                RemotingConfiguration.Configure("Remora.exe.config", false);
                WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

                // "Activate" the NameService singleton.
                objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

                // Retreive the directory of messaging channels
                IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

                // Retreive the Messaging Service channels we want to listen to
                vehicleStateChannel       = channelFactory.GetChannel("PositionChannel", ChannelMode.UdpMulticast);
                observedObstacleChannel   = channelFactory.GetChannel("ObservedObstacleChannel", ChannelMode.UdpMulticast);
                observedVehicleChannel    = channelFactory.GetChannel("ObservedVehicleChannel", ChannelMode.UdpMulticast);
                arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel", ChannelMode.UdpMulticast);
                carModeChannel            = channelFactory.GetChannel("CarMode", ChannelMode.UdpMulticast);
                fakeVehicleChannel        = channelFactory.GetChannel("FakeVehicleChannel", ChannelMode.UdpMulticast);

                // Create a channel listeners and listen on wanted channels
                channelListener          = new MessagingListener();
                vehicleStateChannelToken = vehicleStateChannel.Subscribe(channelListener);
                observedObstacleChannel.Subscribe(channelListener);
                observedVehicleChannel.Subscribe(channelListener);
                arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(channelListener);
                carModeChannelToken            = carModeChannel.Subscribe(channelListener);
                fakeVehicleChannelToken        = fakeVehicleChannel.Subscribe(channelListener);

                // set that remoting has been successfully initialize
                this.RemotingInitialized = true;
                RemoraOutput.WriteLine("Successfully initialized communications");
            }
            catch (Exception e)
            {
                RemoraOutput.WriteLine(e.ToString() + "\n\n" + "Could not initialize communications, attempting to reconnect");

                try
                {
                    WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

                    // "Activate" the NameService singleton.
                    objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

                    // Retreive the directory of messaging channels
                    IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

                    // Retreive the Messaging Service channels we want to listen to
                    vehicleStateChannel       = channelFactory.GetChannel("PositionChannel", ChannelMode.UdpMulticast);
                    observedObstacleChannel   = channelFactory.GetChannel("ObservedObstacleChannel", ChannelMode.UdpMulticast);
                    observedVehicleChannel    = channelFactory.GetChannel("ObservedVehicleChannel", ChannelMode.UdpMulticast);
                    arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel", ChannelMode.UdpMulticast);
                    carModeChannel            = channelFactory.GetChannel("CarMode", ChannelMode.UdpMulticast);
                    fakeVehicleChannel        = channelFactory.GetChannel("FakeVehicleChannel", ChannelMode.UdpMulticast);

                    // Create a channel listeners and listen on wanted channels
                    channelListener          = new MessagingListener();
                    vehicleStateChannelToken = vehicleStateChannel.Subscribe(channelListener);
                    observedObstacleChannel.Subscribe(channelListener);
                    observedVehicleChannel.Subscribe(channelListener);
                    arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(channelListener);
                    carModeChannelToken            = carModeChannel.Subscribe(channelListener);
                    fakeVehicleChannelToken        = fakeVehicleChannel.Subscribe(channelListener);

                    // set that remoting has been successfully initialize
                    this.RemotingInitialized = true;
                    RemoraOutput.WriteLine("Successfully initialized communications");
                }
                catch (Exception e1)
                {
                    RemoraOutput.WriteLine(e1.ToString() + "\n\n" + "Could not reinitialize nameservice communications");

                    try
                    {
                        // Retreive the directory of messaging channels
                        IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

                        // Retreive the Messaging Service channels we want to listen to
                        vehicleStateChannel       = channelFactory.GetChannel("PositionChannel", ChannelMode.UdpMulticast);
                        observedObstacleChannel   = channelFactory.GetChannel("ObservedObstacleChannel", ChannelMode.UdpMulticast);
                        observedVehicleChannel    = channelFactory.GetChannel("ObservedVehicleChannel", ChannelMode.UdpMulticast);
                        arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel", ChannelMode.UdpMulticast);
                        carModeChannel            = channelFactory.GetChannel("CarMode", ChannelMode.UdpMulticast);
                        fakeVehicleChannel        = channelFactory.GetChannel("FakeVehicleChannel", ChannelMode.UdpMulticast);

                        // Create a channel listeners and listen on wanted channels
                        channelListener          = new MessagingListener();
                        vehicleStateChannelToken = vehicleStateChannel.Subscribe(channelListener);
                        observedObstacleChannel.Subscribe(channelListener);
                        observedVehicleChannel.Subscribe(channelListener);
                        arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(channelListener);
                        carModeChannelToken            = carModeChannel.Subscribe(channelListener);
                        fakeVehicleChannelToken        = fakeVehicleChannel.Subscribe(channelListener);

                        // set that remoting has been successfully initialize
                        this.RemotingInitialized = true;
                        RemoraOutput.WriteLine("Successfully initialized communications");
                    }
                    catch (Exception e2)
                    {
                        RemoraOutput.WriteLine(e2.ToString() + "\n\n" + "Could not reinitialize messaging communications");
                    }
                }
            }
        }
Beispiel #30
0
        public string PartitionIdString()
        {
            string final = "";

            #region Standard Areas

            List <AreaProbability> AreaProbabilities = new List <AreaProbability>();

            Circle  circ = new Circle(TahoeParams.T + 0.3, new Coordinates());
            Polygon conv = circ.ToPolygon(32);

            Circle  circ1 = new Circle(TahoeParams.T + 0.6, new Coordinates());
            Polygon conv1 = circ1.ToPolygon(32);

            Circle  circ2 = new Circle(TahoeParams.T + 1.4, new Coordinates());
            Polygon conv2 = circ2.ToPolygon(32);

            for (int i = 0; i < this.trackedCluster.closestPartitions.Length; i++)
            {
                SceneEstimatorClusterPartition secp = this.trackedCluster.closestPartitions[i];

                if (RemoraCommon.RoadNetwork.VehicleAreaMap.ContainsKey(secp.partitionID))
                {
                    IVehicleArea iva = RemoraCommon.RoadNetwork.VehicleAreaMap[secp.partitionID];

                    bool found = false;
                    for (int j = 0; j < AreaProbabilities.Count; j++)
                    {
                        AreaProbability ap = AreaProbabilities[j];

                        if (ap.Key.Equals(iva))
                        {
                            ap.Value = ap.Value + secp.probability;
                            found    = true;
                        }
                    }

                    if (!found)
                    {
                        AreaProbabilities.Add(new AreaProbability(iva, secp.probability));
                    }
                }
                else
                {
                    RemoraOutput.WriteLine("Remora caught exception, partition: " + secp.partitionID + " not found in Vehicle Area Map", OutputType.Remora);
                }
            }

            if (AreaProbabilities.Count > 0)
            {
                double rP = 0.0;
                foreach (AreaProbability ap in AreaProbabilities)
                {
                    if (ap.Key is ArbiterLane)
                    {
                        rP += ap.Value;
                    }
                }

                if (rP > 0.1)
                {
                    foreach (AreaProbability ap in AreaProbabilities)
                    {
                        if (ap.Key is ArbiterLane)
                        {
                            // proabbility says in area
                            double vP = ap.Value / rP;
                            if (vP > 0.3)
                            {
                                #region Check if obstacle enough in area

                                bool ok = false;
                                if (ap.Key is ArbiterLane)
                                {
                                    VehicleState vs = RemoraCommon.Communicator.GetVehicleState();

                                    ArbiterLane al      = (ArbiterLane)ap.Key;
                                    Coordinates closest = this.ClosestPointToLine(al.LanePath(), vs).Value;

                                    // dist to closest
                                    double distanceToClosest = vs.Front.DistanceTo(closest);

                                    // get our dist to closest
                                    if (30.0 < distanceToClosest && distanceToClosest < (30.0 + ((5.0 / 2.24) * Math.Abs(RemoraCommon.Communicator.GetVehicleSpeed().Value))))
                                    {
                                        if (al.LanePolygon != null)
                                        {
                                            ok = this.VehicleExistsInsidePolygon(al.LanePolygon, vs);
                                        }
                                        else
                                        {
                                            ok = al.LanePath().GetClosestPoint(closest).Location.DistanceTo(closest) < al.Width / 2.0;
                                        }
                                    }
                                    else if (distanceToClosest <= 30.0)
                                    {
                                        if (al.LanePolygon != null)
                                        {
                                            if (!this.trackedCluster.isStopped && this.VehicleAllInsidePolygon(al.LanePolygon, vs))
                                            {
                                                ok = true;
                                            }
                                            else
                                            {
                                                if (this.trackedCluster.isStopped)
                                                {
                                                    bool isInSafety = false;
                                                    foreach (ArbiterIntersection ai in RemoraCommon.RoadNetwork.ArbiterIntersections.Values)
                                                    {
                                                        if (ai.IntersectionPolygon.IsInside(this.trackedCluster.closestPoint))
                                                        {
                                                            isInSafety = true;
                                                        }
                                                    }
                                                    foreach (ArbiterSafetyZone asz in al.SafetyZones)
                                                    {
                                                        if (asz.IsInSafety(this.trackedCluster.closestPoint))
                                                        {
                                                            isInSafety = true;
                                                        }
                                                    }

                                                    if (isInSafety)
                                                    {
                                                        if (!this.VehiclePassableInPolygon(al, al.LanePolygon, vs, conv1))
                                                        {
                                                            ok = true;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (!this.VehiclePassableInPolygon(al, al.LanePolygon, vs, conv))
                                                        {
                                                            ok = true;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (!this.VehiclePassableInPolygon(al, al.LanePolygon, vs, conv2))
                                                    {
                                                        ok = true;
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            ok = al.LanePath().GetClosestPoint(closest).Location.DistanceTo(closest) < al.Width / 2.0;
                                        }
                                    }
                                    else
                                    {
                                        ok = true;
                                    }

                                    if (ok)
                                    {
                                        final = final + ap.Key.ToString() + ": " + vP.ToString("F4") + "\n";
                                    }
                                }

                                #endregion
                            }
                        }
                    }
                }
            }

            #endregion

            #region Interconnect Area Mappings

            foreach (ArbiterInterconnect ai in RemoraCommon.RoadNetwork.ArbiterInterconnects.Values)
            {
                if (ai.TurnPolygon.IsInside(this.trackedCluster.closestPoint))
                {
                    final = final + ai.ToString() + "\n";

                    if (ai.TurnDirection == ArbiterTurnDirection.UTurn && ai.InitialGeneric is ArbiterWaypoint && ai.FinalGeneric is ArbiterWaypoint)
                    {
                        // initial
                        ArbiterLane initialLane = ((ArbiterWaypoint)ai.InitialGeneric).Lane;
                        ArbiterLane targetLane  = ((ArbiterWaypoint)ai.FinalGeneric).Lane;
                        final = final + "UTurn2Lane: " + initialLane.ToString() + " & " + targetLane.ToString() + "\n";
                    }
                }
            }

            #endregion

            #region Intersections

            foreach (ArbiterIntersection aInt in RemoraCommon.RoadNetwork.ArbiterIntersections.Values)
            {
                if (aInt.IntersectionPolygon.IsInside(this.trackedCluster.closestPoint))
                {
                    final = final + "Inter: " + aInt.ToString() + "\n";
                }
            }

            #endregion

            return(final);
        }