-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROSInitializer.cs
34 lines (29 loc) · 1.08 KB
/
ROSInitializer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ROSBridgeLib;
public class ROSInitializer : MonoBehaviour
{
public ROSBridgeWebSocketConnection ros = null;
void Start() {
// rosbridge_server node has to be launched before:
// roslaunch rosbridge_server rosbridge_websocket.launch
// Where the rosbridge instance is running, could be localhost, or some external IP (9090 default port)
ros = new ROSBridgeWebSocketConnection ("ws://localhost", 9090);
// Add subscribers and publishers (if any)
ros.AddSubscriber(typeof(PointCloudSubscriber));
ros.AddSubscriber(typeof(TFSubscriber));
// Fire up the subscriber(s) and publisher(s)
ros.Connect ();
}
// Extremely important to disconnect from ROS. Otherwise packets continue to flow
void OnApplicationQuit() {
if(ros!=null) {
ros.Disconnect ();
}
}
// Update is called once per frame in Unity
void Update () {
ros.Render ();
}
}