Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Unity Robotics Hub pick and place for ROS2 Humble

Discussion in 'Robotics' started by Areyer, Jan 25, 2024.

  1. Areyer

    Areyer

    Joined:
    Jun 4, 2023
    Posts:
    1
    Hello everyone, is there anyone who has experience with the ros_tcp_endpoint repository version 0.7.0? I want to use it to create Digital Twin for a UR10e arm with ROS2 Humble in Unity to use for my bachelor project. I am new to ROS and could really need some guidance.
    So far I have created a URDFfile, setup Unity following the pick and place tutorial in the Unity Robotics Hub using the ros2update branch. I did not clone the project just added some separate components of the project to my workspace (adjusted messages/services, SourceDestinationpublisher).
    I am currently stuck at part 2 of the tutorial where I have to launch the server_endpoint.py script. I rewrote the core components of the part_2 launcher as follows

    the launch description:

    Code (CSharp):
    1. from launch import LaunchDescription
    2. from launch_ros.actions import Node
    3.  
    4. [code=Python]def generate_launch_description():
    5.     ld = LaunchDescription()
    6.  
    7.     server_endpoint = Node(
    8.         package="ur10e_moveit",
    9.         executable="server_endpoint.py",
    10.         name='server_endpoint',
    11.         arguments="--wait",
    12.         output="screen",
    13.         respawn=True
    14.     )
    15.  
    16.     trajectory_subscriber = Node(
    17.         package="ur10e_moveit",
    18.         executable="trajectory_subscriber.py",
    19.         name='trajectory_subscriber',
    20.         arguments="--wait",
    21.         output="screen",
    22.     )
    23.  
    24.     ld.add_action(server_endpoint)
    25.     ld.add_action(trajectory_subscriber)
    26.  
    27.     return ld
    My server_endpoint script:

    Code (CSharp):
    1. #!/usr/bin/env python3
    2.  
    3. import rclpy
    4. from rclpy.node import Node
    5.  
    6. from ros_tcp_endpoint import TcpServer
    7. from ur10e_interfaces.msg import UR10eMoveitJoints, UR10eTrajectory
    8. from ur10e_interfaces.srv import MoverService
    9.  
    10. from moveit_msgs.msg import RobotState
    11.  
    12. class ParamNode(Node):
    13.     def __init__(self):
    14.         super().__init__('TCPServer')
    15.         self.declare_parameter("/TCP_NODE_NAME",'TCPServer')      
    16.  
    17. def main(args=None):
    18.     rclpy.init(args=args)
    19.     node = ParamNode()
    20.  
    21.     # Create a TcpServer instance
    22.     tcp_server = TcpServer(node.get_parameter('/TCP_NODE_NAME').get_parameter_value().string_value)
    23.  
    24.     # Start the Server Endpoint with a ROS communication objects dictionary for routing messages
    25.     tcp_server.start({
    26.         'SourceDestination_input': tcp_server.create_publisher(UR10eMoveitJoints,'SourceDestination_input',10),
    27.         'UR10eTrajectory': tcp_server.create_subscription(UR10eTrajectory,'UR10eTrajectory',tcp_server,10),
    28.         'ur10e_moveit': tcp_server.create_service(MoverService,'ur10e_moveit', tcp_server),
    29.         'RobotState': tcp_server.create_subscription(RobotState,'RobotState', tcp_server, 10)
    30.     })
    31.     try:
    32.         rclpy.spin(node)
    33.     except KeyboardInterrupt:
    34.         print(f'{node} stopped cleanly')
    35.     finally:
    36.         node.destroy_node()
    37.         rclpy.shutdown()
    38.  
    39. if __name__ == "__main__":
    40.     main()
    and trajectory_subscriber script:


    Code (CSharp):
    1. #!/usr/bin/env python3
    2. """
    3.    Subscribes to SourceDestination topic.
    4.    Uses MoveIt to compute a trajectory from the target to the destination.
    5.    Trajectory is then published to PickAndPlaceTrajectory topic.
    6. """
    7. import rclpy
    8. from rclpy.node import Node
    9. from std_msgs.msg import String
    10. from ur10e_interfaces.msg import UR10eMoveitJoints, UR10eTrajectory
    11. from moveit_msgs.msg import RobotTrajectory
    12.  
    13.  
    14. class Trajectory_Subscriber(Node):
    15.  
    16.     def __init__(self):
    17.         super().__init__("trajectory_subscriber")
    18.         self.subscription = self.create_subscription(
    19.             String,
    20.             'SourceDestination_input',
    21.             UR10eMoveitJoints,
    22.             self.callback,
    23.             10
    24.         )
    25.         self.subscription   # prevent unused variable warning
    26.  
    27.     def callback(self, data):
    28.         self.get_logger().info("I heard:\n%s", data)
    29.  
    30. def main(args=None):
    31.     rclpy.init(args=args)
    32.     node = Trajectory_Subscriber()
    33.     subscription = node
    34.     # spin() simply keeps python from exiting until this node is stopped
    35.     rclpy.spin(node)
    36.     rclpy.shutdown()
    37.  
    38. if __name__ == '__main__':
    39.     main()
    I would appreciate it if anyone could help me!
     
  2. Miftahur_92

    Miftahur_92

    Joined:
    May 24, 2023
    Posts:
    1
    Hi Areyar, I am trying to use ABB manipulator on ROS2 humble and Unity. Were you successful in implementing it?