Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/torque_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<urcl::ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
"external_control.urp");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
20 changes: 10 additions & 10 deletions resources/external_control.urscript
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ 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)
popup("Torque control is only supported from software 10.11.0 and upwards.", error=True, blocking=True)
{% endif %}
{% else %}
popup("Torque control is only supported from software 5.23.0 and upwards.", error=True, blocking=True)
Expand Down Expand Up @@ -688,17 +688,17 @@ 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)
popup("Torque control is only supported from software 10.11.0 and upwards.", error=True, blocking=True)
{% endif %}
{% else %}
popup("Torque control is only supported from software 5.23.0 and upwards.", error=True, blocking=True)
Expand Down
Loading