Inheritance: MonoBehaviour
Ejemplo n.º 1
0
        // CalculateConvergence: Calculates the rule's convergence fitness
        internal void CollectDisplacement(Vector3[] sendList)
        {
            int tries = 0;

            while (tries < 3)
            {
                int count = 0;

                UDPSend.SendData(UDPSend.EncodeMessage(sendList));
                UDPReceive.MessageReceived = false;

                while (UDPReceive.MessageReceived == false && count < 3)
                {
                    Thread.Sleep(70);
                    count++;
                }

                if (UDPReceive.MessageReceived == true)
                {
                    displacement = UDPReceive.maxDisplacement;
                    break;
                }

                tries++;
                if (tries == 3)
                {
                    Debug.Log("Action Lost");
                }
            }
        }
Ejemplo n.º 2
0
 private void Awake()
 {
     UDPScript     = network.GetComponent <UDPEditMode>();
     udpSend       = network.GetComponent <UDPSend>();
     udpReceive    = network.GetComponent <UDPReceive>();
     baxterCmdList = new List <BaxterCommands>();
 }
 // Start is called before the first frame update
 void OnEnable()
 {
     this.requestData         = Encoding.ASCII.GetBytes(this.broadcastMessage);
     this.udpBroadcaster      = new UDPSend(string.Empty, this.remotePort);
     this.broadcastingRoutine = BroadcastingRoutine();
     StartCoroutine(this.broadcastingRoutine);
 }
Ejemplo n.º 4
0
    // StringMsg rosMsg = new StringMsg("");

    // Use this for initialization
    void Start()
    {
        sendObj      = new UDPSend();
        sendObj.IP   = IP;
        sendObj.port = 2368;
        sendObj.init();
        ranges = new byte[1206];
        for (int i = 0; i < ranges.Length; i++)
        {
            ranges[i] = 0;
        }
        myref          = transform;
        ScannerLoc     = myref.position;
        prevScannerLoc = ScannerLoc;
        if (!SensorRotator)
        {
            SensorRotator = myref.Find("Laser Sensor").transform;
        }
        if (!emitter)
        {
            SensorRotator = myref.Find("Emitter").transform;
        }

        NoOfScansPerFrame = (int)((HorScanAngRange / HorRes) * hz * Time.fixedDeltaTime);
        currentangle      = 0;
    }
Ejemplo n.º 5
0
    // StringMsg rosMsg = new StringMsg("");

    // Use this for initialization
    void Start()
    {
        myref          = transform;
        ScannerLoc     = myref.position;
        prevScannerLoc = ScannerLoc;
        if (!SensorRotator)
        {
            SensorRotator = myref.Find("Laser Sensor").transform;
        }
        if (!emitter)
        {
            SensorRotator = myref.Find("Emitter").transform;
        }

        attachedRB = GetComponentInParent <Rigidbody>();
        if (UDP && !ROS)
        {
            // sendObj =gameObject.AddComponent< UDPSend>();
            sendObj = new UDPSend();
            sendObj.init();
        }
        PointsTemp = new List <Vector3>();
        Points     = new List <Vector3>();
        // writer = new StreamWriter(Application.dataPath+"/Data.csv");
        NoOfScansPerFrame = (int)((HorScanAngRange / HorRes) * hz * Time.fixedDeltaTime);
        currentangle      = -HorScanAngRange / 2;
        if (ROS)
        {
            wsc = FindObjectOfType <WebsocketClient>();
            wsc.Advertise("velodyne", "std_msgs/String");
            // SimulationManager.instance.ros.AddPublisher(typeof(VelodyneStringPublisher));
        }
        // writer.WriteLine("This is a data file");
        // datacolumn=new float[lasercount];
    }
 public Connection(string _remoteIP)
 {
     this.remoteIP    = _remoteIP;
     this.status      = false;
     this.udpSender   = new UDPSend(_remoteIP);
     this.udpReceiver = new UDPReceive();
     this.tcpSender   = new TCPSend(_remoteIP);
 }
	void Start(){

		DontDestroyOnLoad(this.gameObject);

		connectedPlayers = new List<string>();
		Application.runInBackground = true;
		udpReceive = GetComponent<UDPReceive>();
		udpSend = GetComponent<UDPSend>();
	}
Ejemplo n.º 8
0
    // call it from shell (as program)
    private static void Main()
    {
        UDPSend sendObj = new UDPSend();

        sendObj.init();

        // testing via console
        // sendObj.inputFromConsole();
    }
Ejemplo n.º 9
0
    // call it from shell (as program)
    private static void Main()
    {
        UDPSend sendObj = new UDPSend();

        sendObj.init();

        // as server sending endless
        sendObj.sendEndless(" endless infos \n");
    }
Ejemplo n.º 10
0
	private static void Main()
	{
		UDPSend sendObj=new UDPSend();
		sendObj.init();


		sendObj.sendEndless(" endless infos \n");

	}
Ejemplo n.º 11
0
    // call it from shell (as program)
    private static void Main()
    {
        UDPSend sendObj = new UDPSend();

        sendObj.init();
        // testing via console
        // sendObj.inputFromConsole();
        // as server sending endless
        sendObj.sendEndless(" endless infos \n");
    }
 // Start is called before the first frame update
 void OnEnable()
 {
     this.requestData    = Encoding.ASCII.GetBytes(this.broadcastMessage);
     this.udpBroadcaster = new UDPSend(string.Empty, this.remotePort);
     // this.broadcastingRoutine = BroadcastingRoutine();
     // StartCoroutine(this.broadcastingRoutine);
     this.broadcastingThread = new ThreadInterface(Broadcast,
                                                   Convert.ToInt32(this.expireTime) * 1000);
     this.broadcastingThread.Start();
 }
    // Use this for initialization
    void Start()
    {
        // initialize PID parameters
        integralPositionError    = new Vector3(0, 0, 0);
        previousPositionError    = new Vector3(0, 0, 0);
        integralOrientationError = 0.0f;
        previousOrientationError = 0.0f;

        // get raspberry pi socket
        udpclient = gameObject.GetComponent <UDPSend>();
    }
Ejemplo n.º 14
0
    // call it from shell (as program)
    private static void Main()
    {
        UDPSend sendObj = new UDPSend();
        sendObj.init();

        // testing via console
        // sendObj.inputFromConsole();

        // as server sending endless
        sendObj.sendEndless(" endless infos \n");
    }
Ejemplo n.º 15
0
 // log and send ship motion info to comm
 private void sendData()
 {
     UDPSend.newPacket();
     UDPSend.addFloat(Time.time);
     UDPSend.addFloat(scale * Movement.instance.getLinVel().magnitude);
     UDPSend.addVector(scale * Movement.instance.getAngVel());
     UDPSend.addVector(scale * Movement.instance.getLinAcc());
     UDPSend.addVector(scale * Movement.instance.getAngAcc());
     UDPSend.addVector(transform.rotation.eulerAngles);
     UDPSend.sendPacket();
 }
Ejemplo n.º 16
0
	void Start(){
		System.Random random = new System.Random();
		id = random.Next(1000000).ToString();
		Application.runInBackground = true;
		udpReceive = GetComponent<UDPReceive>();
		udpSend = GetComponent<UDPSend>();
		
		sendLimit = 0.5f;
		sendCounter = 0;

	}
Ejemplo n.º 17
0
    // Use this for initialization
    void Start()
    {
        udpSender     = GetComponent <UDPDoubleArrSend> ();
        triggerSender = GetComponent <UDPSend> ();
        stream        = GetComponent <txtStreamReader> ();

        while (Directory.Exists("E:/HrTestData/" + participantID))
        {
            participantID += 1;
        }
        Directory.CreateDirectory("E:/HrTestData/" + participantID);
        directoryPath = "E:/HrTestData/" + participantID + "/";
    }
Ejemplo n.º 18
0
    private void Awake()
    {
        audioHum   = AddAudio(clipHum, true, false, 0.5f);
        audioClash = AddAudio(clipClash, false, false, 0.5f);
        //gameManager = GameManager.Instance;'

        if (baxter == null)
        {
            baxter = GameObject.FindGameObjectWithTag("Network");
        }
        UDPScript = baxter.GetComponent <UDPSend>();


        lensFlare = Instantiate(lensFlarePrefab, gameObject.transform);
        lensFlare.SetActive(false);
    }
Ejemplo n.º 19
0
    // Use this for initialization
    void Start()
    {
        shield      = new Shield();
        blur        = new BlurEffect();
        rb          = GetComponent <Rigidbody>();
        speedometer = new Speedometer();

        udpSendRef = sendRef.GetComponent <UDPSend> ();

        aDoubleTap = new DoubleTap(KeyCode.A, 0.2f, DashLeft);
        bDoubleTap = new DoubleTap(KeyCode.D, 0.2f, DashRight);

        wheelSmoke          = GameObject.FindGameObjectsWithTag("WheelSmoke");
        portalDesertSpawner = gameObject.GetComponent <PortalDesertSpawner>();
        Invoke("ReadyToDie", 5.0f);
    }
 // Use this for initialization
 void Start()
 {
     // let's first get access to the other components of this object
     udpSender     = GetComponent <UDPDoubleArrSend> ();
     triggerSender = GetComponent <UDPSend> ();
     stream        = GetComponent <Main> ();
     // This is for the purpose of separating the different subjects you have recorded
     // each time the program is restarted it creates a new folder for the new participant,
     // in this way you know exactly which participant you are working with and the number that has been through.
     while (Directory.Exists("E:/HrTestData/" + participantID))
     {
         participantID += 1;
     }
     Directory.CreateDirectory("E:/HrTestData/" + participantID);
     directoryPath = "E:/HrTestData/" + participantID + "/";
 }
Ejemplo n.º 21
0
    void foo()
    {
        Vector3      winnerVector = new Vector3();
        List <float> disps        = new List <float>();

        for (int i = 0; i < 30; i++)
        {
            int tries = 0;

            var       randomAgent = listAgents[UnityEngine.Random.Range(0, listAgents.Length - 1)];
            var       v           = randomAgent.Cell.GetFaceNeighbours().Where(x => x.Alive == false).ToArray()[0].Center;
            Vector3[] N           = new Vector3[] { v };

            while (tries < 3)
            {
                int count = 0;

                UDPSend.SendData(UDPSend.EncodeMessage(listAgents.Select(a => a.Cell.Center).Union(N).ToArray()));
                UDPReceive.MessageReceived = false;

                while (UDPReceive.MessageReceived == false && count < 3)
                {
                    Thread.Sleep(40);
                    count++;
                }

                if (UDPReceive.MessageReceived == true)
                {
                    print("Count: " + count + ", Tries: " + tries);
                    print("_" + UDPReceive.maxDisplacement.ToString("F10"));

                    disps.Add(UDPReceive.maxDisplacement);
                    if (disps.Min() >= UDPReceive.maxDisplacement)
                    {
                        winnerVector = v;
                    }

                    break;
                }

                tries++;
            }
        }

        print("Winner: " + winnerVector + "," + disps.Min().ToString("F10"));
        Instantiate(agentPrefab, winnerVector, Quaternion.identity);
    }
Ejemplo n.º 22
0
        public Client()
        {
            ClientReceiveManager = new ClientReceiveManager();
            Send = new ClientSend();

            Action <Packet> receivePacketAction = (packet) =>
            {
                ClientReceiveManager.ExecuteOnMainThread(() =>
                {
                    ClientReceiveManager.ProcessPacket(packet.PacketTypeId, this, packet);
                });
            };

            tcp        = new TCP(this, receivePacketAction);
            udpSend    = new UDPSend(this, receivePacketAction);
            udpReceive = new UDPReceive(receivePacketAction);
        }
Ejemplo n.º 23
0
    public void Awake()
    {
        instance = this;
        DontDestroyOnLoad(gameObject);

        //如果不填写Ip则广播
        IPAddress ip;

        if (IPAddress.TryParse(ipSend, out ip))
        {
            remoteEndPoint = new IPEndPoint(ip, sendPort);
        }
        else
        {
            remoteEndPoint = new IPEndPoint(IPAddress.Broadcast, sendPort);
        }
        client = new UdpClient();
    }
Ejemplo n.º 24
0
        public Client(int _clientId)
        {
            Id = _clientId;

            Action <Packet> receivePacketAction = (packet) =>
            {
                Server.ReceiveManager.ExecuteOnMainThread(() =>
                {
                    Server.ReceiveManager.ProcessPacket(packet.PacketTypeId, packet);
                });
            };

            tcp = new TCP(this, receivePacketAction);

            if (Constants.AllowUDP)
            {
                udp = new UDPSend(this, receivePacketAction);
            }

            player = new Player(Id, "NewPlayer", new Vector3(0, 0, 0), this);
        }
Ejemplo n.º 25
0
        public override void RunInterface(string pluginName)
        {
            this.Log.Debug("Running interface");
            pName = pluginName;
            OSAEObjectTypeManager.ObjectTypeUpdate("ONKYO RECEIVER", "ONKYO RECEIVER", "Onkyo Receiver", pluginName, "ONKYO RECEIVER", 0, 0, 0, 1);

            _UDPListen = new UDPListen();
            _UDPSend = new UDPSend();
            _UDPListen.OnkyoDevice += new DelegateOnkyoReply(OnkyoMessageHandler);

            _UDPListen.Listen();
            _UDPSend.Send();

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("ONKYO RECEIVER");

            foreach (OSAEObject obj in objects)
            {
                Receiver r = new Receiver(obj.Name);
                foreach (OSAEObjectProperty prop in obj.Properties)
                {
                    switch (prop.Name)
                    {
                        case "Communication Type":
                            r.Type = prop.Value;
                            break;
                        case "IP":
                            r.IP = prop.Value;
                            break;
                        case "Network Port":
                            try
                            {
                                r.NetworkPort = Int32.Parse(prop.Value);
                            }
                            catch
                            {
                                r.NetworkPort = 0;
                            }
                            break;
                        case "COM Port":
                            try
                            {
                                r.ComPort = Int32.Parse(prop.Value);
                            }
                            catch
                            {
                                r.ComPort = 0;
                            }
                            break;
                    }
                }

                receivers.Add(r);
                this.Log.Debug("Added receiver to list: " + r.Name);

                try
                {
                    if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                    {
                        this.Log.Debug("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort);
                        r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                        //get a network stream from server
                        r.clientSockStream = r.tcpClient.GetStream();

                        // create new writer and reader stream to send and receive
                        r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                        r.clientStreamReader = new StreamReader(r.clientSockStream);

                        //Start listening
                        r.Connect();
                    }
                    else if (r.Type == "Serial" && r.ComPort != 0)
                    {
                        //not implemented
                    }
                    else
                    {
                        this.Log.Info(r.Name + " - Properties not set");
                    }
                }
                catch (Exception ex)
                {
                    this.Log.Error("Error creating connection to receiver", ex);
                }
            }
            this.Log.Info("Run Interface Complete");
        }
    //  PID
    void Update()
    {
        if (!goal)
        {
            return;
        }
        //  compute errors
        Vector3 positionError   = goal.transform.position - transform.position;
        Vector3 derivativeError = (positionError - previousPositionError) / elapseTime;

        float angle = goal.transform.rotation.eulerAngles.y - transform.rotation.eulerAngles.y;

        //  keep angle between -180 and 180 degree
        if (angle > 180)
        {
            angle -= 360.0f;
        }
        else if (angle < -180)
        {
            angle += 360.0f;
        }
        float orientationError           = Mathf.Deg2Rad * angle;
        float derivativeOrientationError = (orientationError - previousOrientationError) / elapseTime;


        //  compute PID
        Vector3 commandPosition = new Vector3();

        commandPosition.x = Kp_pitchroll * positionError.x + Ki_pitchroll * integralPositionError.x + Kd_pitchroll * derivativeError.x;
        commandPosition.y = Kp_vertical * positionError.y + Ki_vertical * integralPositionError.y + Kd_vertical * derivativeError.y;
        commandPosition.z = Kp_pitchroll * positionError.z + Ki_pitchroll * integralPositionError.z + Kd_pitchroll * derivativeError.z;

        float commandOrientation = Kp_yaw * orientationError + Ki_yaw * integralOrientationError + Kd_yaw * derivativeOrientationError;


        // update PID parameters
        previousPositionError  = positionError;
        integralPositionError += elapseTime * positionError;

        previousOrientationError  = orientationError;
        integralOrientationError += elapseTime * orientationError;


        // clamp commands and integral error to prevent drone dammages
        commandPosition.x  = Mathf.Clamp(commandPosition.x, -CommandClamp_pitchroll, CommandClamp_pitchroll);
        commandPosition.y  = Mathf.Clamp(commandPosition.y, -CommandClamp_vertical, CommandClamp_vertical);
        commandPosition.z  = Mathf.Clamp(commandPosition.z, -CommandClamp_pitchroll, CommandClamp_pitchroll);
        commandOrientation = Mathf.Clamp(commandOrientation, -CommandClamp_yaw, CommandClamp_yaw);

        integralPositionError.x  = Mathf.Clamp(integralPositionError.x, -IntegralClamp_pitchroll, IntegralClamp_pitchroll);
        integralPositionError.y  = Mathf.Clamp(integralPositionError.y, -IntegralClamp_vertical, IntegralClamp_vertical);
        integralPositionError.z  = Mathf.Clamp(integralPositionError.z, -IntegralClamp_pitchroll, IntegralClamp_pitchroll);
        integralOrientationError = Mathf.Clamp(integralOrientationError, -IntegralClamp_yaw, IntegralClamp_yaw);


        //  compute local command : from global Optitrack to local drone body
        Matrix4x4  localToWorld         = Matrix4x4.Translate(transform.position) * Matrix4x4.Rotate(transform.rotation);
        Vector4    localPositionCommand = localToWorld.inverse * new Vector4(commandPosition.x, commandPosition.y, commandPosition.z, 0.0f);
        Vector3Int msgComm = new Vector3Int(Mathf.RoundToInt(localPositionCommand.x), Mathf.RoundToInt(localPositionCommand.y), Mathf.RoundToInt(localPositionCommand.z));


        //  Send command to raspberry pi : to make sure the order of execution doesnt matter (unity <-> raspberry pi)
        if (udpclient)
        {
            udpclient.SendMessage(msgComm.x.ToString() + " " + msgComm.y.ToString() + " " + msgComm.z.ToString() + " " + Mathf.RoundToInt(commandOrientation).ToString());
        }
        else
        {
            udpclient = gameObject.GetComponent <UDPSend>();
            if (udpclient)
            {
                Debug.Log("CONNECTED ");
            }
        }

        //Debug.Log(localPositionCommand.x.ToString() + " " + localPositionCommand.y.ToString() + " " + localPositionCommand.z.ToString() + " " + Mathf.RoundToInt(commandOrientation).ToString());
        //Debug.Log(msgComm.x.ToString() + " " + msgComm.y.ToString() + " " + msgComm.z.ToString() + " " + Mathf.RoundToInt(commandOrientation).ToString());
    }
Ejemplo n.º 27
0
 // Use this for initialization
 void Start()
 {
     udpSend    = new UDPSend(remoteIP, sendPort);
     udpReceive = new UDPReceive(localIP, remoteIP, receivePort);
 }
Ejemplo n.º 28
0
 public void sendIp(){
     UDPSend sendObj = new UDPSend();
     sendObj.init();
     sendObj.sendString("MyIP" + " " + Network.player.ipAddress);
     GameObject.Destroy(sendObj);
 }
Ejemplo n.º 29
0
        public void TestUDPSendReceive_ConnectAndSend()
        {
            var log = new Logger();

            var ip           = "127.0.0.1";
            var receiverPort = 8880;
            var sender1Port  = 8881;
            var sender2Port  = 8882;

            var sender1Key = UDPReceive.GetRemoteEndpointKey(ip, sender1Port);
            var sender2Key = UDPReceive.GetRemoteEndpointKey(ip, sender2Port);

            var hello1 = "Hello from " + sender1Port;
            var hello2 = "Hello from " + sender2Port;
            var bye1   = "Bye from " + sender1Port;
            var bye2   = "Bye from " + sender2Port;

            #region Setup

            var receiverUdpClient = new UdpClient(receiverPort);
            var receiver          = new UDPReceive(receiverUdpClient, log);
            receiver.Init();

            var sender1UdpClient = new UdpClient(sender1Port);
            var sender1          = new UDPSend(sender1UdpClient, log);
            sender1.remoteIP   = ip;
            sender1.remotePort = receiverPort;
            sender1.Init();

            var sender2UdpClient = new UdpClient(sender2Port);
            var sender2          = new UDPSend(sender2UdpClient, log);
            sender2.remoteIP   = ip;
            sender2.remotePort = receiverPort;
            sender2.Init();

            #endregion

            // Check startup state.
            Assert.AreEqual(0, receiver.allReceivedUDPPackets.Count);
            Assert.AreEqual("", receiver.lastReceivedUDPPacket);

            // Send 'Hello' message from sender 1
            sender1.SendString(hello1);

            Thread.Sleep(100);

            Assert.AreEqual(1, receiver.allReceivedUDPPackets.Count);

            Assert.AreEqual(hello1, receiver.allReceivedUDPPackets[sender1Key]);

            Assert.AreEqual(hello1, receiver.lastReceivedUDPPacket);

            // Send 'Hello' message from sender 2
            sender2.SendString(hello2);

            Thread.Sleep(100);

            Assert.AreEqual(2, receiver.allReceivedUDPPackets.Count);

            Assert.AreEqual(hello2, receiver.allReceivedUDPPackets[sender2Key]);

            Assert.AreEqual(hello2, receiver.lastReceivedUDPPacket);

            // Send 'Bye' message from sender 1
            sender1.SendString(bye1);

            Thread.Sleep(100);

            Assert.AreEqual(hello1 + bye1, receiver.allReceivedUDPPackets[sender1Key]);

            Assert.AreEqual(bye1, receiver.lastReceivedUDPPacket);

            // Send 'Bye' message from sender 2
            sender2.SendString(bye2);

            Thread.Sleep(500);

            Assert.AreEqual(hello2 + bye2, receiver.allReceivedUDPPackets[sender2Key]);

            Assert.AreEqual(bye2, receiver.lastReceivedUDPPacket);

            #region Teardown

            receiver.Shutdown();

            receiverUdpClient.Close();
            sender1UdpClient.Close();
            sender2UdpClient.Close();

            #endregion
        }
Ejemplo n.º 30
0
    private static void Main()
    {
        UDPSend sendObj = new UDPSend();

        sendObj.init();
    }
Ejemplo n.º 31
0
 // start from unity3d
 public void Start()
 {
     udpSendRef = sendRef.GetComponent <UDPSend> ();
     init();
 }
Ejemplo n.º 32
0
	void AutoConnect()
	{
		send = GameObject.Find("Smart Floor").GetComponent<UDPSend>();
		//send.init();
		StartCoroutine(SendMessageStart());
	}
 private void Awake()
 {
     trackedObj = GetComponent <SteamVR_TrackedObject>();
     UDPScript  = network.GetComponent <UDPSend>();
 }