ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS2 Unity subscribe to joint_states

asked 2023-06-26 12:32:52 -0600

Areyer gravatar image

I am currently trying to simulate the UR10e in Unity to then remote control it in VR. So far I have managed to control the robot locally by using the universal robots ros2 driver for humble. But I have problems with unity. I was following the guide of the unity-robotics-hub, transfer the xarco files to an urdf. For this I added the ur_description to the ur driver and generated the urdf file with following command

ros2 run xacro xacro $(ros2 pkg prefix ur_description --share)/urdf/ur.urdf.xacro \
name:=ur10e \
joint_limit_params:=$(ros2 pkg prefix ur_description --share)/config/ur10e/joint_limits.yaml \
physical_params:=$(ros2 pkg prefix ur_description --share)/config/ur10e/physical_parameters.yaml \
kinematics_params:=$(ros2 pkg prefix ur_description --share)/config/ur10e/default_kinematics.yaml \
visual_params:=$(ros2 pkg prefix ur_description --share)/config/ur10e/visual_parameters.yaml

after that I have placed the generated file in the Asset folder in unity and used the urdf-importer to integrate my model in the project.

Then I created a new packag in the ur_driver

ros2 pkg create --build-type ament_python unity_messages

created a Subscriber Node in the python maiin file and tried to get the message information of the robot states with the following script

import rclpy
from rclpy.node import Node
from sensor_msgs.msg import JointState  

class URDriverSubscriber(Node):
    def __init__(self):
        super().__init__('ur_driver_subscriber')
        self.subscription = self.create_subscription(
            JointState,                   
            'joint_states',               
            self.callback_function,       
            10                           
        )
        self.subscription  

    def callback_function(self, msg):
        joint_positions = msg.position
        self.get_logger().info(f'Received joint positions: {joint_positions}')

def main(args=None):
    rclpy.init(args=args)
    ur_driver_subscriber = URDriverSubscriber()
    rclpy.spin(ur_driver_subscriber)
    ur_driver_subscriber.destroy_node()
    rclpy.shutdown()

if __name__ == '__main__':
    main()

made according adjustments in the newly created package.xml file where I have added rclpy and sensor_msgs. In the setup.py I have added 'unity_messages = unity_messages.main:main' into the console_scripts. Finally after executing the code with ros2 run unity_messages unity_messages I get the error that URDriverSubscriber does not exist.

Could anyone please tell me what I have done wrong? My end goal is to simulate the roboter in unity to then be able to remote control it over VR.

I am working on Ubuntu 22.04, installed the real time kernel 5.15.107-rt62 and use ros2 humble.

Thanks in advance for your help!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-27 05:39:01 -0600

Areyer gravatar image

Alright I found the problem. In my code I accidentally had the main inside my URDriverSubscriber class....

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2023-06-26 12:32:52 -0600

Seen: 164 times

Last updated: Jun 27