Example #1
0
 /// <summary>
 /// Change icon in view according to new ros message.
 /// </summary>
 /// <param name="rosMessage"></param>
 public override void ProcessRosMessage(RosJsonMessage rosMessage)
 {
     if (!rosMessage.currentIcon.Equals(""))
     {
         currentIconName = rosMessage.currentIcon;
         //print("Current Icon name: " + currentIconName);
         if (icons.TryGetValue(currentIconName, out currentIcon))
         {
             //print("Got value " + currentIcon);
             if (view != null)
             {
                 //print(view);
                 ((IconView)view).SetIcon(currentIcon);
                 if (!rosMessage.currentIconAlpha.Equals(""))
                 {
                     ((IconView)view).SetIconAlpha(rosMessage.currentIconAlpha);
                 }
                 //print("Finito");
             }
         }
         else
         {
             print("Icon " + currentIconName + " is not among the icons for this widget");
         }
     }
 }
Example #2
0
        /// <summary>
        /// Initializes toastr widget subclass with default values from widget template.
        /// </summary>
        /// <param name="context">Widget context</param>
        /// <param name="viewDesignPrefab">Prefab for toastr views</param>
        public new void Init(RosJsonMessage context, GameObject viewDesignPrefab)
        {
            duration = context.toastrDuration;
            color    = WidgetUtility.BytesToColor(context.toastrColor);
            fontSize = context.toastrFontSize;

            base.Init(context, viewDesignPrefab);
        }
Example #3
0
        /// <summary>
        /// Publish a RosJsonMessage on ros for mocking
        /// </summary>
        /// <param name="demoMessage"></param>
        public void PublishMessage(RosJsonMessage demoMessage)
        {
            string jsonString = JsonUtility.ToJson(demoMessage);

            RosSharp.RosBridgeClient.MessageTypes.Std.String tmpMessage = new RosSharp.RosBridgeClient.MessageTypes.Std.String(jsonString);
            PublishMessage(tmpMessage);

            WriteMessageToFile("demoMessage", jsonString);
        }
Example #4
0
        /// <summary>
        /// Stores the initial data.
        /// </summary>
        /// <param name="context">the message which contains the initial data</param>
        /// <param name="viewDesignPrefab">the prefab that should be instantiated to show the widget</param>
        public new void Init(RosJsonMessage context, GameObject viewDesignPrefab)
        {
            color               = WidgetUtility.BytesToColor(context.graphColor);
            numXLabels          = context.xDivisionUnits;
            numYLabels          = context.yDivisionUnits;
            showCompleteHistory = context.showCompleteHistory;

            base.Init(context, viewDesignPrefab);
        }
Example #5
0
        /// <summary>
        /// Initializes text widget subclass with default values from widget template.
        /// </summary>
        /// <param name="context">Widget context</param>
        /// <param name="viewDesignPrefab">Prefab for icon views</param>
        public new void Init(RosJsonMessage context, GameObject viewDesignPrefab)
        {
            color    = WidgetUtility.BytesToColor(context.textColor);
            fontSize = context.textFontSize;

            TextWidgetTemplate incomingMessageTemplate = new TextWidgetTemplate(context.textMessage, WidgetUtility.BytesToColor(context.textColor), context.textFontSize);

            currentlyDisplayedMessage = incomingMessageTemplate;

            base.Init(context, viewDesignPrefab);
        }
Example #6
0
        /// <summary>
        /// Initialization of widget.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="viewDesignPrefab"></param>
        public void Init(RosJsonMessage context, GameObject viewDesignPrefab)
        {
            this.context          = context;
            id                    = context.id;
            childWidgetId         = context.childWidgetId;
            position              = WidgetUtility.StringToWidgetPosition(context.widgetPosition);
            relativeChildPosition = WidgetUtility.StringToRelativeChildPosition(context.relativeChildPosition);
            trainingInfo          = context.trainingInfo;

            this.viewDesignPrefab = viewDesignPrefab;
        }
Example #7
0
        /// <summary>
        /// Parse a single widget template and create the RosJsonMessage object.
        /// </summary>
        /// <param name="asset"></param>
        /// <returns></returns>
        private static RosJsonMessage ParseWidgetTemplate(TextAsset asset)
        {
            RosJsonMessage parsedContext = JsonUtility.FromJson <RosJsonMessage>(asset.text);

            if (parsedContext == null)
            {
                Debug.LogWarning("Json " + asset.text + " is faulty");
                return(null);
            }

            return(parsedContext);
        }
Example #8
0
        /// <summary>
        /// Initializes icon widget subclass with default values from widget template.
        /// </summary>
        /// <param name="context">Widget context</param>
        /// <param name="viewDesignPrefab">Prefab for icon views</param>
        /// <param name="icons">Icons registered for this widget as dictionary with file names as keys</param>
        public void Init(RosJsonMessage context, GameObject viewDesignPrefab, Dictionary <string, Texture2D> icons)
        {
            this.icons = icons;
            iconsArray = new Texture2D[icons.Count];
            icons.Values.CopyTo(iconsArray, 0);

            childWidgetId = context.childWidgetId;

            ProcessRosMessage(context);

            base.Init(context, viewDesignPrefab);
        }
Example #9
0
        /// <summary>
        /// Checks, if widget id of given context is already taken
        /// </summary>
        /// <param name="newWidgetContext">Widget context of new widget to register</param>
        /// <param name="existingWidgets">List of existing widgets</param>
        /// <returns></returns>
        private bool IsWidgetIdUnique(RosJsonMessage newWidgetContext, List <Widget> existingWidgets)
        {
            foreach (Widget existingWidget in existingWidgets)
            {
                if (existingWidget.GetID() == newWidgetContext.id)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #10
0
        /// <summary>
        /// Sends mock messages to toggle the senseglove icon.
        /// </summary>
        private void PublishIconDemoMessage()
        {
            RosJsonMessage demoMessage;

            if (toggle)
            {
                demoMessage = RosJsonMessage.CreateIconMessage(20, "SenseGlove_0");
            }
            else
            {
                demoMessage = RosJsonMessage.CreateIconMessage(20, "SenseGlove_1");
            }
            PublishMessage(demoMessage);

            toggle = !toggle;
        }
Example #11
0
        /// <summary>
        /// Forwared a given ros message to the widget with the corresponding id.
        /// </summary>
        /// <param name="rosMessage">Incoming ros message to be forwarded</param>
        private void ForwardMessageToWidget(RosJsonMessage rosMessage)
        {
            if (rosMessage == null)
            {
                Debug.LogWarning("RosMessage was null");
                return;
            }

            Widget widget = FindWidgetWithID(rosMessage.id);

            if (widget == null)
            {
                Debug.LogWarning("Message could not be forwarded.");
                return;
            }

            widget.ProcessRosMessage(rosMessage);
        }
Example #12
0
        /// <summary>
        /// Publish a graph demo message with a random temperature
        /// </summary>
        private void PublishGraphDemoMessage()
        {
            System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
            double          cur_time   = (System.DateTime.UtcNow - epochStart).TotalSeconds;

            byte[] col = new byte[] { 255, 255, 255, 255 };
            if (temperature > 30)
            {
                col = new byte[] { 255, 20, 5, 255 };
            }
            else if (temperature < 20)
            {
                col = new byte[] { 5, 10, 255, 255 };
            }
            RosJsonMessage demoMessage = RosJsonMessage.CreateGraphMessage(1, temperature, cur_time, col);

            PublishMessage(demoMessage);
        }
Example #13
0
        /// <summary>
        /// Parses all widget template json files in resources folder and deserializes them into RosJsonMessages as contexts for initialization by the factory.
        /// </summary>
        /// <returns></returns>
        public static List <RosJsonMessage> ParseAllWidgetTemplates()
        {
            List <RosJsonMessage> widgetContexts = new List <RosJsonMessage>();

            TextAsset[] widgetTemplates = Resources.LoadAll <TextAsset>("JsonTemplates");
            foreach (TextAsset widgetTemplate in widgetTemplates)
            {
                RosJsonMessage parsedWidgetContext = ParseWidgetTemplate(widgetTemplate);

                if (parsedWidgetContext == null)
                {
                    continue;
                }

                widgetContexts.Add(ParseWidgetTemplate(widgetTemplate));
            }

            return(widgetContexts);
        }
Example #14
0
        /// <summary>
        /// Create a new widget object from a given context.
        /// </summary>
        /// <param name="widgetContext">Context of new widget to create</param>
        /// <param name="existingWidgets">List of already existing widgets, to check for duplicate ids</param>
        /// <returns></returns>
        public Widget CreateWidgetFromContext(RosJsonMessage widgetContext, List <Widget> existingWidgets)
        {
            if (IsWidgetIdUnique(widgetContext, existingWidgets) == false)
            {
                Debug.LogWarning("duplicate ID: " + widgetContext.id + " in widget templates");
                return(null);
            }

            GameObject widgetGameObject = new GameObject();

            widgetGameObject.name = widgetContext.title;
            widgetGameObject.transform.SetParent(widgetParentGameObject.transform, false);

            switch (widgetContext.type)
            {
            case "Graph":
                GraphWidget graphWidget = widgetGameObject.AddComponent <GraphWidget>();
                graphWidget.Init(widgetContext, graphDesignPrefab);
                return(graphWidget);

            case "Toastr":
                ToastrWidget toastrWidget = widgetGameObject.AddComponent <ToastrWidget>();
                toastrWidget.Init(widgetContext, toastrDesignPrefab);
                return(toastrWidget);

            case "Icon":
                IconWidget iconWidget = widgetGameObject.AddComponent <IconWidget>();
                Dictionary <string, Texture2D> iconsForThisWidget = FindIconsWithName(widgetContext.icons);
                iconWidget.Init(widgetContext, iconDesignPrefab, iconsForThisWidget);
                return(iconWidget);

            case "Text":
                TextWidget textWidget = widgetGameObject.AddComponent <TextWidget>();
                textWidget.Init(widgetContext, textDesignPrefab);
                return(textWidget);

            default:
                Debug.LogWarning("Type not defined: " + widgetContext.type);
                Destroy(widgetGameObject);
                return(null);
            }
        }
Example #15
0
        /// <summary>
        /// Gets called when a new RosMessage arrives for the widget. Adds a new datapoint and/or updates
        /// the widget properties
        /// </summary>
        /// <param name="rosMessage">the message which contains the live data point</param>
        public override void ProcessRosMessage(RosJsonMessage rosMessage)
        {
            if (rosMessage.graphColor != null && rosMessage.graphColor.Length == 4)
            {
                color = WidgetUtility.BytesToColor(rosMessage.graphColor);
            }
            DateTime dt = DateTime.Now;

            if (rosMessage.graphTimestamp != 0)
            {
                DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
                dt = epochStart.AddSeconds(rosMessage.graphTimestamp);
            }
            if (rosMessage.graphValue != 0)
            {
                AddDatapoint(new Datapoint(dt, rosMessage.graphValue));
            }

            showCompleteHistory = rosMessage.showCompleteHistory;
        }
Example #16
0
 /// <summary>
 /// Process incoming new ros message.
 /// </summary>
 /// <param name="rosMessage"></param>
 public override void ProcessRosMessage(RosJsonMessage rosMessage)
 {
     EnqueueNewMessage(rosMessage.toastrMessage, rosMessage.toastrDuration, WidgetUtility.BytesToColor(rosMessage.toastrColor), rosMessage.toastrFontSize);
 }
Example #17
0
 /// <summary>
 /// Process incoming ros message
 /// </summary>
 /// <param name="rosMessage"></param>
 public abstract void ProcessRosMessage(RosJsonMessage rosMessage);
Example #18
0
        /// <summary>
        /// Sends mock messages for a toastr.
        /// </summary>
        private void PublishToastrDemoMessage()
        {
            RosJsonMessage demoMessage = RosJsonMessage.CreateToastrMessage(10, "Hello Roboy", 2, null);

            PublishMessage(demoMessage);
        }
Example #19
0
        /// <summary>
        /// Process new incoming ros message.
        /// </summary>
        /// <param name="rosMessage"></param>
        public override void ProcessRosMessage(RosJsonMessage rosMessage)
        {
            TextWidgetTemplate incomingMessageTemplate = new TextWidgetTemplate(rosMessage.textMessage, WidgetUtility.BytesToColor(rosMessage.textColor), rosMessage.textFontSize);

            changeDisplayedMessage(incomingMessageTemplate);
        }
Example #20
0
 /// <summary>
 /// Enqueues the interface message queue.
 /// </summary>
 /// <param name="msg">The interface Message.</param>
 public void EnqueueInterfaceMessage(RosJsonMessage msg)
 {
     interfaceMessageQueue.Enqueue(msg);
 }