Visualizing cobot controlled by python

I am controlling UR5e (URsim in VMWare) with python code on a windows machine. I have ROS2 Humble installed on WSL2 but when I run the ROS2 code while my code is connected to the robot, rviz launches with errors below. If I end my script, then rviz loads the “RobotModel” and everything works.

Is there a way to have visualize the cobot in rviz while I’m controlling it via python?

RobotModel not working on RViz

Code and Error in WSL2 terminal

ros2 launch ur_robot_driver ur_control.launch.py ur_type:=ur5 robot_ip:=192.168.174.129

[INFO] [launch]: All log files can be found below /home/glitchy/.ros/log/2025-04-04-09-21-38-902307-8J9HB54-1043
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [dashboard_client-2]: process started with pid [1053]
[INFO] [controller_stopper_node-3]: process started with pid [1055]
[INFO] [ur_ros2_control_node-1]: process started with pid [1051]
[INFO] [urscript_interface-4]: process started with pid [1057]
[INFO] [robot_state_publisher-5]: process started with pid [1059]
[INFO] [rviz2-6]: process started with pid [1061]
[INFO] [spawner-7]: process started with pid [1063]
[INFO] [spawner-8]: process started with pid [1065]
[INFO] [spawner-9]: process started with pid [1067]
[dashboard_client-2] [INFO] [1743729699.418256889] [UR_Client_Library:]: Connected: Universal Robots Dashboard Server
[dashboard_client-2]
[controller_stopper_node-3] [INFO] [1743729699.423580284] [Controller stopper]: Waiting for switch controller service to come up on controller_manager/switch_controller
[robot_state_publisher-5] [INFO] [1743729699.432849874] [robot_state_publisher]: got segment base
[robot_state_publisher-5] [INFO] [1743729699.433102139] [robot_state_publisher]: got segment base_link
[robot_state_publisher-5] [INFO] [1743729699.433121431] [robot_state_publisher]: got segment base_link_inertia
[robot_state_publisher-5] [INFO] [1743729699.433130620] [robot_state_publisher]: got segment flange
[robot_state_publisher-5] [INFO] [1743729699.433138126] [robot_state_publisher]: got segment forearm_link
[robot_state_publisher-5] [INFO] [1743729699.433145290] [robot_state_publisher]: got segment ft_frame
[robot_state_publisher-5] [INFO] [1743729699.433152211] [robot_state_publisher]: got segment shoulder_link
[robot_state_publisher-5] [INFO] [1743729699.433159036] [robot_state_publisher]: got segment tool0
[robot_state_publisher-5] [INFO] [1743729699.433165606] [robot_state_publisher]: got segment upper_arm_link
[robot_state_publisher-5] [INFO] [1743729699.433172195] [robot_state_publisher]: got segment world
[robot_state_publisher-5] [INFO] [1743729699.433178660] [robot_state_publisher]: got segment wrist_1_link
[robot_state_publisher-5] [INFO] [1743729699.433185335] [robot_state_publisher]: got segment wrist_2_link
[robot_state_publisher-5] [INFO] [1743729699.433192020] [robot_state_publisher]: got segment wrist_3_link
[ur_ros2_control_node-1] [WARN] [1743729699.441302713] [controller_manager]: [Deprecated] Passing the robot description parameter directly to the control_manager node is deprecated. Use '~/robot_description' topic from 'robot_state_publisher' instead.
[ur_ros2_control_node-1] text not specified in the tf_prefix tag
[ur_ros2_control_node-1] [INFO] [1743729699.441887876] [resource_manager]: Loading hardware 'ur5'
[ur_ros2_control_node-1] [INFO] [1743729699.448870554] [resource_manager]: Initialize hardware 'ur5'
[ur_ros2_control_node-1] [INFO] [1743729699.449158776] [resource_manager]: Successful initialization of hardware 'ur5'
[ur_ros2_control_node-1] [INFO] [1743729699.449998339] [resource_manager]: 'configure' hardware 'ur5'
[ur_ros2_control_node-1] [INFO] [1743729699.450132861] [URPositionHardwareInterface]: Starting ...please wait...
[ur_ros2_control_node-1] [INFO] [1743729699.450178375] [URPositionHardwareInterface]: Initializing driver...
[ur_ros2_control_node-1] [WARN] [1743729699.457569553] [UR_Client_Library:]: Your system/user seems not to be setup for FIFO scheduling. We recommend using a lowlatency kernel with FIFO scheduling. See https://github.com/UniversalRobots/Universal_Robots_ROS_Driver/blob/master/ur_robot_driver/doc/real_time.md for details.
[ur_ros2_control_node-1] [INFO] [1743729699.460404508] [UR_Client_Library:]: Negotiated RTDE protocol version to 2.
[ur_ros2_control_node-1] [INFO] [1743729699.462259235] [UR_Client_Library:]: Setting up RTDE communication with frequency 500.000000
[rviz2-6] QStandardPaths: wrong permissions on runtime directory /run/user/1000/, 0755 instead of 0700
[spawner-9] [INFO] [1743729699.858582656] [spawner_forward_position_controller]: waiting for service /controller_manager/list_controllers to become available...
[spawner-7] [INFO] [1743729699.860223281] [spawner_scaled_joint_trajectory_controller]: waiting for service /controller_manager/list_controllers to become available...
[spawner-8] [INFO] [1743729699.862556248] [spawner_joint_state_broadcaster]: waiting for service /controller_manager/list_controllers to become available...
[rviz2-6] [INFO] [1743729700.105275332] [rviz2]: Stereo is NOT SUPPORTED
[rviz2-6] [INFO] [1743729700.105665142] [rviz2]: OpenGl version: 4.5 (GLSL 4.5)
[rviz2-6] [INFO] [1743729700.176682224] [rviz2]: Stereo is NOT SUPPORTED
[ur_ros2_control_node-1] [FATAL] [1743729700.517374403] [URPositionHardwareInterface]: Variable 'standard_digital_output_mask' is currently controlled by another RTDE client. The input recipe can't be used as configured
[ur_ros2_control_node-1] [INFO] [1743729700.517466238] [resource_manager]: Failed to 'configure' hardware 'ur5'
[ur_ros2_control_node-1] terminate called after throwing an instance of 'std::runtime_error'
[ur_ros2_control_node-1]   what():  Failed to set the initial state of the component : ur5 to active
[ur_ros2_control_node-1] Stack trace (most recent call last):
[ur_ros2_control_node-1] #13   Object "", at 0xffffffffffffffff, in
[ur_ros2_control_node-1] #12   Object "/opt/ros/humble/lib/ur_robot_driver/ur_ros2_control_node", at 0x55a5fb39bbc4, in
[ur_ros2_control_node-1] #11   Object "/usr/lib/x86_64-linux-gnu/libc.so.6", at 0x7f4aabd0fe3f, in __libc_start_main
[ur_ros2_control_node-1] #10   Object "/usr/lib/x86_64-linux-gnu/libc.so.6", at 0x7f4aabd0fd8f, in
[ur_ros2_control_node-1] #9    Object "/opt/ros/humble/lib/ur_robot_driver/ur_ros2_control_node", at 0x55a5fb39b853, in
[ur_ros2_control_node-1] #8    Object "/opt/ros/humble/lib/libcontroller_manager.so", at 0x7f4aac42811b, in controller_manager::ControllerManager::ControllerManager(std::shared_ptr<rclcpp::Executor>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::NodeOptions const&)
[ur_ros2_control_node-1] #7    Object "/opt/ros/humble/lib/libcontroller_manager.so", at 0x7f4aac40c972, in
[ur_ros2_control_node-1] #6    Object "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30", at 0x7f4aabfdd4d7, in __cxa_throw
[ur_ros2_control_node-1] #5    Object "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30", at 0x7f4aabfdd276, in std::terminate()
[ur_ros2_control_node-1] #4    Object "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30", at 0x7f4aabfdd20b, in
[ur_ros2_control_node-1] #3    Object "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30", at 0x7f4aabfd1b9d, in
[ur_ros2_control_node-1] #2    Object "/usr/lib/x86_64-linux-gnu/libc.so.6", at 0x7f4aabd0e7f2, in abort
[ur_ros2_control_node-1] #1    Object "/usr/lib/x86_64-linux-gnu/libc.so.6", at 0x7f4aabd28475, in raise
[ur_ros2_control_node-1] #0    Object "/usr/lib/x86_64-linux-gnu/libc.so.6", at 0x7f4aabd7c9fc, in pthread_kill
[ur_ros2_control_node-1] Aborted (Signal sent by tkill() 1051 1000)
[ERROR] [ur_ros2_control_node-1]: process has died [pid 1051, exit code -6, cmd '/opt/ros/humble/lib/ur_robot_driver/ur_ros2_control_node --ros-args --params-file /tmp/launch_params_a7qwvbep --params-file /opt/ros/humble/share/ur_robot_driver/config/ur5_update_rate.yaml --params-file /tmp/launch_params_5zu9ojpo'].