Skip to content

JointState messages #8

@brausebart

Description

@brausebart

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions