diff --git a/README.md b/README.md index 99cabab7..f54f203d 100644 --- a/README.md +++ b/README.md @@ -11,20 +11,8 @@ drivers. --- > [!IMPORTANT] -> The **torque_control** branch is a **beta feature**. At the current time, you will need to -> participate in the public beta program at -> [https://ur.centercode.com/key/PolyScope5Beta](https://ur.centercode.com/key/PolyScope5Beta) to -> use it. It will not work with any released robot software version. At a later time this will -> require a certain robot software version to work and the new features will not work with older -> software versions. However, old functionality will still be working with older robot software as -> noted in the version requirements below. -> -> This being a beta feature, the API is not to be considered stable. Anything developed on this -> branch might be changing in a breaking way until it is merged into the master branch. -> -> Also, please keep the beta status in mind when operating the robot. Parts of the software -> involved in the beta-feature might not be tested to the usual extent and might show unexpected -> behavior in edge cases. +> This branch adds torque_control to the ur_client_library. PolyScope version 5.23.0 / 10.11.0 will +> be required to run this on a robot. A simulated robot doesn't act on direct torque commands. > > Documentation for the new features may also be missing initially. This will be added before > merging things to the master branch. diff --git a/examples/torque_control.cpp b/examples/torque_control.cpp index ae885b0b..f8c789e9 100644 --- a/examples/torque_control.cpp +++ b/examples/torque_control.cpp @@ -54,6 +54,13 @@ int main(int argc, char* argv[]) robot_ip = std::string(argv[1]); } + // Parse how many seconds to run + auto second_to_run = std::chrono::seconds(0); + if (argc > 2) + { + second_to_run = std::chrono::seconds(std::stoi(argv[2])); + } + bool headless_mode = true; g_my_robot = std::make_unique(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode, "external_control.urp"); @@ -89,6 +96,7 @@ int main(int argc, char* argv[]) // otherwise we will get pipeline overflows. Therefor, do this directly before starting your main // loop. g_my_robot->getUrDriver()->startRTDECommunication(); + auto start_time = std::chrono::system_clock::now(); while (!(passed_positive_part && passed_negative_part)) { // Read latest RTDE package. This will block for a hard-coded timeout (see UrDriver), so the @@ -140,6 +148,12 @@ int main(int argc, char* argv[]) return 1; } URCL_LOG_DEBUG("data_pkg:\n%s", data_pkg->toString().c_str()); + if (second_to_run.count() > 0 && (std::chrono::system_clock::now() - start_time) > second_to_run) + { + URCL_LOG_WARN("Time limit reached, stopping movement. This is expected on a simualted robot, as it doesn't move " + "to torque commands."); + break; + } } g_my_robot->getUrDriver()->stopControl(); URCL_LOG_INFO("Movement done"); diff --git a/resources/external_control.urscript b/resources/external_control.urscript index 7b56390c..0dfffbe3 100644 --- a/resources/external_control.urscript +++ b/resources/external_control.urscript @@ -270,11 +270,11 @@ thread torqueThread(): textmsg("ExternalControl: Starting torque thread") while control_mode == MODE_TORQUE: torque = cmd_torque - {% if ROBOT_SOFTWARE_VERSION >= v5.22.0 %} # ToDo: Increase to 5.23.0 once released + {% if ROBOT_SOFTWARE_VERSION >= v5.23.0 %} {% if ROBOT_SOFTWARE_VERSION < v6.0.0 %} - torque_command(torque, friction_comp=friction_compensation_enabled) - {% elif ROBOT_SOFTWARE_VERSION >= v10.10.0 %} - torque_command(torque, friction_comp=friction_compensation_enabled) + direct_torque(torque, friction_comp=friction_compensation_enabled) + {% elif ROBOT_SOFTWARE_VERSION >= v10.11.0 %} + direct_torque(torque, friction_comp=friction_compensation_enabled) {% else %} popup("Torque control is only supported from software 10.10.0 and upwards.", error=True, blocking=True) {% endif %} @@ -688,15 +688,15 @@ end thread PDControlThread(): while control_mode == MODE_PD_CONTROLLER_JOINT or control_mode == MODE_PD_CONTROLLER_TASK: local q_err = cmd_servo_q - get_actual_joint_positions() - {% if ROBOT_SOFTWARE_VERSION >= v5.22.0 %} # ToDo: Increase to 5.23.0 once released + {% if ROBOT_SOFTWARE_VERSION >= v5.23.0 %} {% if ROBOT_SOFTWARE_VERSION < v6.0.0 %} local tau = pd_controller_gains.kp * q_err - pd_controller_gains.kd * get_actual_joint_speeds() tau = clamp_array(tau, max_joint_torques) - torque_command(tau, friction_comp=friction_compensation_enabled) - {% elif ROBOT_SOFTWARE_VERSION >= v10.10.0 %} + direct_torque(tau, friction_comp=friction_compensation_enabled) + {% elif ROBOT_SOFTWARE_VERSION >= v10.11.0 %} local tau = pd_controller_gains.kp * q_err - pd_controller_gains.kd * get_actual_joint_speeds() tau = clamp_array(tau, max_joint_torques) - torque_command(tau, friction_comp=friction_compensation_enabled) + direct_torque(tau, friction_comp=friction_compensation_enabled) {% else %} popup("Torque control is only supported from software 10.10.0 and upwards.", error=True, blocking=True) {% endif %}