Skip to content

Add set_target_payload support to ScriptCommandInterface#515

Open
srvald wants to merge 7 commits into
UniversalRobots:masterfrom
srvald:set_target_payload
Open

Add set_target_payload support to ScriptCommandInterface#515
srvald wants to merge 7 commits into
UniversalRobots:masterfrom
srvald:set_target_payload

Conversation

@srvald

@srvald srvald commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Description

Adds support for the URScript set_target_payload() command through the
ScriptCommandInterface, allowing users to set the payload mass, center of
gravity, inertia matrix, and transition time.

This follows the same pattern as the existing setPayload() implementation.

Changes

  • include/ur_client_library/control/script_command_interface.h: Added
    setTargetPayload() declaration and the SET_TARGET_PAYLOAD = 12 enum value
    to ScriptCommand.
  • include/ur_client_library/ur/ur_driver.h: Added setTargetPayload()
    declaration to UrDriver.
  • src/control/script_command_interface.cpp: Implemented
    ScriptCommandInterface::setTargetPayload(), encoding mass, CoG (3 values),
    inertia matrix (6 values), and transition time into the binary message.
  • src/ur/ur_driver.cpp: Implemented UrDriver::setTargetPayload().
  • resources/external_control.urscript: Added SET_TARGET_PAYLOAD = 12
    constant and the corresponding elif branch in the script_commands thread
    to call set_target_payload().
  • tests/test_script_command_interface.cpp: Added
    test_set_target_payload unit test verifying correct encoding of all fields
    (mass, CoG, inertia, transition time) and that unused message slots are zero.

Message layout for SET_TARGET_PAYLOAD

Index Meaning
0 Command (12)
1 Mass (kg)
2–4 Center of gravity (m)
5–10 Inertia matrix elements (kg·m²)
11 Transition time (s)
12–27 Unused (zero-padded)

Notes

  • transition_time defaults to 0.0 seconds (no transition).

Related issues

UniversalRobots/Universal_Robots_ROS2_Driver#1711

Related PR (ur_ros2_driver): UniversalRobots/Universal_Robots_ROS2_Driver#1808

Tasks

  • Implement the feature
  • Make documentation
  • Make Unit test
  • Make example
  • Test on real hardware

Note

Medium Risk
Changes active payload modeling on the robot (mass, inertia, transition), which affects motion and force behavior; version fallbacks omit inertia on older PolyScope.

Overview
Adds setTargetPayload end-to-end so clients can set mass, CoG, inertia, and transition time via the script command socket (command 12), mirroring existing setPayload.

ScriptCommandInterface and UrDriver expose the new API; the driver uses the binary interface when connected, otherwise emits set_target_payload() (PolyScope ≥ 5.10) or falls back to set_payload() with a warning. external_control.urscript decodes the message and calls set_target_payload() on supported versions. MULT_TIME moves to ReverseInterface (shared with script command encoding); docs and the script-command example are updated. Unit/integration tests cover wire format and fallback script paths.

Reviewed by Cursor Bugbot for commit 8e57d54. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.70%. Comparing base (c85ffa8) to head (8e57d54).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/ur/ur_driver.cpp 94.11% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #515      +/-   ##
==========================================
- Coverage   77.66%   76.70%   -0.97%     
==========================================
  Files         115      116       +1     
  Lines        6480     6649     +169     
  Branches     2898     2939      +41     
==========================================
+ Hits         5033     5100      +67     
- Misses       1081     1210     +129     
+ Partials      366      339      -27     
Flag Coverage Δ
check_version_ur10-3.15.8 11.51% <0.00%> (-0.02%) ⬇️
check_version_ur10e-10.11.0 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur10e-5.15.2 11.55% <0.00%> (-0.16%) ⬇️
check_version_ur12e-10.12.1 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur12e-5.25.1 11.51% <0.00%> (-0.76%) ⬇️
check_version_ur15-10.12.1 11.36% <0.00%> (-0.11%) ⬇️
check_version_ur15-5.25.1 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur16e-10.12.1 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur16e-5.25.1 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur18-10.12.1 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur18-5.25.1 11.36% <0.00%> (-0.16%) ⬇️
check_version_ur20-10.12.1 11.36% <0.00%> (-0.21%) ⬇️
check_version_ur20-5.25.1 11.31% <0.00%> (-0.35%) ⬇️
check_version_ur3-3.14.3 11.51% <0.00%> (+0.66%) ⬆️
check_version_ur30-10.12.1 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur30-5.25.1 11.36% <0.00%> (-0.11%) ⬇️
check_version_ur3e-10.11.0 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur3e-5.9.4 11.51% <0.00%> (+0.03%) ⬆️
check_version_ur5-3.15.8 11.55% <0.00%> (+0.08%) ⬆️
check_version_ur5e-10.11.0 11.36% <0.00%> (-0.16%) ⬇️
check_version_ur5e-5.12.8 11.31% <0.00%> (-0.40%) ⬇️
check_version_ur7e-10.11.0 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur7e-5.22.2 11.31% <0.00%> (-0.21%) ⬇️
check_version_ur8long-10.12.1 11.31% <0.00%> (-0.16%) ⬇️
check_version_ur8long-5.25.1 11.31% <0.00%> (-0.21%) ⬇️
python_scripts 75.90% <ø> (?)
start_ursim 83.69% <ø> (+2.30%) ⬆️
ur5-3.14.3 74.38% <84.21%> (+1.15%) ⬆️
ur5e-10.11.0 ?
ur5e-10.12.0 ?
ur5e-10.7.0 68.79% <86.84%> (+1.42%) ⬆️
ur5e-5.9.4 75.19% <84.21%> (+1.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@urfeex urfeex force-pushed the set_target_payload branch from 67d123d to 2d1074a Compare June 8, 2026 07:29
Comment thread resources/external_control.urscript Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 2cfc96c. Configure here.

Comment thread src/ur/ur_driver.cpp

@urfeex urfeex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking clean! I'm only wondering whether we should move the MULT_TIME up to ReverseInterface and re-use that for the transition time. I think, we should do that.

Comment thread resources/external_control.urscript Outdated
Comment thread src/control/script_command_interface.cpp Outdated
Comment thread tests/test_script_command_interface.cpp Outdated
@srvald srvald requested a review from urfeex June 10, 2026 08:06

@urfeex urfeex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add documentation updates to script_command_interface.rst and add a command to the script_command_example,

@srvald srvald requested a review from urfeex June 10, 2026 08:55
@srvald

srvald commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@urfeex Should we put somewhere that setPayload is deprecated?

@urfeex

urfeex commented Jun 10, 2026

Copy link
Copy Markdown
Member

@urfeex Should we put somewhere that setPayload is deprecated?

I would say let's not add a compile time deprecation. We could print a warning when setPayload is used on a robot with software newer than or equal to 5.10/3.15 (which covers most of our supported versions, anyway). @urrsk what is your opinion on this?

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

Successfully merging this pull request may close these issues.

2 participants