Пример #1
0
    private void ReceiveAsyncMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        // Handler method for the streaming data. This code copies the data values
        SpheroDeviceSensorsAsyncData message =
            (SpheroDeviceSensorsAsyncData)eventArgs.Message;
        SpheroDeviceSensorsData sensorsData = message.Frames[0];

        // There can be some discontinuation with vision data coming in, and what we requested,
        // so check if the data actually exists
        SpheroAttitudeData attitudeData = sensorsData.AttitudeData;

        if (attitudeData != null)
        {
            SpheroYaw = sensorsData.AttitudeData.Yaw;
        }

        SpheroQuaternionData quaternionData = sensorsData.QuaternionData;

        if (quaternionData != null)
        {
            SpheroQuaternion = new Quaternion(sensorsData.QuaternionData.Q1,
                                              sensorsData.QuaternionData.Q2,
                                              sensorsData.QuaternionData.Q3,
                                              sensorsData.QuaternionData.Q0);
        }
    }
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTED)
        {
            // Connect to the robot and move to the next scene designated by the developer
            if (!m_MultipleSpheros)
            {
                m_Title = "CONNECTION SUCCESS";
                SpheroDeviceMessenger.SharedInstance.NotificationReceived -= ReceiveNotificationMessage;
                {
                    if (m_threadSafeLoadLevel != null)
                    {
                        m_threadSafeLoadLevel.LoadLevel(m_NextLevel);
                    }
                }
            }
        }
        else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTION_FAILED)
        {
            Sphero notifiedSphero = m_SpheroProvider.GetSphero(message.RobotID);
            // Connection only has failed if we are trying to connect to that robot the notification belongs to
            if (m_ConnectingRobotName.Equals(notifiedSphero.DeviceInfo.Name))
            {
                m_Title = "CONNECTION FAILED";
            }
        }
    }
Пример #3
0
    private void ReceiveAsyncMessage(object sender,
                                     SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        if (Time.timeScale > 0)
        {
            // Event Handler function
            SpheroDeviceSensorsAsyncData message =
                (SpheroDeviceSensorsAsyncData)eventArgs.Message;

            SpheroDeviceSensorsData sensorsData = message.Frames[0];

            // Get the yaw value which is used to rotate the on screen Sphero
            yaw1 = sensorsData.AttitudeData.Yaw;

            // Update the on screen Sphero position using the accelerometer values for x and y
            float   xAcceleration   = sensorsData.AccelerometerData.Normalized.X;
            float   yAcceleration   = sensorsData.AccelerometerData.Normalized.Y;
            Vector3 currentPosition = transform.position;

            // Create a new position by filtering the accelerometer data using the low pass
            // filtering formula (alpha * filteredValue + (1 - alpha) * newValue)
            position = new Vector3(0.9f * currentPosition.x + 0.35f * xAcceleration,
                                   0.9f * currentPosition.y + 0.1f * yAcceleration, 0.0f);
        }
    }
Пример #4
0
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTED)
        {
            // Go to the desired scene
            Application.LoadLevel(m_NextLevel);
        }
    }
Пример #5
0
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;
        Sphero notifiedSphero            = SpheroProvider.GetSharedProvider().GetSphero(message.RobotID);

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected;
            Application.LoadLevel("NoSpheroConnectedScene");
        }
    }
Пример #6
0
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED)
        {
            SpheroDeviceMessenger.SharedInstance.AsyncDataReceived    -= ReceiveAsyncMessage;
            SpheroDeviceMessenger.SharedInstance.NotificationReceived -=
                ReceiveNotificationMessage;
        }
    }
Пример #7
0
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        // Event handler that listens for disconnects. An example of when one would be received is when Sphero
        // goes to sleep.
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;
        Sphero notifiedSphero            = SpheroProvider.GetSharedProvider().GetSphero(message.RobotID);

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected;
            streaming = false;
            Application.LoadLevel("NoSpheroConnectedScene");
        }
    }
Пример #8
0
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTED)
        {
            // Go to the desired scene
            {
                if (m_threadSafeLoadLevel != null)
                {
                    m_threadSafeLoadLevel.LoadLevel("NoSpheroConnectedScene");
                }
            }
        }
    }
Пример #9
0
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;
        Sphero notifiedSphero            = GetSphero(message.RobotID);

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Connected;
        }
        else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected;
        }
        else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTION_FAILED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Failed;
        }
    }
Пример #10
0
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;
        Sphero notifiedSphero            = m_PairedSpheros[0];

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Connected;
            // Consider setting bluetooth device info here
        }
        else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected;
        }
        else if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.CONNECTION_FAILED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Failed;
        }
    }
Пример #11
0
    private void ReceiveAsyncMessage(object sender,
                                     SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        // Handler method for the streaming data. This code copies the data values
        // to instance variables, which are updated on the screen in the OnGUI method.
        SpheroDeviceSensorsAsyncData message =
            (SpheroDeviceSensorsAsyncData)eventArgs.Message;
        SpheroDeviceSensorsData sensorsData = message.Frames[0];

        acceleration = sensorsData.AccelerometerData.Normalized;

        pitch = sensorsData.AttitudeData.Pitch;
        roll  = sensorsData.AttitudeData.Roll;
        yaw   = sensorsData.AttitudeData.Yaw;

        q0 = sensorsData.QuaternionData.Q0;
        q1 = sensorsData.QuaternionData.Q1;
        q2 = sensorsData.QuaternionData.Q2;
        q3 = sensorsData.QuaternionData.Q3;
    }