Example #1
0
    // Update is called once per frame
    void Update()
    {
        UpdateState();

        // Send encoder data
        Newtonsoft.Json.Linq.JObject jo = new JObject();
        jo.Add(new JProperty("type", "CANEncoder"));
        jo.Add(new JProperty("device", $"Talon SRX[{Id}]/Quad Encoder"));
        Newtonsoft.Json.Linq.JObject dataObject = new JObject();
        dataObject.Add(new JProperty(">rawPositionInput", encoderPosition));
        dataObject.Add(new JProperty(">velocity", encoderVelocity));
        jo.Add("data", dataObject);
        string message = JsonConvert.SerializeObject(jo);

        WebSocketInterface.Send(message);

        jo = new JObject();
        jo.Add(new JProperty("type", "CANMotor"));
        jo.Add(new JProperty("device", $"Talon SRX[{Id}]"));
        dataObject = new JObject();
        dataObject.Add(new JProperty(">busVoltage", busVoltage));
        dataObject.Add(new JProperty(">supplyCurrent", supplyCurrent));
        dataObject.Add(new JProperty(">motorCurrent", motorCurrent));
        jo.Add("data", dataObject);
        message = JsonConvert.SerializeObject(jo);
        WebSocketInterface.Send(message);
    }
    // Update is called once per frame
    void Update()
    {
        if (ws)
        {
            Newtonsoft.Json.Linq.JObject jo = new JObject();
            jo.Add(new JProperty("type", "DriverStation"));
            jo.Add(new JProperty("device", ""));

            Newtonsoft.Json.Linq.JObject dataObject = new JObject();
            dataObject.Add(new JProperty(">new_data", newData));
            //dataObject.Add(new JProperty(">enabled", enable));

            dataObject.Add(new JProperty(">enabled", enable ? 1 : 0));

            dataObject.Add(new JProperty(">autonomous", autonomous ? 1 : 0));
            //dataObject.Add(new JProperty(">test", testing ? 1 : 0));
            dataObject.Add(new JProperty(">estop", estop ? 1 : 0));
            dataObject.Add(new JProperty(">fms", fmsConnected));
            dataObject.Add(new JProperty(">ds", dsConnected));
            dataObject.Add(new JProperty(">station", station));
            // dataObject.Add(new JProperty(">match_time", matchTime));
            dataObject.Add(new JProperty(">game_data", gameData));
            jo.Add("data", dataObject);

            string message = JsonConvert.SerializeObject(jo);
            if (enable && teleop)
            {
                //    Debug.Log($"Driverstation message {message}");
            }
            ws.Send(message);
        }

        newData = false;
    }
    // Update is called once per frame
    // Inputs to robot code
    void Update()
    {
        // add processing for each value

        Newtonsoft.Json.Linq.JObject jo = new JObject();
        jo.Add(new JProperty("type", "RoboRIO"));
        jo.Add(new JProperty("device", ""));

        Newtonsoft.Json.Linq.JObject dataObject = new JObject();
        dataObject.Add(new JProperty(">fpga_button", fpgaButton));
        dataObject.Add(new JProperty(">vin_voltage", vinVoltage));
        dataObject.Add(new JProperty(">vin_current", vinCurrent));

        dataObject.Add(new JProperty(">6v_voltage", sixvVoltage));
        dataObject.Add(new JProperty(">6v_current", sixvCurrent));
        dataObject.Add(new JProperty(">6v_active", sixvActive));
        dataObject.Add(new JProperty(">6v_faults", sixvFaults));

        dataObject.Add(new JProperty(">5v_voltage", fivevVoltage));
        dataObject.Add(new JProperty(">5v_current", fivevCurrent));
        dataObject.Add(new JProperty(">5v_active", fivevActive));
        dataObject.Add(new JProperty(">5v_faults", fivevFaults));

        dataObject.Add(new JProperty(">3v3_voltage", threeThreevVoltage));
        dataObject.Add(new JProperty(">3v3_current", threeThreevCurrent));
        dataObject.Add(new JProperty(">3v3_active", threeThreevActive));
        dataObject.Add(new JProperty(">3v3_faults", threeThreevFaults));

        jo.Add("data", dataObject);
        string message = JsonConvert.SerializeObject(jo);

        ws.Send(message);
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        if (encoder)
        {
            int counts = encoder.Counts;
            // compute velocity.Position already figured by encoder.
            encoderPosition = counts;
            // Compute velocity as change in position. Delta ticks /time in seconds / 10 to get time per 100 mSec
            encoderVelocity  = ((counts - lastEncoderValue)) / (Time.deltaTime) / 10.0f;
            lastEncoderValue = counts;
        }
        supplyCurrent = Mathf.Abs((float)percentOutput) * 30 * Random.Range(0.95f, 1.05f);
        busVoltage    = 12.0 - (percentOutput * percentOutput) * 0.75 * Random.Range(0.95f, 1.05f);

        // Send encoder data
        Newtonsoft.Json.Linq.JObject jo = new JObject();
        jo.Add(new JProperty("type", "SimDevice"));
        jo.Add(new JProperty("device", $"Talon SRX[{Id}]/Encoder"));
        Newtonsoft.Json.Linq.JObject dataObject = new JObject();
        dataObject.Add(new JProperty(">position", encoderPosition));
        dataObject.Add(new JProperty(">velocity", encoderVelocity));
        jo.Add("data", dataObject);
        string message = JsonConvert.SerializeObject(jo);

        ws.Send(message);
//        Debug.Log($"talon encoder data sent is {message}");

        jo = new JObject();
        jo.Add(new JProperty("type", "SimDevice"));
        jo.Add(new JProperty("device", $"Talon SRX[{Id}]"));
        dataObject = new JObject();
        dataObject.Add(new JProperty(">busVoltage", busVoltage));
        dataObject.Add(new JProperty(">supplyCurrent", supplyCurrent));
        // dataObject.Add(new JProperty(">motorCurrent", motorCurrent));
        jo.Add("data", dataObject);
        message = JsonConvert.SerializeObject(jo);
        ws.Send(message);

        // wpk future - add support for DutyCycle,
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        if (ws)
        {
            Newtonsoft.Json.Linq.JObject jo = new JObject();
            jo.Add(new JProperty("type", "AI"));
            jo.Add(new JProperty("device", $"{PortNumber}"));

            Newtonsoft.Json.Linq.JObject dataObject = new JObject();
            dataObject.Add(new JProperty(">voltage", voltage));
            jo.Add("data", dataObject);
            string message = JsonConvert.SerializeObject(jo);
            ws.Send(message);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (ws)
        {
            Newtonsoft.Json.Linq.JObject jo = new JObject();
            jo.Add(new JProperty("type", "DIO"));
            jo.Add(new JProperty("device", $"{EncoderNumber}"));

            Newtonsoft.Json.Linq.JObject dataObject = new JObject();
            dataObject.Add(new JProperty(">count", count));
            jo.Add("data", dataObject);
            string message = JsonConvert.SerializeObject(jo);
            ws.Send(message);
        }
    }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        if (ws)
        {
            Newtonsoft.Json.Linq.JObject jo = new JObject();
            jo.Add(new JProperty("type", "PCM"));
            jo.Add(new JProperty("device", $"{PCMNumber}"));

            Newtonsoft.Json.Linq.JObject dataObject = new JObject();
            dataObject.Add(new JProperty(">current", current));
            dataObject.Add(new JProperty(">on", isOn));
            dataObject.Add(new JProperty(">pressure_switch", pressureSwitch));
            jo.Add("data", dataObject);
            string message = JsonConvert.SerializeObject(jo);
            ws.Send(message);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (ws)
        {
            Newtonsoft.Json.Linq.JObject jo = new JObject();
            jo.Add(new JProperty("type", "Joystick"));
            jo.Add(new JProperty("device", JoystickNumber.ToString()));

            Newtonsoft.Json.Linq.JObject dataObject = new JObject();

            double[] axisValues = new double[NumAxes];
            for (int i = 0; i < AxisName.Length; i++)
            {
                if (AxisName[i].Trim() != "")
                {
                    axisValues[i] = Input.GetAxis(AxisName[i]);
                }
                else
                {
                    axisValues[i] = 0.0;
                }
            }
            dataObject.Add(new JProperty(">axes", axisValues));

            bool[] buttonValues = new bool[NumButtons];
            for (int i = 0; i < ButtonName.Length; i++)
            {
                if (ButtonName[i].Trim() != "")
                {
                    buttonValues[i] = Input.GetAxis(ButtonName[i]) > 0;
                }
                else
                {
                    buttonValues[i] = false;
                }
            }
            dataObject.Add(new JProperty(">buttons", buttonValues));

            jo.Add("data", dataObject);

            string message = JsonConvert.SerializeObject(jo);
            ws.Send(message);
        }
    }
    // Update is called once per frame
    void Update()
    {
        // If its an input to the Roborio (i.e.,output from the sim)
        if (isInput)
        {
            if (ws)
            {
                Newtonsoft.Json.Linq.JObject jo = new JObject();
                jo.Add(new JProperty("type", "DIO"));
                jo.Add(new JProperty("device", $"{PortNumber}"));

                Newtonsoft.Json.Linq.JObject dataObject = new JObject();
                dataObject.Add(new JProperty("<>value", currentValue));
                jo.Add("data", dataObject);
                string message = JsonConvert.SerializeObject(jo);
                ws.Send(message);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        // In unity, the axis normal to the ground is the Y axis.
        angle     = this.transform.rotation.eulerAngles.y;
        rate      = (angle - lastAngle) / Time.deltaTime;
        lastAngle = angle;

        // Send encoder data
        Newtonsoft.Json.Linq.JObject jo = new JObject();
        jo.Add(new JProperty("type", DeviceType));
        jo.Add(new JProperty("device", deviceName));
        Newtonsoft.Json.Linq.JObject dataObject = new JObject();
        dataObject.Add(new JProperty(">angle_x", this.angle));
        dataObject.Add(new JProperty(">rate_x", this.rate));
        jo.Add("data", dataObject);
        string message = JsonConvert.SerializeObject(jo);

        WebSocketInterface.Send(message);
    }
Example #11
0
    // Update is called once per frame
    void Update()
    {
        if (Body)
        {
            // In unity, the axis normal to the ground is the Y axis.
            yaw            = AdjustedAngle(this.transform.rotation.eulerAngles.y);
            pitch          = AdjustedAngle(this.transform.rotation.eulerAngles.x);
            roll           = AdjustedAngle(this.transform.rotation.eulerAngles.z);
            rate           = Mathf.Rad2Deg * Body.angularVelocity.y;
            compassHeading = this.transform.rotation.eulerAngles.y;
            fusedHeading   = this.transform.rotation.eulerAngles.y;
            lastYaw        = yaw;

            Vector3 linearWorldAccel = (Body.velocity - lastVelocity) / Time.deltaTime;
            accelX       = $"{linearWorldAccel.x:0.000}";
            accelY       = $"{linearWorldAccel.y:0.000}";
            accelZ       = $"{linearWorldAccel.z:0.000}";
            lastVelocity = Body.velocity;

            // Send encoder data
            Newtonsoft.Json.Linq.JObject jo = new JObject();
            jo.Add(new JProperty("type", DeviceType));
            jo.Add(new JProperty("device", deviceName));
            Newtonsoft.Json.Linq.JObject dataObject = new JObject();
            dataObject.Add(new JProperty(">Yaw", yaw));
            dataObject.Add(new JProperty(">Pitch", pitch));
            dataObject.Add(new JProperty(">Roll", roll));
            dataObject.Add(new JProperty(">Rate", rate));

            dataObject.Add(new JProperty(">CompassHeading", compassHeading));
            dataObject.Add(new JProperty(">FusedHeading", fusedHeading));

            // The following code maps from unity axes to NavX axes.
            dataObject.Add(new JProperty(">LinearWorldAccelX", linearWorldAccel.x));
            dataObject.Add(new JProperty(">LinearWorldAccelY", linearWorldAccel.z));
            dataObject.Add(new JProperty(">LinearWorldAccelZ", linearWorldAccel.y));

            jo.Add("data", dataObject);
            string message = JsonConvert.SerializeObject(jo);
            WebSocketInterface.Send(message);
        }
    }