Open brausebart opened 7 years ago
It looks suspiciously like your ToYAMLString() method is not generating a valid json string and so ROSbridge cannot parse it (as there is clearly an op field of ‘publish’
Take the json string and take it apart to see if this is the problem (you sent as an image so this is not practical for others, but it might be that the name array contains text, not strings? )
Michael
On Nov 15, 2017, at 5:43 PM, brausebart notifications@github.com wrote:
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: https://user-images.githubusercontent.com/25354745/32864129-27cb6a90-ca5e-11e7-9efe-98bb5f55038a.PNG 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\": " + "[" + System.Convert.ToBase64String(_position) + "]}" + ", {\"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
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/michaeljenkin/unityros/issues/8, or mute the thread https://github.com/notifications/unsubscribe-auth/AJy_koRJJT6kAg3cMEmyjIG-7wEh38T_ks5s22kCgaJpZM4Qfr_z.
Did you find a solution to this @brausebart ? I'm also having issues with string[] and float64[] when making a jointstate message
There is no Float msg type. You’d have to add your own. If you look at Int32 the following might work
using System.Collections; using System.Text; using SimpleJSON;
namespace ROSBridgeLib { namespace std_msgs { public class Float32Msg : ROSBridgeMsg { private float _data;
public Float32Msg(JSONNode msg) {
_data = float.Parse(msg["data”]);
}
public Float32Msg(int data) {
_data = data;
}
public static string GetMessageType() {
return “std_msgs/Float32";
}
public float GetData() {
return _data;
}
public override string ToString() {
return “Float32 [data=" + _data + "]";
}
public override string ToYAMLString() {
return "{\"data\" : " + _data + "}";
}
}
}
}
and if you drop it in the std_msgs folder, you can now talk about Float32’s.
In terms of string, there is a stringMsg, but its not very clever about escaped symbols, so a raw “ in the message is likely to be a problem.
Hope this helps
Michael
On Dec 3, 2017, at 5:57 AM, Minimartian notifications@github.com wrote:
Did you find a solution to this @brausebart https://github.com/brausebart ? I'm also having issues with string[] and float64[] when making a jointstate message
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/michaeljenkin/unityros/issues/8#issuecomment-348755956, or mute the thread https://github.com/notifications/unsubscribe-auth/AJy_kpg5WVADKb4CoK05Y0SPqD6ATR9gks5s8n6TgaJpZM4Qfr_z.
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:
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;
}`
How should I pass those string[] and double[] to ROS?
Maybe you guys could help me. Would be great. Many thanks