siemens / ros-sharp

ROS# is a set of open source software libraries and tools in C# for communicating with ROS from .NET applications, in particular Unity3D
Apache License 2.0
984 stars 373 forks source link

Trouble setting up ros-sharp for unity on Ubuntu #443

Open rodhakate opened 1 year ago

rodhakate commented 1 year ago

So I have imported the ROS# package available on Asset store (https://assetstore.unity.com/packages/tools/physics/ros-107085)

The import was successful however when I tried to create a publisher I have encountering the namespace error.

error CS0234: The type or namespace name 'Messages' does not exist in the namespace 'RosSharp.RosBridgeClient' (are you missing an assembly reference?)

In the "Assets" > "RosSharp" > "Scripts" > "RosBridgeClient" there is no Messages folder, Instead there is MessageHandling folder.

Following is the code I am having issues with.

using UnityEngine;
using RosSharp.RosBridgeClient;
using RosSharp.RosBridgeClient.Messages.Geometry;
using RosSharp.RosBridgeClient.Messages.Standard;

public class UnityPublisher : MonoBehaviour {

    public string PositionTopicName = "/position";
    public string OrientationTopicName = "/orientation";
    public string LinearVelocityTopicName = "/linear_velocity";
    public string AngularVelocityTopicName = "/angular_velocity";
    public string CablesTopicName = "/cables";

    private RosSocket rosSocket;
    private Pose positionMessage;
    private QuaternionMessage orientationMessage;
    private Vector3Message linearVelocityMessage;
    private Vector3Message angularVelocityMessage;
    private Float32MultiArray cablesMessage;

    // Use this for initialization
    void Start () {
        rosSocket = new RosSocket("ws://localhost:9090");

        positionMessage = new Pose();
        orientationMessage = new QuaternionMessage();
        linearVelocityMessage = new Vector3Message();
        angularVelocityMessage = new Vector3Message();
        cablesMessage = new Float32MultiArray();
    }

    // Update is called once per frame
    void Update () {
        // Publish position
        positionMessage.position.x = robPos_x;
        positionMessage.position.y = robPos_y;
        positionMessage.position.z = robPos_z;
        rosSocket.Publish(PositionTopicName, positionMessage);

        // Publish orientation
        orientationMessage.x = robotOri_eul.x;
        orientationMessage.y = robotOri_eul.y;
        orientationMessage.z = robotOri_eul.z;
        orientationMessage.w = robotOri_quat.w;
        rosSocket.Publish(OrientationTopicName, orientationMessage);

        // Publish linear velocity
        linearVelocityMessage.x = robLinVel_x;
        linearVelocityMessage.y = robLinVel_y;
        linearVelocityMessage.z = robLinVel_z;
        rosSocket.Publish(LinearVelocityTopicName, linearVelocityMessage);

        // Publish angular velocity
        angularVelocityMessage.x = robAngVel_x;
        angularVelocityMessage.y = robAngVel_y;
        angularVelocityMessage.z = robAngVel_z;
        rosSocket.Publish(AngularVelocityTopicName, angularVelocityMessage);

        // Publish cables
        cablesMessage.data = new float[] { c1_len, c2_len, c3_len, c4_len };
        rosSocket.Publish(CablesTopicName, cablesMessage);
    }

    private void OnApplicationQuit()
    {
        rosSocket.Close();
    }
}