joint state publisher

Hello everyone,

my question is how can i create a joint state subscriber or publisher like ros# script ? ı want to control a robot arm via rviz with moviet.

ı upload a photo of ros# script for subs to joints.

thanks.7659658--955771--joint_publisher_script.jpg

Hi, sorry for the late reply. It sounds like you want to do something similar to our Pick and Place demo: https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/pick_and_place/README.md

Specifically, here's a script that makes the robot perform the trajectory sent by MoveIt: https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/d324209baa4ed58f883d93c38b30c942e9b63fbf/tutorials/pick_and_place/Scripts/TrajectoryPlanner.cs#L171

Hope that helps!

Hi, I am also working with the same robot.
I have created this. It works perfectly.

using UnityEngine;
using Unity.Robotics.ROSTCPConnector;
using SensorUnity = RosMessageTypes.Sensor.JointStateMsg;
using System.Collections;

public class JointStateSub : MonoBehaviour
{
    [SerializeField] private string rosTopic = "joint_states";
    [SerializeField] private ROSConnection ROS;
    [SerializeField] private ArticulationBody[] robotJoints = new ArticulationBody[9];
    // Start is called before the first frame update
    void Start()
    {
        ROS = ROSConnection.GetOrCreateInstance();
        ROS.Subscribe<SensorUnity>(rosTopic, GetJointPositions);
    }

    private void GetJointPositions(SensorUnity sensorMsg)
    {
        StartCoroutine(SetJointValues(sensorMsg));
    }
    IEnumerator SetJointValues(SensorUnity message)
    {
        for (int i = 0; i < message.name.Length; i++)
        {
            var joint1XDrive = robotJoints[i].xDrive;
            joint1XDrive.target = (float)(message.position[i]) * Mathf.Rad2Deg;
            robotJoints[i].xDrive = joint1XDrive;
            Debug.Log(joint1XDrive.target);
        }

        yield return new WaitForSeconds(0.5f);
    }

    public void UnSub()
    {
        ROS.Unsubscribe(rosTopic);
    }
}
1 Like

@medinafb01 Do you know how to use joint velocity controller?

At present, I have seen unity only has position controller.
If anyone knows how to setup joint velocity controller than please let me know.

@vermahrithik10 Hello,
No, I have not used it.

But I know it is possible to build it.
Here are some links that may help you:

How to create your own controller - Unity Robotics.
https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/urdf_importer/urdf_appendix.md#guide-to-write-your-own-controller

How a velocity controller works
https://modernrobotics.northwestern.edu/nu-gm-book-resource/11-3-motion-control-with-velocity-inputs-part-1-of-3/#department

One question, are you still using ROS# with the panda robot?

@medinafb01 @vermahrithik10 Hello, you two. You basically did the same work i'm doing now and maybe one of you can help me.
First of all, @medinafb01 thanks for your script, it works really well and i haven't found anyone who did the same thing besides you. I just have one question. Do you know any way to specify how often the joint states position gets updated in unity or something like that?
For better context: i'm simulating the panda robot on the hololens 2 and i try to use the robotics hub. Since there is really no good documentation, i searched ages for a way to subscribe to the jointstates topic. Then i found your script. I have to say i don't understand it completly, for example: does the Subscribe function you call in Start reguarly call the GetJointPositions function or just once? Before i found your script i thought, that i probably have to update the joint position reguarly in the update function or something like that.
But back to my main problem. Your Script works fine, but on the hololens, the robots movement looks like it is only moving with 15-20 fps, like really jittery. I don't know how to fix that, in Ros i already specified a 60 fps rate for sending the joint states. Do you have any idea how to fix that? Thanks in advance and if you need any more information, do not hesitate to ask!