Esempio n. 1
0
    /// <summary>
    /// Call ROS.Init if it hasn't been called, and informs callers whether to try to make a nodehandle and pubs/subs
    /// </summary>
    /// <returns>Whether ros.net initialization can continue</returns>
    public void StartROS(MonoBehaviour caller, Action whensuccessful)
    {
        XmlRpcUtil.SetLogLevel(XmlRpcUtil.XMLRPC_LOG_LEVEL.ERROR);
        if (whensuccessful != null)
        {
            Action whatToDo = () =>
            {
#if UNITY_EDITOR
                if (EditorApplication.isPlaying && !EditorApplication.isPaused)
                {
#endif
                _startROS();
                if (whensuccessful != null)
                {
                    whensuccessful();
                }
#if UNITY_EDITOR
            }
#endif
            };
            if (caller != null)
            {
                MasterChooserController MasterChooser = caller.transform.root.GetComponentInChildren <MasterChooserController>(true);
                if (MasterChooser == null || !MasterChooser.checkNeeded())
                {
                    whatToDo();
                }
                else if (!MasterChooser.ShowIfNeeded(whatToDo))
                {
                    Debug.LogError("Failed to test for applicability, show, or handle masterchooser input");
                }
            }
            else
            {
                whatToDo();
            }
        }
        else
        {
#if UNITY_EDITOR
            if (EditorApplication.isPlaying && !EditorApplication.isPaused)
            {
#endif
            _startROS();
#if UNITY_EDITOR
        }
#endif
        }
#if LOG_TO_FILE
        lock (loggerlock)
        {
            if (logwriter == null)
            {
                string validlogpath = null;
                string filename     = "unity_test_" + DateTime.Now.Ticks + ".log";
                foreach (string basepath in new[] { Application.dataPath, "/sdcard/ROS.NET_Logs/" })
                {
                    if (Directory.Exists(basepath))
                    {
                        try
                        {
                            if (Directory.GetFiles(basepath) == null)
                            {
                                continue;
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.LogWarning(e);
                        }
                    }
                    try
                    {
                        logwriter           = new StreamWriter(Path.Combine(basepath, filename));
                        logwriter.AutoFlush = true;
                        logwriter.WriteLine("Opened log file for writing at " + DateTime.Now);
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning(e);
                    }
                    break;
                }
            }
        }
#endif
        Application.logMessageReceived += Application_logMessageReceived;
    }
Esempio n. 2
0
 public XmlRpcManager()
 {
     XmlRpcUtil.ShowOutputFromXmlRpcPInvoke(XmlRpcUtil.XMLRPC_LOG_LEVEL.NOTHING);
     server = new XmlRpcServer();
     getPid = (parms, result) => responseInt(1, "", Process.GetCurrentProcess().Id)(result);
 }
Esempio n. 3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            controllerUpdater = new DispatcherTimer()
            {
                Interval = new TimeSpan(0, 0, 0, 0, 10)
            };
            controllerUpdater.Tick += Link;
            controllerUpdater.Start();

            new Thread(() =>
            {
                XmlRpcUtil.ShowOutputFromXmlRpcPInvoke();

                // ROS stuff
                ROS.Init(new string[0], "The_UI_" + System.Environment.MachineName.Replace("-", "__"));
                nh = new NodeHandle();
                Dispatcher.Invoke(new Action(() =>
                {
                    battvolt.startListening(nh);
                    EStop.startListening(nh);
                    MotorGraph.startListening(nh);
                    rosout_control.startListening(nh);
                    spinningstuff.startListening(nh, "/imu/data");
                }));
                velPub       = nh.advertise <gm.Twist>("/cmd_vel", 1);
                multiplexPub = nh.advertise <m.Byte>("/cam_select", 1);
                armPub       = nh.advertise <am.ArmMovement>("/arm/movement", 1);
                ArmON        = nh.advertise <m.Bool>("arm/on", 1);
                mast_pub     = nh.advertise <m.Bool>("raise_camera_mast", 1);

                tilt_pub = new Publisher <m.Int32> [4];

                for (int i = 0; i < 4; i++)
                {
                    tilt_pub[i] = nh.advertise <m.Int32>("camera" + i + "/tilt", 1);
                }

                Dispatcher.Invoke(new Action(() =>
                {
                    mainCameras = new TabItem[] { MainCamera1, MainCamera2, MainCamera3, MainCamera4 };
                    subCameras  = new TabItem[] { SubCamera1, SubCamera2, SubCamera3, SubCamera4 };
                    mainImages  = new ROS_ImageWPF.CompressedImageControl[] { camImage0, camImage1, camImage2, camImage3 };
                    subImages   = new ROS_ImageWPF.SlaveImage[] { camImageSlave0, camImageSlave1, camImageSlave2, camImageSlave3 };
                    for (int i = 0; i < mainCameras.Length; i++)
                    {
                        mainImages[i].AddSlave(subImages[i]);
                    }
                    subCameras[1].Focus();
                    adr(false);

                    // instantiating some global helpers

                    /*detectors = new DetectionHelper[4];
                     * for (int i = 0; i < 4; ++i)
                     * {
                     *  detectors[i] = new DetectionHelper(nh, i, this);
                     * }*/
                }));

#if !INSTANT_DETECTION_DEATH
                while (ROS.ok)
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            detectors[i].churnAndBurn();
                        }
                    }));
                    Thread.Sleep(100);
                }
#endif
            }).Start();
        }