Is there any way to get information about whether the ROS-TCP Connector is connected to ros?

Is there any way to get information about whether the ROS-TCP Connector is connected to ros? I would like to disable some buttons in Unity if Unity is not connected to ROS. Is there an easy way to do this, like an attribute or a method?

[quote=“agru”, post:1, topic: 868153]
Is there any way to get information about whether the ROS-TCP Connector is connected to ros? I would like to disable some buttons in Unity if Unity is not connected to ROS. Is there an easy way to do this, like an attribute or a method?
[/quote]

Hi, I wrote this code quickly.
The ROSConnection class has a boolean called “HasConnectionError” that changes every time the ros_tcp_endpoint is connected on the ROS side.
You can use it to check if ROS is connected in Unity or if it has disconnected in runtime.
So you can use it to disable and enable your buttons.

using UnityEngine;
using Unity.Robotics.ROSTCPConnector;

public class ROSState : MonoBehaviour
{
    private ROSConnection ROS;

    void Start()
    {
        ROS = ROSConnection.GetOrCreateInstance(); // Get ROS connection static instance
    }
    void Update()
    {
        if (ROS.HasConnectionError)
        {
            Debug.Log("ROS is not connected");
            //Do some stuff
        }
        else
        {
            Debug.Log("ROS is connected");
            //Do some stuff
        }
    }
}
2 Likes

Thank you very much! :slight_smile:

1 Like