Content-Length: 200702 | pFad | http://github.com/RobotecAI/ros2-for-unity/issues/111

26 Can you provide a listener example for joint_states? · Issue #111 · RobotecAI/ros2-for-unity · GitHub
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

Can you provide a listener example for joint_states? #111

Open
terkaa opened this issue Aug 24, 2024 · 1 comment
Open

Can you provide a listener example for joint_states? #111

terkaa opened this issue Aug 24, 2024 · 1 comment

Comments

@terkaa
Copy link

terkaa commented Aug 24, 2024

Hi,

Could you please provide an example on how to listen the topic /joint_states and print individual joint positions in Unity Debugger.log?

Tero

@terkaa
Copy link
Author

terkaa commented Aug 25, 2024

`using System;
using UnityEngine;
using sensor_msgs.msg;

namespace ROS2
{

public class JointStateListener : MonoBehaviour
{

private ROS2UnityComponent ros2Unity;
private ROS2Node ros2Node;
private ISubscription<JointState> jointStateSub;

void Start()
{
    // Find the ROS2UnityComponent in the scene
    ros2Unity = GetComponent<ROS2UnityComponent>();
}

void Update()
{
     if (ros2Node == null && ros2Unity.Ok())
    {
        // Create a node
        ros2Node = ros2Unity.CreateNode("joint_state_listener_node");

        // Subscribe to the /joint_states topic
        jointStateSub = ros2Node.CreateSubscription<JointState>(
            "/joint_states",
            msg =>
            {
                for (int i = 0; i < msg.Position.Length; i++)
                {
                    Debug.Log($"Joint {i}: Position {msg.Position[i]}");
                }
            });
    }
}

}
}`

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

1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RobotecAI/ros2-for-unity/issues/111

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy