Skip to content

Commit

Permalink
Use diff between commands instead of distance from current joint pose…
Browse files Browse the repository at this point in the history
… to target pose
  • Loading branch information
fmauch committed Jun 27, 2024
1 parent 66f52b6 commit 92ee816
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions resources/external_control.urscript
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ thread_script_commands = 0
#
# @returns bool true if the target is reachable within the robot's speed limits, false otherwise
###
def targetWithinLimits(target, time):
def targetWithinLimits(step_start, step_end, time):
local idx = 0
local actual_q = get_actual_joint_positions()
while idx < 6:
local velocity = norm(target[idx] - actual_q[idx]) / time
local velocity = norm(step_end[idx] - step_start[idx]) / time
if velocity > MAX_JOINT_SPEED:
local str = str_cat(str_cat("Velocity required to reach the received target ", target), str_cat(str_cat(" within ", time), " seconds is exceeding the joint velocity limits. Aborting script."))
local str = str_cat(str_cat("Velocity ", velocity), str_cat(str_cat(" required to reach the received target ", step_end), str_cat(str_cat(" within ", time), " seconds is exceeding the joint velocity limits. Aborting script.")))
textmsg(str)
return False
end
Expand Down Expand Up @@ -127,6 +126,7 @@ end
thread servoThread():
textmsg("ExternalControl: Starting servo thread")
state = SERVO_IDLE
local q_last = get_target_joint_positions()
while control_mode == MODE_SERVOJ:
enter_critical
q = cmd_servo_q
Expand All @@ -146,16 +146,18 @@ thread servoThread():
end

q = extrapolate()
if targetWithinLimits(q, steptime):
if targetWithinLimits(q_last, q, steptime):
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
q_last = q
else:
terminateProgram()
end

elif state == SERVO_RUNNING:
extrapolate_count = 0
if targetWithinLimits(q, steptime):
if targetWithinLimits(q_last, q, steptime):
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
q_last = q
else:
terminateProgram()
end
Expand Down Expand Up @@ -189,13 +191,13 @@ def cubicSplineRun(end_q, end_qd, time, is_last_point=False):
local str = str_cat(end_q, str_cat(end_qd, time))
textmsg("Cubic spline arg: ", str)

local start_q = get_target_joint_positions()
# Zero time means infinite velocity to reach the target and is therefore impossible
if time <= 0.0:
textmsg("Spline time shouldn't be zero as it would require infinite velocity to reach the target. Aborting script.")
socket_send_int(TRAJECTORY_RESULT_CANCELED, "trajectory_socket")
terminateProgram()
elif targetWithinLimits(end_q, time):
local start_q = get_target_joint_positions()
elif targetWithinLimits(start_q, end_q, time):
local start_qd = spline_qd

# Coefficients0 is not included, since we do not need to calculate the position
Expand All @@ -215,13 +217,13 @@ def quinticSplineRun(end_q, end_qd, end_qdd, time, is_last_point=False):
local str = str_cat(end_q, str_cat(end_qd, str_cat(end_qdd, time)))
textmsg("Quintic spline arg: ", str)

local start_q = get_target_joint_positions()
# Zero time means infinite velocity to reach the target and is therefore impossible
if time <= 0.0:
textmsg("Spline time shouldn't be zero as it would require infinite velocity to reach the target. Aborting script.")
socket_send_int(TRAJECTORY_RESULT_CANCELED, "trajectory_socket")
terminateProgram()
elif targetWithinLimits(end_q, time):
local start_q = get_target_joint_positions()
elif targetWithinLimits(start_q, end_q, time):
local start_qd = spline_qd
local start_qdd = spline_qdd

Expand Down

0 comments on commit 92ee816

Please sign in to comment.