// Update is called once per frame in Unity. The Unity camera follows the robot (which is driven by // the ROS environment. We also use the joystick or cursor keys to generate teleoperational commands // that are sent to the ROS world, which drives the robot which ... void Update() { float _dx, _dy; int _button = 0; if (_useJoysticks) { _dx = Input.GetAxis("Joy0X"); _dy = Input.GetAxis("Joy0Y"); } else { _dx = Input.GetAxis("Horizontal"); _dy = Input.GetAxis("Vertical"); Debug.Log("no joysticks " + _dx + " " + _dy); } float linear = _dy * 0.5f; float angular = -_dx * 0.2f; TwistMsg msg = new TwistMsg(new Vector3Msg(linear, 0.0, 0.0), new Vector3Msg(0.0, 0.0, angular)); ros.Publish(Turtle1Teleop.GetMessageTopic(), msg); if (Input.GetKeyDown(KeyCode.T)) { if (lineOn) { ros.CallService("/turtle1/set_pen", "{\"off\": 1}"); } else { ros.CallService("/turtle1/set_pen", "{\"off\": 0}"); } lineOn = !lineOn; } ros.Render(); }
public void Send_message() { float _dx = 0.1f, _dy = 0.2f; float linear = _dy * 0.5f; float angular = -_dx * 0.2f; TwistMsg msg = new TwistMsg(new Vector3Msg(linear, 10, 10), new Vector3Msg(-10, 40, angular)); ros.Publish(Turtle1Teleop.GetMessageTopic(), msg); Debug.Log("Message sent to ROS"); if (Input.GetKeyDown(KeyCode.T)) { if (lineOn) { ros.CallService("/turtle1/set_pen", "{\"off\": 1}"); } else { ros.CallService("/turtle1/set_pen", "{\"off\": 0}"); } lineOn = !lineOn; } ros.Render(); }