Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve limit check #256

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
47 changes: 20 additions & 27 deletions resources/external_control.urscript
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,23 @@ def targetWithinLimits(step_start, step_end, time):
while idx < 6:
local velocity = norm(step_end[idx] - step_start[idx]) / time
if velocity > JOINT_IGNORE_SPEED:
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. Ignoring commands until a valid command is received.")))
local str = str_cat(
str_cat("Velocity ", velocity), str_cat(
str_cat(" required in joint ", idx), str_cat(
str_cat(" to go from ", step_start[idx]), str_cat(
str_cat(" to ", step_end[idx]), str_cat(
str_cat(" within ", time), " seconds is exceeding the joint velocity limits. Ignoring commands until a valid command is received.")))))
if violation_popup_counter == 0:
# We want a popup when an invalid commant is sent. As long as we keep sending invalid
# commands, we do not want to repeat the popup.
popup(str, title="External Control error", blocking=False, error=True)
popup(str, title="External Control speed limit", blocking=False, warning=True)
end
if violation_popup_counter * get_steptime() % 5.0 == 0:
# We want to have a log printed regularly. We are receiving motion commands that are not
# feasible. The user should have a chance to know about this.
textmsg(str)
textmsg("start configuration: ", step_start)
textmsg("end configuration: ", step_end)
end
violation_popup_counter = violation_popup_counter + 1
return False
Expand Down Expand Up @@ -143,8 +150,10 @@ end

def set_servo_setpoint(q):
cmd_servo_state = SERVO_RUNNING
cmd_servo_q_last = cmd_servo_q
cmd_servo_q = q
if targetWithinLimits(cmd_servo_q, q, steptime):
cmd_servo_q_last = cmd_servo_q
cmd_servo_q = q
end
end

def extrapolate():
Expand All @@ -158,7 +167,6 @@ end
thread servoThread():
textmsg("ExternalControl: Starting servo thread")
state = SERVO_IDLE
local q_last = get_joint_positions()
while control_mode == MODE_SERVOJ:
enter_critical
q = cmd_servo_q
Expand All @@ -178,17 +186,11 @@ thread servoThread():
end

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

elif state == SERVO_RUNNING:
extrapolate_count = 0
if targetWithinLimits(q_last, q, steptime):
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
q_last = q
end
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
else:
extrapolate_count = 0
sync()
Expand Down Expand Up @@ -557,7 +559,6 @@ end
thread servoThreadP():
textmsg("Starting pose servo thread")
state = SERVO_IDLE
local q_last = get_joint_positions()
while control_mode == MODE_POSE:
enter_critical
q = cmd_servo_q
Expand All @@ -577,15 +578,11 @@ thread servoThreadP():
end

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

elif state == SERVO_RUNNING:
extrapolate_count = 0
if targetWithinLimits(q_last, q, steptime):
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
end
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
else:
extrapolate_count = 0
sync()
Expand All @@ -596,12 +593,6 @@ thread servoThreadP():
stopj(STOPJ_ACCELERATION)
end

def set_servo_pose(pose):
cmd_servo_state = SERVO_RUNNING
cmd_servo_q_last = cmd_servo_q
cmd_servo_q = get_inverse_kin(pose, cmd_servo_q)
end

def tool_contact_detection():
# Detect tool contact in the directions that the TCP is moving
step_back = tool_contact(direction = get_actual_tcp_speed())
Expand Down Expand Up @@ -720,6 +711,7 @@ while control_mode > MODE_STOPPED:
join thread_move
end
if control_mode == MODE_SERVOJ:
cmd_servo_q = get_joint_positions()
thread_move = run servoThread()
elif control_mode == MODE_SPEEDJ:
thread_move = run speedThread()
Expand All @@ -729,6 +721,7 @@ while control_mode > MODE_STOPPED:
elif control_mode == MODE_SPEEDL:
thread_move = run speedlThread()
elif control_mode == MODE_POSE:
cmd_servo_q = get_joint_positions()
thread_move = run servoThreadP()
end
end
Expand Down Expand Up @@ -758,7 +751,7 @@ while control_mode > MODE_STOPPED:
set_speedl(twist)
elif control_mode == MODE_POSE:
pose = p[params_mult[2] / MULT_jointstate, params_mult[3] / MULT_jointstate, params_mult[4] / MULT_jointstate, params_mult[5] / MULT_jointstate, params_mult[6] / MULT_jointstate, params_mult[7] / MULT_jointstate]
set_servo_pose(pose)
set_servo_setpoint(get_inverse_kin(pose, cmd_servo_q))
elif control_mode == MODE_FREEDRIVE:
if params_mult[2] == FREEDRIVE_MODE_START:
textmsg("Entering freedrive mode")
Expand Down
Loading