Universal Robots Client Library
repository·master·Indexed 41 days ago
https://github.com/universalrobots/universal_robots_client_libraryA C++ library providing access to Universal Robots interfaces, serving as the foundation for ROS and ROS 2 drivers. It enables interaction with UR robotic manipulators via RTDE, Dashboard, and primary/secondary interfaces. Key components include the DashboardClient for robot management, the InstructionExecutor for motion commands (MoveJ, MoveL, MoveP, MoveC), and the RTDEClient for high-frequency data exchange. Supports CB3-Series (PolyScope 3.14.3+), e-Series (PolyScope 5.9.4+), and PolyScope X (10.7.0+).
What's inside Universal Robots Client Library
- The library provides low-level communication protocols for interacting with Universal Robots. It is composed of several standalone modules that allow developers to access specific subsets of functionality. Depending on your use case, you may interact with different client interfaces or specialized modules.
Overview of Library Interfaces
masterThe library provides several ways to interact with Universal Robots:
- RTDE Interface: Fully supported via the
RTDEClient. This is the primary method used by the ROS/ROS 2 drivers. - Dashboard Interface: Access the Dashboard server directly through helper functions.
- Custom Motion Streaming: Supports data streaming through custom sockets for motion command streaming.
- Primary/Secondary Interface: Limited support. The
PrimaryClientdoes not support all features, and package parsing is not implemented for most packages. You can usecomm::URStreamto open a connection and send data, or use the producer/consumer pipeline (seeexamples/primary_pipeline.cpp).
- RTDE Interface: Fully supported via the
Configure Spline Velocities and Accelerations
masterWhen using
SPLINEtrajectory points, you can achieve higher precision for velocities and accelerations using theMULT_VEL_ACCmultiplier (1e-8 resolution).Requirements for High Precision:
- The robot's control script must define the matching multiplier using the
{{VEL_ACC_REPLACE}}placeholder. - If this placeholder is not present in the user-supplied script, the library falls back to using
MULT_JOINTSTATEfor encoding spline velocities and accelerations.
Warning: Using the coarser
MULT_JOINTSTATEscaling for spline velocities/accelerations can cause quantized, jagged acceleration profiles, which may trigger controller faults. Values exceeding the maximum magnitude (~21.47 rad/s or rad/s²) are rejected by the library.- The robot's control script must define the matching multiplier using the
Requirements for using Instruction Executor
masterTo use theInstructionExecutor, you must provide aur_driverobject. The executor relies on both thetrajectory_point_interfaceand thereverse_interfaceto communicate motion instructions to the robot.How the Producer / Consumer pipeline architecture works
masterThe library uses a producer/consumer architecture to handle data streams from the robot.
- Producer: Reads data from a stream, parses that data, and places it into a queue.
- Consumer: Reads data from the queue and performs its intended task (e.g., logging, processing, or executing commands).
- Pipeline: Orchestrates the connection between a producer and a consumer. You can optionally provide an
INotifierto handle pipeline start and stop events.
Use the Script Command Interface to send commands to a running URScript
masterThe
ScriptCommandInterfaceallows you to send predefined commands to a Universal Robot while a URScript (such asexternal_control.urscript) is actively running and connected to the robot.To use this interface effectively, you must ensure that the robot is running a script that establishes a connection to the
ScriptCommandInterface. In a typical driver setup, theUrDriverforwards calls from theScriptCommandInterfaceto the robot.Because the script command connection is part of the larger external control loop, you must maintain the connection by sending regular keepalive signals (often handled by the driver's control loop) to prevent the script from terminating.
// Example of accessing the interface via the driver g_my_robot->getUrDriver()->zeroFTSensor();Use Direct Torque Control mode
masterDirect torque control mode (available since PolyScope 5.23.0 / 10.10.0) allows commanding joint torques directly to the robot using control mode
8(TORQUE).Key details:
- Gravity Compensation: Target torques are provided after gravity compensation. A vector of zeros will maintain the current position if the payload is correctly known to the controller.
- Safety Warning: This is a very low-level interface. High torques in free space can cause rapid, unexpected movement that may trigger safety faults (joint velocity or TCP speed violations).
Use the ReverseInterface for motion command streaming
masterThe
ReverseInterfaceclass opens a TCP port to implement a custom protocol between the robot and the control PC. It is primarily used for high-frequency motion command streaming, such as sending joint positions or velocities.To use
ReverseInterfacein an application, you must ensure a corresponding URScript is running on the robot to interpret the incoming commands. A reference implementation can be found in theexternal_control.urscriptresource.Depending on the selected control mode, you use different methods to send data:
write(): Used forSERVOJ,SPEEDJ,SPEEDL,POSE, andTORQUEmodes.writeTrajectoryControlMessage(): Used forFORWARD(trajectory interpolation) mode.writeFreedriveControlMessage(): Used forFREEDRIVEmode.
How the Trajectory Point Interface works
masterThe
TrajectoryPointInterfaceis used to transfer trajectory points from an external control PC to the robot for execution. It is designed to be used alongside theReverseInterfaceduring trajectory forwarding.Workflow:
- The
TrajectoryPointInterfaceforwards trajectory points to the robot. - Execution is triggered by sending a start command via the
ReverseInterface. - Once execution completes (success, failure, or external cancellation), the robot sends a response back to the control PC via the trajectory socket.
Important Constraints:
- The interface simply forwards points; the robot executes them using standard URScript functions like
movejormovel. - All parameters and restrictions of those URScript functions apply. For example, if a segment duration (time) > 0 is provided, velocity and acceleration parameters will be ignored.
- The
Create a read-only RTDEClient
masterWhile multiple clients can connect to a robot, only one client is permitted to write data. To create a client that only reads data, initialize the
RTDEClientwith an empty input recipe. This can be done by passing an empty list of strings or an empty filename string.Note that when using a read-only client, all attempts to use the
RTDEWriterwill returnfalse.// Create with an empty input recipe (read-only) rtde_interface::RTDEClient my_client(ROBOT_IP, notifier, OUTPUT_RECIPE, {}); // Alternatively, using an empty filename // rtde_interface::RTDEClient my_client(ROBOT_IP, notifier, OUTPUT_RECIPE_FILE, ""); my_client.init(); auto data_pkg = std::make_unique<rtde_interface::DataPackage>(my_client->getOutputRecipe()); my_client.start(); while (true) { if (my_client.getDataPackage(data_pkg, READ_TIMEOUT)) { std::cout << data_pkg->toString() << std::endl; } }Producer / Consumer Architecture
masterCommunication with the primary/secondary and RTDE interfaces follows a producer/consumer pattern:
- Producer: Reads data from the socket, parses the contents, and stores parsed packages into a pipeline queue.
- Consumer: You can implement custom consumers to process the packages provided by the producer.
An example of a consumer implementation can be found in
include/ur_client_library/comm/shell_consumer.h.Real-Time Scheduling for RTDE
masterTo ensure reliable operation and prevent missing RTDE messages, it is critical to use real-time scheduling:
- RTDE Receive Thread: This thread is automatically scheduled with real-time priority if the system allows. If it fails, an error is raised at startup.
- Application Thread: The main thread calling
getDataPackage()must be manually scheduled with real-time priority by your application.
Refer to
doc/real_time.rstfor detailed setup instructions.