Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JointState messages #8

Open
brausebart opened this issue Nov 15, 2017 · 3 comments
Open

JointState messages #8

brausebart opened this issue Nov 15, 2017 · 3 comments

Comments

@brausebart
Copy link

brausebart commented Nov 15, 2017

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

@michaeljenkin
Copy link
Owner

michaeljenkin commented Nov 16, 2017 via email

@Minimartian
Copy link

Did you find a solution to this @brausebart ? I'm also having issues with string[] and float64[] when making a jointstate message

@michaeljenkin
Copy link
Owner

michaeljenkin commented Dec 5, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants