예제 #1
0
    //unsubscribe form topics
#if UNITY_EDITOR
    void OnApplicationQuit()
    {
        if (ros != null)
        {
            ros.Publish(HoloLensActivityPublisher.GetMessageTopic(), new BoolMsg(false));
            ros.Disconnect();
        }
    }
예제 #2
0
    //may be used for unsubscribing in hololens.. gotta try how it will work
#if !UNITY_EDITOR
    void OnApplicationFocus(bool focus)
    {
        if (!focus)
        {
            if (ros != null)
            {
                //send message of hololens inactivity
                ros.Publish(HoloLensActivityPublisher.GetMessageTopic(), new BoolMsg(false));
                //not needed .. system automatically disconnects from rosbridge
                //ros.Disconnect();
            }
        }
    }
예제 #3
0
    void Update()
    {
        if (connectToROS)
        {
            ros.SetIPConfig(serverIP, port);
            ros.AddSubscriber(typeof(DetectedObjectsSubscriber));
            ros.AddSubscriber(typeof(InterfaceStateSubscriber));
            ros.AddSubscriber(typeof(HololensStateSubscriber));
            ros.AddSubscriber(typeof(CollisionEnvSubscriber));
            ros.AddSubscriber(typeof(LearningRequestActionResultSubscriber));
            ros.AddPublisher(typeof(HoloLensClickPublisher));
            ros.AddPublisher(typeof(HoloLensActivityPublisher));
            ros.AddPublisher(typeof(HoloLensLearningPublisher));
            ros.AddPublisher(typeof(InterfaceStatePublisher));
            ros.AddPublisher(typeof(CollisionEnvPublisher));
            ros.AddPublisher(typeof(TFPublisher));
            ros.AddPublisher(typeof(LearningRequestActionGoalPublisher));

            ros.AddPublisher(typeof(TF2WebRepublisherGoalPublisher));
            ros.AddPublisher(typeof(TF2WebRepublisherCancelPublisher));
            ros.AddSubscriber(typeof(TF2WebRepublisherFeedbackSubscriber));

            ros.AddSubscriber(typeof(GuiNotificationsSubscriber));

            ros.AddSubscriber(typeof(RobotLeftArmGraspedObjectSubscriber));
            ros.AddSubscriber(typeof(RobotRightArmGraspedObjectSubscriber));

            ros.AddServiceResponse(typeof(ROSCommunicationManager));
            ros.Connect();

            connectToROS = false;
        }

        if (ros._connected)
        {
            connectedToROS = true;

            //activate callbacks
            ros.Render();

            //every 5 secs publish activity msg
            if (awake_counter <= 0f)
            {
                ros.Publish(HoloLensActivityPublisher.GetMessageTopic(), new BoolMsg(true), debug_log: false);
                ros.Publish(HoloLensLearningPublisher.GetMessageTopic(), new BoolMsg(InteractiveProgrammingManager.Instance.holoLearningEnabled), debug_log: false);

                awake_counter = 5f;
            }
            awake_counter -= Time.deltaTime;

            //if(UnbiasedTime.Instance.TimeSynchronized) {
            //    try {
            //        Debug.Log(ROSTimeHelper.GetCurrentTime().ToYAMLString());
            //    }
            //    catch (Exception e) {

            //    }
            //}
        }

        if (!ros._connected)
        {
            connectedToROS = false;
        }
    }