GithubHelp home page GithubHelp logo

unityros's Introduction

Version 3.3

Updated everything to work with ROS Indigo. All of the std_msgs are now there, although some of the more less often used ones are not fully debugged.

Cleaned up the repository somewhat, removing files not directly source code related.

Updated the TurtleSimViewer application so that the parameters are visible in the editor.

Removed unnecessary files from the repository

Version 3.2

Updated turtlesim example to work with ROS Hydro and added some geometry message files

Version 3.1

Major change here is to make the c# method names all upper case and to add better comments

Version 3.0 Its self documenting (ha).

So its a unity project, with two basic libraries * SimpleJSON - to do the basic JSON work * ROSBridgeLib - to do the ROSBridge-Unity heavy lifting

There is a sample application built at the top of the library. It requires a ROS world somewhere running the turtlesim package along with rosbridge. Turtlesim made some changes after groovy, and this has only been tested with groovy, so I would start there.

There is one hard coded constant in TurtleSimViewer - the ip address of the host running the rosbridge package.

Fire up the turtle simulator under ros along with rosbridge web socket server. Then fire up the unity program. with luck (?) you should see a checkerboard with a robot on it. The robot is listening to the location of the turtle and updating its location and orientation as appropriate. So if you teleoperate the turtle around its motion should be tracked by the unity robot. The unity camera is slaved to the robot.

The cursor keys are used to generate tele operational instructions for the turtle simulator in ros, which in turn moves the turtle, which in turn moves the robot in unity.

As a final example, the T key is tied to a ros service, that turns the pen on and off on the turtle simulator.

Note: SimpleJSON is included here as a convenience. It has its own licensing requirements. See source code and unity store for details.

Version 2.0

A hacked up version for the CSA demo

unityros's People

Contributors

rcodddow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unityros's Issues

Publishing custom message that requires BSON

Hi!

Thanks for creating this library, I've been using it a lot lately in my robust tele-operation work and it has been awesome. I am stuck at a small problem. I'm transferring a custom made message composed of Stochastic params (extremely compressed Dense Point Clouds). It is lower in size than sensor_msgs/PointCloud, but is significantly high to such extent that I am observing high network latency. Moreover, I am not reading data using roslibjs. I am using this repo in Unity C# to parse data. Currently, I have a nicely working JSON parser which parses my data with some latency.

Will this BSON enhancement work for such custom messages too? Other than writing a BSON parser, what other enhancements would my repo require?

Thanks for having a look. Awaiting your response.

Kshitij

Publishing image to ROS

Hi. Thanks very much for putting together this awesome library to connect Unity 3D to ROS. I have enjoyed using it to connect SLAM algorithms to Unity 3D. I had a quick question regarding publishing images. I'm trying to publish an image to ROS bridge every 2 seconds.

Does this use case feel feasible? Any help you can offer would be appreciated.

ROS is currently mentioning that it's missing an op code.

`
using UnityEngine;
using System;
using System.Collections;
using ROSBridgeLib.sensor_msgs;
using ROSBridgeLib.std_msgs;
using ROSBridgeLib;
using System.Text;

public class VideoTexture : MonoBehaviour {

// Use this for initialization
ROSBridgeWebSocketConnection ros;
WebCamTexture webcamTexture;
int count;
DateTime lastFrame;
DateTime camStart;
void Start () {

    webcamTexture = new WebCamTexture();
    Renderer renderer = GetComponent<Renderer>();
    renderer.material.mainTexture = webcamTexture;
    webcamTexture.Play();


    ros = new ROSBridgeWebSocketConnection ("ws://192.168.2.12", 9090);
    ros.AddPublisher(typeof(ImagePublisher));

    ros.Connect ();

    count = 0;
    lastFrame = DateTime.Now;
    camStart = DateTime.Now;
}

void OnApplicationQuit() {
    if(ros!=null)   
        ros.Disconnect ();

}


// Update is called once per frame
void Update () {

    //get jpeg of current frame ..
    Texture2D snap = new Texture2D(webcamTexture.width, webcamTexture.height);
    snap.SetPixels(webcamTexture.GetPixels());
    snap.Apply();

    byte[] data = snap.EncodeToJPG();
    string picString = Convert.ToBase64String(data);

    //picString = picString.Replace("data:image/jpeg;base64,", "");

    // set format
    string format = "jpeg";

    //How do you get a header message???
    // public TimeMsg(int secs, int nsecs)


    var now = DateTime.Now;
    var timeSpan = now - lastFrame;
    var timeSinceStart = now - camStart;

    if(timeSpan.Seconds > 2)
    {
        var timeMessage = new TimeMsg(timeSinceStart.Seconds, timeSinceStart.Milliseconds);

        // public HeaderMsg(int seq, TimeMsg stamp, string frame_id) 
        var headerMessage = new HeaderMsg(count, timeMessage, "camera");

        //CompressedImageMsg(HeaderMsg header, string format, byte[] data)
        byte[] array = Encoding.ASCII.GetBytes(picString);
        var compressedImageMsg = new CompressedImageMsg(headerMessage, format, array);

        ros.Publish(ImagePublisher.GetMessageTopic(), compressedImageMsg);

        lastFrame = now;
        count++;

    }

    ros.Render ();

}

}

`

Creating a new ros type

Hi,

I need to subscribe to a new type of message, LogMsg.
I wrote the msg as follows. It's located under Assets/ROSBridgeLib/tevel_msgs

/////////////////////////////////////////////////////////////////////
using System.Collections;
using System.Text;
using SimpleJSON;
using ROSBridgeLib.tevel_msgs;


namespace ROSBridgeLib {
namespace tevel_msgs {
	public class LogMsg : ROSBridgeMsg {
		private string _module_name;
		private string _text;

		public LogMsg(JSONNode msg) {
			_module_name 	= msg ["module_name"].Value;
			_text 		= msg ["text"].Value;
		}

		public LogMsg(string moduleName, string text) {
			_module_name	= moduleName;
			_text 		= text;
		}

		public static string GetMessageType() {
			return "tevel_msgs/Log";
		}

		public string GetText() {
			return _text;
		}

		public string GetModule() {
			return _module_name;
		}

		public override string ToString() {
			return "text =" + _text;
		}

		public override string ToYAMLString() {
			return "{\"text\" : " + _text + "}";
		}
	}
}
}
//////////////////////////////////////////////////////

The subscriber is this:

////////////////////////////////////////////////////////////
using ROSBridgeLib;
using ROSBridgeLib.tevel_msgs;
using System.Collections;
using SimpleJSON;
using UnityEngine;

public class TevelInfo : ROSBridgeSubscriber {

public delegate void NewLogMessageDelegate (string module, string text);//, int type);
public static event NewLogMessageDelegate newLogMessageEvent;

public static int lastCounter = -1;

public new static string GetMessageTopic() {
	return "/tevel/info";
}  

public new static string GetMessageType() {
	return "tevel_msgs/Log";
}


public new static ROSBridgeMsg ParseMessage(JSONNode msg) {
	LogMsg newMsg = new LogMsg(msg);
	if (newLogMessageEvent != null)
		newLogMessageEvent (newMsg.GetModule (), newMsg.GetText ());

	return new LogMsg(msg);
}

public new static void CallBack(ROSBridgeMsg msg) {
	
}
}
///////////////////////////////////////////////////////////////////

I use this line of code:
ros.AddSubscriber (typeof(TevelInfo));
And on RosBridge on Ubuntu, I get this error message:
subscribe: Unable to load the manifest for package tevel_msgs. Caused by: tevel_msgs

Why can't I subscribe to any topic / message type I want?

Thanks :-)

Not able to parse float32[]

I am trying to subscribe to a rosmsg that looks like this :

std_msgs/Header header
uint32 seq
time stamp
string frame_id
uint8 order
float32[] knot_times
float32[] coefficients
float32 sample_dt

I debugged a little bit and found out that my message file is not able to parse a float32 array. If I just take a byte, it works fine.

JointState messages

Hey,

I also want to thank you guys for providing this great environment.
I have an issue that I want to publish JointState messages from Unity to ROS. But if publish them i also get the error in ROS:
roserror

Here is the code to JointMsg i created:
`using System.Collections;
using System.IO;
using System.Text;
using SimpleJSON;
using ROSBridgeLib.std_msgs;
using UnityEngine;
using System;
using System.Linq;
using System.Collections.Generic;

namespace ROSBridgeLib {
namespace sensor_msgs {
public class JointStateMsg : ROSBridgeMsg {
private HeaderMsg _header;
private string _name;
private double[] _position;
private double[] _velocity;
private double[] _effort;

		public JointStateMsg(JSONNode msg) {
			_header = new HeaderMsg (msg ["header"]);
            string jointnames = msg["name"];
            //_name = jointnames.Split(new[] { ", " }, StringSplitOptions.None);
            _position = Array.ConvertAll((msg["position"]).Split(','), new Converter<string, double>(Double.Parse));
            _velocity = Array.ConvertAll((msg["velocity"]).Split(','), new Converter<string, double>(Double.Parse));
            _effort = Array.ConvertAll((msg["effort"]).Split(','), new Converter<string, double>(Double.Parse));

        }
		
		public JointStateMsg(HeaderMsg header, string[] name, double[] position, double[] velocity, double[] effort) {
			_header = header;
			//_name = name;
			_position = position;
            _velocity = velocity;
            _effort = effort;
        }

        public JointStateMsg(HeaderMsg header, string name_joined, double[] position, double[] velocity, double[] effort)
        {
            _header = header;
            _name = name_joined;
            _position = position;
            _velocity = velocity;
            _effort = effort;
        }

        public double[] GetPosition() {
			return _position;
		}

        public double GetJointPosition(int Joint)
        {
            return _position[Joint];
        }
        
        public double[] GetVelocity()
        {
            return _velocity;
        }

        public double GetJointVelocity(int Joint)
        {
            return _velocity[Joint];
        }

        public double GetJointEffort(int Joint)
        {
            return _effort[Joint];
        }

        public double[] GetEffort()
        {
            return _effort;
        }

        public static string GetMessageType() {
			return "sensor_msgs/JointState";
		}
		
		public override string ToString() {
			return "Joint State [Header " + _header.ToString() + ",  name =" + _name
                + ", position = " + string.Join(", ", _position.Select(p => p.ToString()).ToArray())
                + ", velocity = " + string.Join(", ", _velocity.Select(p => p.ToString()).ToArray())
                + ", effort = " + string.Join(", ", _effort.Select(p => p.ToString()).ToArray()) + "]";
		}

        public override string ToYAMLString()
        {

            return "{\"header\" :" + _header.ToYAMLString()
                           + ", {\"name\": " + "[" + _name + "]}"
                           + ", {\"position\": " + "[" + string.Join(", ", _position.Select(p => p.ToString()).ToArray()) + "]}"
                           + ", {\"velocity\": " + "[" + string.Join(", ", _velocity.Select(p => p.ToString()).ToArray()) + "]}"
                           + ", {\"effort\": " + "[" + string.Join(", ", _effort.Select(p => p.ToString()).ToArray()) + "]}"
                           + "}";
        }
	}
}

}`

How should I pass those string[] and double[] to ROS?

Maybe you guys could help me. Would be great.
Many thanks

Point Cloud Library not found?

When adding all the files in Unity, I get the error:

The type or namespace name 'PointCloud' could not be found (are you missing a using directive or an assembly reference?)

Do I need a specific PCL?

Cheers

Edit: Found the submodule, sorry to have bothered

Can't read sensor_msgs/PointCloud

Is there an upper bound to the data that can be transmitted through rosbridge? I am not able to transfer my point cloud message in time and there's too much lag in transferring.

I saw this paper and I'm curious as to how it is achieved in real-time using this repository.

Failed to send StringMsg

Hello,

I am trying to follow example from the submodule developed here

I am trying to check my connection by sending string message, however, my final intention is to send an array of integer values coming from slider position I have.

Presently I am trying this:

#if UNITY_EDITOR
    void Start(){

        ros = new ROSBridgeLib.ROSBridgeWebSocketConnection("ws://192.168.142.67", 9090);
        ros.AddPublisher(typeof(ROSCommsSlider));

        
       
    }
#endif
#if UNITY_EDITOR
    private void OnApplicationQuit(){
        if (ros != null) {
            ros.Disconnect();
        }
    }
#endif

#if UNITY_EDITOR
    public void my_func() {
       
    }
#endif

    // Update is called once per frame
    void Update() {
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.C))
        {
            ros.Connect();
        }
        
        //ros.Render();
        ROSBridgeLib.std_msgs.StringMsg ms = new ROSBridgeLib.std_msgs.StringMsg("checking_connection");
        ros.Publish(ROSCommsSlider.GetMessageTopic(), ms);
#endif
}

my ROSCommsSlider looks like this:

public class ROSCommsSlider : ROSBridgeLib.ROSBridgePublisher {
    // my class for sending message to ROSbridge
    public static string GetMessageTopic()
    {
        return "/joint_values";
    }
        public static string GetMessageType()
    {
        return "std_msgs/String";
    }

    public static string ToYAMLString(ROSBridgeLib.std_msgs.StringMsg msg)
    {
        return msg.ToYAMLString();
    }

    public new static ROSBridgeMsg ParseMessage(JSONNode msg)
    {
        return new ROSBridgeLib.std_msgs.StringMsg(msg);
    }

}

When I run the ros bridge, for some reason it is creating 3 client connection instance, but however, it doesn't send in the string to my topic when I do:
rostopic echo /joint_values

I do get this in my unity console:

Sending {"op": "advertise", "topic": "/joint_values", "type": "std_msgs/String"}
UnityEngine.Debug:Log(Object)
ROSBridgeLib.ROSBridgeWebSocketConnection:Run() (at Assets/ROSBridgeLib/ROSBridgeWebSocketConnection.cs:195)

and an error:

InvalidOperationException: The current state of the connection is not Open.
WebSocketSharp.WebSocket.Send (System.String data)
ROSBridgeLib.ROSBridgeWebSocketConnection.Publish (System.String topic, .ROSBridgeMsg msg) (at Assets/ROSBridgeLib/ROSBridgeWebSocketConnection.cs:264)
ROSCommsMain.Update () (at Assets/Scripts/ROSCommsMain.cs:73)

which i dont understand why as under my rosbridge shows: Clients Connected.

Additionally, I receive this Null Reference Issue when close the unity editor play.

NullReferenceException: Object reference not set to an instance of an object

ROSBridgeLib.ROSBridgeWebSocketConnection.Disconnect () (at Assets/ROSBridgeLib/ROSBridgeWebSocketConnection.cs:170)
ROSCommsMain.OnApplicationQuit () (at Assets/Scripts/ROSCommsMain.cs:27)

Compatibility with ros kinetic?

Hello,

Has anyone had success using the library with ros kinetic? I haven't tested yet, but I am wondering if serialization formats may have changed in recent releases of rosbridge, for example.

Publishing OccupancyGrid Message to ROS

Hello,
Thank you for your work!
I am using your library to send and receive some SLAM maps between unity and ROS. I have succeeded in sending OccupancyGrid msgs from ROS to Unity. However, when trying to send msg back from Unity I am having the "op" error below:

[ERROR] [WallTime: 1514206643.195341] [Client 1] Received a message without an op. All messages require 'op' field with value one of: ['service_response', 'unadvertise_service', 'call_service', 'publish', 'fragment', 'subscribe', 'advertise_service', 'unsubscribe', 'unadvertise', 'advertise']. Original message was:

{"op": "publish",
"topic": "/Unitymap",
"msg": {
"info":
{"origin":
{"position": {"y": -10, "x": -10, "z": 0}, "orientation": {"y": 0, "x": 0, "z": 0, "w": 1}},
"width": 192,
"map_load_time": {"secs": 0, "nsecs": 0},
"resolution": 0.1,
"height": 192},
"header":
{"stamp": {"secs": 1514206624, "nsecs": 631136325},
"frame_id"= "map",
"seq": 2422},
"data":[0,0,0,0,0,0,0,0,0]}} --->> I deleted the data to save some space here.

I have been stuck in this a error for a while, your help is much appreciated!!

Call_service and no response

Hallo,

i used the rosbridge to connect ROS with Unity, which i control the RPLidar, when i call the function RosbridgeWebSocketConnection.CallService with the string
CallService("/stop_motor", null)
as i understood, this should send the message {"op": "call_service", "service": "/stop_motor"} to ROS, and it supposed to call the service in ROS so that the PRLidar would stop, but it dose not work.
Have i done something wrong?
Thanks in advance

JSON Compression for point cloud

Hi
i am doing the project with ROSBridgeLib, thanks a lot for the job what you have done.
i habe read the ROSBridge_suite that can compress the JSON to binary data, is there a way doing that with the ROSBridgeLib?
One more question, what is the different between ROSBridgeLib.cs and ROSBridgeMsg.cs this two files?
Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.