Ejemplo n.º 1
0
 void FilterSignalEvent(DingSignal signal)
 {
     if (filter.Match(signal))
     {
         HandleSignalEvent(signal);
     }
 }
Ejemplo n.º 2
0
 private void HandleSignalEvent(DingSignal signal)
 {
     signals.Add(signal);
     if (signals.Count > 1000)
     {
         signals.RemoveAt(0);
     }
     Repaint();
 }
Ejemplo n.º 3
0
        protected override void HandleSignalEvent(DingSignal signal)
        {
            float value;

            if (filter.TryExtractValue <float>(signal, out value))
            {
                this.signal = signal;
                this.value  = value;
            }
        }
Ejemplo n.º 4
0
 public bool Match(DingSignal signal)
 {
     // if (messageType == AiGlobals.FloatConditionType.analogin) {
     //  this.messageFilter = "/num/analogin/" + port + "/";
     // } else if (messageType == AiGlobals.FloatConditionType.touch) {
     //  this.messageFilter = "/num/touch/" + port + "/";
     // }
     //Debug.Log(messageFilter);
     return(signal.device == device && signal.source == source && signal.oscMessage.Filter(this.messageFilter.Split(':') [0]));
 }
Ejemplo n.º 5
0
        protected override void HandleSignalEvent(DingSignal signal)
        {
            string value;

            if (filter.TryExtractValue <string>(signal, out value))
            {
                this.signal = signal;
                this.value  = value;
            }
            //Debug.Log("HandleSignalEvent " + signal + " " + this.value);
        }
Ejemplo n.º 6
0
 public void sttResults(string transcription)
 {
     print("Virt - Speech To Text: " + transcription);
     //stt.StopRecording();
     sttRecording = false;
     DelftToolkit.DingSignal signal = new DelftToolkit.DingSignal(thisDevice, AiGlobals.SensorSource.virt, "/str/speech2text/", transcription);
     if (DelftToolkit.DingSignal.onSignalEvent != null)
     {
         DelftToolkit.DingSignal.onSignalEvent(signal);
     }
 }
Ejemplo n.º 7
0
        public bool TryExtractValue <T>(DingSignal signal, out T value)
        {
            object obj = null;

            if (messageFilter.StartsWith("/num/"))
            {
                return(signal.TryGetValue <T>(out value));
            }
            else if (messageFilter.StartsWith("/vec/"))
            {
                Vector3 v;
                if (signal.TryGetValue <Vector3>(out v))
                {
                    if (messageFilter.EndsWith(":x"))
                    {
                        obj = v.x;
                    }
                    else if (messageFilter.EndsWith(":y"))
                    {
                        obj = v.y;
                    }
                    else if (messageFilter.EndsWith(":z"))
                    {
                        obj = v.z;
                    }
                    else if (messageFilter.EndsWith(":mag"))
                    {
                        obj = v.magnitude;
                    }
                    else
                    {
                        return(signal.TryGetValue <T>(out value));
                    }
                    if (obj is T)
                    {
                        value = (T)obj;
                        return(true);
                    }
                }
            }
            else if (messageFilter.StartsWith("/str/"))
            {
                return(signal.TryGetValue <T>(out value));
            }
            value = default(T);
            return(false);
        }
Ejemplo n.º 8
0
        public bool Match(DingSignal signal)
        {
            // AiGlobals.Devices device = signal.device;
            // AiGlobals.SensorSource source = signal.source;
            // string oscMessage = signal.oscMessage;
            // object value = signal.value;
            // if (signal.oscMessage == AiGlobals.StrConditionType.recognize) {
            //  this.messageFilter = "/str/recognize/";
            // } else if (messageType == AiGlobals.StrConditionType.keydown) {
            //  this.messageFilter = "/str/keydown/";
            // } else if (messageType == AiGlobals.StrConditionType.speech2text) {
            //  this.messageFilter = "/str/speech2text/";
            // }
            //Debug.Log(messageType);
            //Debug.Log(this.messageFilter);
            //return signal.device == device && signal.source == source && signal.oscMessage.Filter(this.messageFilter.Split(':') [0]);

            return(signal.device == device && signal.source == source && signal.oscMessage.Filter(messageFilter.Split(':') [0]));
        }
Ejemplo n.º 9
0
        public override void Update()
        {
            // keep track of speech to text
            if (sttRecording == true && Time.time - sttStartTime >= sttDuration)
            {
                stt.StopRecording();
                sttRecording = false;
                //print("stopped STT");
                Debug.LogWarning("DING-VIRTUAL stopped STT after: " + sttDuration + " seconds");
            }

            // send virtual sensor data
            if (sendSensors)
            {
                // very crude implementation
                if (DelftToolkit.DingSignal.onSignalEvent != null)
                {
                    RaycastHit hit;
                    Ray        forwardRay = new Ray(transform.position, -Vector3.up);

                    //Cast a ray straight forwards.
                    float   distance = 1000;                   // when nothing is in front of it
                    Vector3 fwd      = transform.TransformDirection(Vector3.forward);
                    if (Physics.Raycast(transform.position, fwd, out hit))
                    {
                        //print("Found an object - distance: " + hit.distance);
                        // make it similar to what comes out of the phycical sensor
                        //distance = 1023 - (hit.distance * 100); // IR sensor
                        distance = hit.distance * 10;                         // sonar sensor goes lower as it object gets closer
                    }
                    string url = "/num/analogin/" + analoginPort + "/";
                    DelftToolkit.DingSignal signal = new DelftToolkit.DingSignal(thisDevice, AiGlobals.SensorSource.virt, url, distance);
                    if (DelftToolkit.DingSignal.onSignalEvent != null)
                    {
                        DelftToolkit.DingSignal.onSignalEvent(signal);
                    }
                }
            }

            // handle recognize request
            if (recognize)
            {
                if (DelftToolkit.DingSignal.onSignalEvent != null)
                {
                    String     tag  = "Untagged";
                    Transform  tilt = FindChildByRecursion(transform, "tilt");
                    RaycastHit hit;

                    //Cast a ray straight forwards from servo tilt/pan head
                    Vector3 fwd = tilt.TransformDirection(Vector3.forward);
                    if (Physics.Raycast(tilt.position, fwd, out hit))
                    {
                        if (hit.distance < recogDistance)
                        {
                            tag = hit.collider.tag;
                        }
                        else
                        {
                            tag = "far:" + hit.collider.tag;
                        }
                    }
                    //Debug.LogWarning("recognize: " + tag);
                    Debug.DrawRay(tilt.position, fwd * 10, Color.green, 4, false);
                    // if (tag != "Untagged") {
                    DelftToolkit.DingSignal signal = new DelftToolkit.DingSignal(thisDevice, AiGlobals.SensorSource.virt, "/str/recognize/", tag);
                    DelftToolkit.DingSignal.onSignalEvent(signal);
                    // }
                }
            }

            // watch keyboard
            foreach (KeyCode currentKey in allKeyCodes)
            {
                if (Input.GetKeyDown(currentKey))
                {
                    if (DelftToolkit.DingSignal.onSignalEvent != null)
                    {
                        //print(currentKey);
                        DelftToolkit.DingSignal signal = new DelftToolkit.DingSignal(thisDevice, AiGlobals.SensorSource.virt, "/str/keydown/", currentKey.ToString());
                        DelftToolkit.DingSignal.onSignalEvent(signal);
                    }
                }
            }

            // handle led blinking
            if (ledBlinkNum > 0 && Time.time > ledBlinkNextTime)
            {
                if (ledBlinkState)                   // turn it off
                {
                    body.GetComponent <Renderer>().material.color = new Color(0.0f, 0.0f, 0.0f);
                }
                else                     // turn it on
                {
                    body.GetComponent <Renderer>().material.color = ledBlinkColor;
                }
                ledBlinkState    = !ledBlinkState;
                ledBlinkNextTime = Time.time + ledBlinkInterval;
                ledBlinkNum--;
            }

            // handle servo position
            moveYaw();
            movePitch();

            // change this to use separate vars for move and movetype if move active
            float moveAmount = moveSpeed * speedAdj * Time.deltaTime;

            switch (moveType)
            {
            case AiGlobals.ActionMoveTypes.stop:
                break;

            case AiGlobals.ActionMoveTypes.forward:
                transform.position += transform.forward * moveAmount;
                break;

            case AiGlobals.ActionMoveTypes.backward:
                transform.position -= transform.forward * moveAmount;
                break;

            case AiGlobals.ActionMoveTypes.turnRight:
                transform.Rotate(Vector3.up, 1 * 100f * moveAmount);
                break;

            case AiGlobals.ActionMoveTypes.turnLeft:
                transform.Rotate(Vector3.up, -1 * 100f * moveAmount);
                break;

            default:
                break;
            }

            // OSC
            if (OSCInit)
            {
                OSCHandler.Instance.UpdateLogs();

                servers = OSCHandler.Instance.Servers;

                foreach (KeyValuePair <string, ServerLog> item in servers)
                {
                    //print(item.Value.packets.Count);
                    // get the most recent NEW OSC message received
                    if (serverClientID == item.Key && item.Value.packets.Count > 0 && item.Value.packets[item.Value.packets.Count - 1].TimeStamp != lastOscMessageIn)
                    {
                        // count back until we find the matching timestamp
                        int lastMsgIndex = item.Value.packets.Count - 1;
                        while (lastMsgIndex > 0 && item.Value.packets[lastMsgIndex].TimeStamp != lastOscMessageIn)
                        {
                            lastMsgIndex--;
                        }

                        // set how many messages are queued up
                        int msgsQd = 1;
                        if (item.Value.packets.Count > 1)                           // not the first item
                        {
                            msgsQd = item.Value.packets.Count - lastMsgIndex - 1;
                        }
                        lastOscMessageIn = item.Value.packets[item.Value.packets.Count - 1].TimeStamp;

                        // check the queued messages
                        for (int msgIndex = item.Value.packets.Count - msgsQd; msgIndex < item.Value.packets.Count; msgIndex++)
                        {
                            //
                            string address = item.Value.packets[msgIndex].Address;
                            if (address.StartsWith("/"))
                            {
                                float value0 = item.Value.packets[msgIndex].Data.Count > 0 ? float.Parse(item.Value.packets[msgIndex].Data[0].ToString()) : 0.0f;
                                float value1 = item.Value.packets[msgIndex].Data.Count > 1 ? float.Parse(item.Value.packets[msgIndex].Data[1].ToString()) : 0.0f;
                                float value2 = item.Value.packets[msgIndex].Data.Count > 2 ? float.Parse(item.Value.packets[msgIndex].Data[2].ToString()) : 0.0f;
                                address = "/num" + address + "/";
                                print(OSC_SERVER_CLIENT + ": " + address + " " + value0 + " " + value1 + " " + value2);
                                if (DelftToolkit.DingSignal.onSignalEvent != null)
                                {
                                    DelftToolkit.DingSignal signal = new DelftToolkit.DingSignal(thisDevice, AiGlobals.SensorSource.virt, address, value0);
                                    DelftToolkit.DingSignal.onSignalEvent(signal);
                                    //DelftToolkit.DingSignal.onSignalEvent(new DelftToolkit.DingSignal(thisDevice, AiGlobals.SensorSource.virt, address, new Vector3(value0, value1, value2)));
                                }
                            }
                            //print(OSC_SERVER_CLIENT + ": " + address + " " + float.Parse(item.Value.packets[msgIndex].Data[0].ToString()));
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        // public DingSignalFilter filter = new DingSignalFilter(AiGlobals.Devices.ding1, AiGlobals.SensorSource.virt, AiGlobals.FloatConditionType.analogin, 0);
        // [Tooltip("Read signals matching message signature. (only exact match supported)")]
        // /// <summary> The last signal we received which passed the filter </summary>
        // [NonSerialized] public DingSignal signal;

        // protected override void Init() {
        //  base.Init();
        //  DingSignal.onSignalEvent -= FilterSignalEvent;
        //  DingSignal.onSignalEvent += FilterSignalEvent;
        // }

        // void FilterSignalEvent(DingSignal signal) {
        //  if (filter.Match(signal)) {
        //      HandleSignalEvent(signal);
        //  }
        // }

        protected abstract void HandleSignalEvent(DingSignal signal);
Ejemplo n.º 11
0
 public static void HandleSignalEvent(DingSignal signal)
 {
     NodeEditorWindow.current.Repaint();
 }