/* NoVRRoboterControl.cs * authors: Lydia ebbinghaus, Ayumi Bischoff, Yannic Seidler */ using System.Collections; using UnityEngine; using UnityEngine.InputSystem; using RosSharp.RosBridgeClient; using Valve.VR.InteractionSystem; // Class to Control the Robot in Unity and getting control signals over the Controller. // Attach to robot prefab in 2D mode (not recommended) public class NoVRRoboterControl : MonoBehaviour { // Just for using XBoxController &Keayboard for control. XBoxController controler; float moveforward; float movebackward; float rotateL; float rotateR; // Subscriber of position and inputreader of VR-controller. private PoseStampedSubscriber robot_pose_sub; Vector2 controlSignal; // Calibration variables. private int changed; public int calibrationtime; public float speed; private void Awake() { controler = new XBoxController(); MovementSetUp(); } // Setup of control with Input of old gamepad or keyboard.. private void MovementSetUp() { controler.Movement.Moveforward.performed += (InputAction.CallbackContext context) => moveforward = context.ReadValue() * speed; controler.Movement.Moveforward.canceled += (InputAction.CallbackContext context) => moveforward = 0; controler.Movement.Movebackward.performed += (InputAction.CallbackContext context) => movebackward = context.ReadValue() * speed; controler.Movement.Movebackward.canceled += (InputAction.CallbackContext context) => movebackward = 0; controler.Movement.RotationL.performed += (InputAction.CallbackContext context) => rotateL = context.ReadValue() * speed; controler.Movement.RotationL.canceled += (InputAction.CallbackContext context) => rotateL = 0; controler.Movement.RotationR.performed += (InputAction.CallbackContext context) => rotateR = context.ReadValue() * speed; controler.Movement.RotationR.canceled += (InputAction.CallbackContext context) => rotateR = 0; } private void OnEnable() { Debug.Log("Controller enabled"); controler.Movement.Enable(); } private void OnDisable() { Debug.Log("Controller disabled"); controler.Movement.Disable(); } // Start is called before the first frame update. // Starting coroutine and declerating variables. void Start() { changed=0; robot_pose_sub = GameObject.Find("RosBridge").GetComponent(); Debug.Log("Starting to update position"); StartCoroutine("timer"); } // Update is called once per frame. // Calibrates robot in the first "calibrationtime" cycles. void Update() { if(changed