Asked — Edited

Vr Options?

Does anyone know if the SDK of the Oculus Rift package would work with EZB if there was a plug in developed for it? It doesn't really need to be something as big and bulky as that. Very unfortunate that Vuzix is no longer offering support with EZB. That would work great.

Like the Vuzix, I'd like to pull from the IMU data to move servos and transfer the camera feed from the EZ camera to the goggles over two complete separate computers in different places.

Any ideas or suggestions on how to POC this, would be grateful.


ARC Pro

Upgrade to ARC Pro

Experience the transformation – subscribe to Synthiam ARC Pro and watch your robot evolve into a marvel of innovation and intelligence.

PRO
USA
#193  

@mickey, i thinks things are getting lost in translation. In post #191, that you have 8 DOF working, is that with another "board" and NOT working with ARC? LOL I'm so confused when you say "I have it working".

#194  

@fxrtst Yes this is correct! And I wanted to show this to proof it can be done, so maybe some more attention gets drawn to this thread!

But now we are having @ptp so we are blessed!:D

#196  

@ptp This script is great! I just cannot belive how fat you got this going!

So it works with JDs first two joints, while for whatever reason it seems to show the extracted values and also the amount of change for the two joints, but only one servo is moving...I will have to check my wiring to make sure it is not just some lazy wire somewhere!

But as soon as I hook up the third joint, the EZ-B drops out again...

PRO
USA
#197  

I'm preparing another script.

PRO
USA
#199  

namespace BioIK
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using EZ_B;
    using UnityEngine;

    public class RotNew : MonoBehaviour
    {
        private static ServoDefinition[] definitions = new ServoDefinition[]
        {
            //DEFINE YOUR SERVOS HERE
            //Start with one only, but you can assign RotNew to all Joints
            //Remember "0" is the joint name, you can define a proper name, the name must match the definition.

            //map joint "0"/X to D0
            new ServoDefinition("0", AxisType.X, Servo.ServoPortEnum.D0, false),

            //map joint "0"/Y to D1 but invert the servo value
            new ServoDefinition("0", AxisType.Y, Servo.ServoPortEnum.D1, true),

        };

        private int[] lastRotation = new[] { int.MinValue, int.MinValue, int.MinValue };

        private void Start()
        {
            EZBController.Instance.Connect("192.168.1.1");
        }

        private void OnApplicationQuit()
        {
            EZBController.Instance.Disconnect();
        }

        private void Update()
        {
            //Note: Start with a conservative value here
            //a high value slows down.
            const int interval = 30;
            if (Time.frameCount % interval != 0)
            {
                //don't run yet
                return;
            }

            BioJoint joint = this.GetComponent<BioJoint>();
            var rotation = new int[]
            {
                Mathf.RoundToInt((float)joint.X.GetTargetValue()),
                Mathf.RoundToInt((float)joint.Y.GetTargetValue()),
                Mathf.RoundToInt((float)joint.Z.GetTargetValue()),
            };

            if (rotation[0] == this.lastRotation[0] && rotation[1] == this.lastRotation[1] && rotation[2] == this.lastRotation[2])
            {
                //nothing changed
                return;
            }

            var servosToMove = new List<EZ_B.Classes.ServoPositionItem>();

            var jointServos = definitions.Where(js => js.JointName.Equals(this.name, StringComparison.OrdinalIgnoreCase)).ToArray();

            if (rotation[0] != this.lastRotation[0])
            {
                Debug.Log(string.Format("Joint:[{0}] X changed New=[{1}] Prev=[{2}]", this.name, rotation[0], this.lastRotation[0]));

                foreach (var servo in jointServos.Where(s => s.Axis == AxisType.X))
                {
                    servosToMove.Add(new EZ_B.Classes.ServoPositionItem(servo.Port, FixRotation(rotation[0], servo.Inverted)));
                }
            }

            if (rotation[1] != this.lastRotation[1])
            {
                Debug.Log(string.Format("Joint:[{0}] Y changed New=[{1}] Prev=[{2}]", this.name, rotation[1], this.lastRotation[1]));

                foreach (var servo in jointServos.Where(s => s.Axis == AxisType.Y))
                {
                    servosToMove.Add(new EZ_B.Classes.ServoPositionItem(servo.Port, FixRotation(rotation[1], servo.Inverted)));
                }
            }
            if (rotation[2] != this.lastRotation[2])
            {
                Debug.Log(string.Format("Joint:[{0}] Z changed New=[{1}] Prev=[{2}]", this.name, rotation[2], this.lastRotation[2]));

                foreach (var servo in jointServos.Where(s => s.Axis == AxisType.Z))
                {
                    servosToMove.Add(new EZ_B.Classes.ServoPositionItem(servo.Port, FixRotation(rotation[2], servo.Inverted)));
                }
            }

            this.lastRotation = rotation;

            if (servosToMove.Count > 0)
            {
                EZBController.Instance.SetServosPositions(servosToMove.ToArray());
            }
        }

        private int FixRotation(int deg, bool inverted, int middleAngle = 90)
        {

            return !inverted ? middleAngle + deg : (middleAngle * 2 - (middleAngle + deg));
        }

        private class EZBController
        {
            private EZB ezb;
            private object lockObject = new object();

            private EZBController()
            {
                this.ezb = new EZB("MyEzb");
                this.ezb.OnConnectionChange += this.EzbOnConnectionChange;
            }

            public static EZBController Instance
            {
                get { return Creator.Singleton; }
            }

            public void Connect(string hostname)
            {
                lock (this.lockObject)
                {
                    if (!this.ezb.IsConnected)
                    {
                        Debug.Log("Connecting to EZB hostname:" + hostname);
                        this.ezb.Connect(hostname);
                    }
                }
            }

            public void Disconnect()
            {
                lock (this.lockObject)
                {
                    if (this.ezb.IsConnected)
                    {
                        this.ezb.Disconnect();
                    }
                }
            }

            public void SetServoPosition(Servo.ServoPortEnum servoPort, int position)
            {
                if (!this.ezb.IsConnected)
                {
                    Debug.LogWarning("EZB is not connected, SetServoPosition will be ignored");
                    return;
                }

                try
                {
                    this.ezb.Servo.SetServoPosition(servoPort, position);
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex);
                }
            }

            public void SetServosPositions(EZ_B.Classes.ServoPositionItem[] servos)
            {
                if (!this.ezb.IsConnected)
                {
                    Debug.LogWarning("EZB is not connected, SetServosPositions will be ignored");
                    return;
                }

                try
                {
                    this.ezb.Servo.SetServoPosition(servos);
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex);
                }
            }



            private void EzbOnConnectionChange(bool isConnected)
            {
                Debug.Log("EZB connection changed to: " + (isConnected ? "Connected" : "Disconnect"));
            }

            private sealed class Creator
            {
                private static readonly EZBController instance = new EZBController();

                internal static EZBController Singleton
                {
                    get { return instance; }
                }
            }
        }

        private enum AxisType
        {
            X = 0,
            Y = 1,
            Z = 2
        }
        private class ServoDefinition
        {
            public Servo.ServoPortEnum Port;
            public string JointName;
            public AxisType Axis;
            public bool Inverted;
            public ServoDefinition(string jointName, AxisType axis, Servo.ServoPortEnum port, bool inverted)
            {
                this.Port = port;
                this.JointName = jointName;
                this.Axis = axis;
                this.Inverted = inverted;
            }
        }

    }
}

Please look to the code comments.