// Update is called once per frame in Unity void Update() { if (!started && Input.GetButtonDown("Start")) { ConnectionStatus.text = "Connected"; started = true; ros = new ROSBridgeWebSocketConnection("ws://localhost", 8080); ros.AddPublisher(typeof(CommandPublisher)); ros.AddPublisher(typeof(VelocityPublisher)); // Fire up the subscriber(s) and publisher(s) ros.Connect(); } ControlCommand command_msg = GetControlCommand(); Debug.Log("Sending: " + command_msg.ToYAMLString()); ControlVelocity velocity_msg = new ControlVelocity(GetPitch(), GetRoll(), GetThrottle(), GetYaw()); Debug.Log("Sending: " + velocity_msg.ToYAMLString()); // Publish it (ros is the object defined in the first class) ros.Publish(CommandPublisher.GetMessageTopic(), command_msg); ros.Publish(VelocityPublisher.GetMessageTopic(), velocity_msg); ros.Render(); }
void Awake() { simpleCarController = this.GetComponent <SimpleCarController>(); imagePublisher = this.GetComponent <ImagePublisher>(); laserScanPublisher = this.GetComponent <LaserScanPublisher>(); iMUPublisher = this.GetComponent <IMUPublisher>(); velocityPublisher = this.GetComponent <VelocityPublisher>(); gPSPublisher = this.GetComponent <GPSPublisher>(); motorsSubscriber = this.GetComponent <IGVCMotorsSubscriber>(); simpleCarController.useController = !RobotOptions.GetValue(robotName + "Autonomous").Equals("True"); //rosConnector.RosBridgeServerUrl = "ws://" + RobotOptions.GetValue(robotName + "ROS Bridge IP"); if (RobotOptions.Exists(robotName + "Camera Topic")) { imagePublisher.Topic = RobotOptions.GetValue(robotName + "Camera Topic"); } if (RobotOptions.Exists(robotName + "Show Camera View") && RobotOptions.GetValue(robotName + "Show Camera View").Equals("True")) { robotCamera.targetDisplay = 0; robotCamera.enabled = true; mainCamera.enabled = false; // If we are publishing the camera, we need to duplicate it because the publishing script // will override the camera output. if (RobotOptions.GetValue(robotName + "Publish Camera").Equals("True")) { GameObject robotCameraDupe = Instantiate(robotCamera.gameObject, robotCamera.gameObject.transform.parent); } } if (RobotOptions.GetValue(robotName + "Publish Camera").Equals("True")) { imagePublisher.enabled = true; robotCamera.enabled = true; } laserScanPublisher.Topic = RobotOptions.GetValue(robotName + "Laser Scan Topic"); iMUPublisher.Topic = RobotOptions.GetValue(robotName + "IMU Topic"); velocityPublisher.Topic = RobotOptions.GetValue(robotName + "Velocity Topic"); gPSPublisher.Topic = RobotOptions.GetValue(robotName + "GPS Topic"); motorsSubscriber.Topic = RobotOptions.GetValue(robotName + "Motors Topic"); }