void PublishWindDirection() { if (ready) { RosInterface.Publish <Float32> ("/anemometer", new Float32(windDirection)); } }
void PublishCurrentPos() { if (ready) { RosInterface.Publish <Point> ("/lps", new Point(boatPos)); } }
void PublishWaypoints() { if (ready) { RosInterface.Publish <PointArray> ("/waypoints", new PointArray(waypoints)); } }
void Awake() { if (!instance) { instance = this; } else { Debug.LogWarning("Please only have one instance of RosInterface script."); } }
//entry point public void InitSimulation(string ip) { //expect ip to be in format "192.168.0.29:9090" string fullUrl = "ws://" + ip; RosInterface.Connect(fullUrl); RosInterface.Subscribe <BoatState> ("/boat_state", "boat_msgs/BoatState").MessageReceived += OnBoatStateMsg; RosInterface.Subscribe <Float32> ("/target_heading", "std_msgs/Float32").MessageReceived += OnHeadingMsg; RosInterface.Subscribe <Float32> ("/winch", "std_msgs/Int32").MessageReceived += OnWinchMsg; RosInterface.Advertise("/lps", "boat_msgs/Point"); RosInterface.Advertise("/waypoints", "boat_msgs/PointArray"); RosInterface.Advertise("/anemometer", "std_msgs/Float32"); ready = true; PublishWaypoints(); PublishWindDirection(); boatPos = boatVel = boatAccel = Vector2.zero; PublishCurrentPos(); }