Skip to content

Commit 99f0a76

Browse files
authored
Improve limit check (#256)
This should reduce the limit check getting triggered and also improve the check's output for debugging purposes.
1 parent 55ec716 commit 99f0a76

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

resources/external_control.urscript

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,23 @@ def targetWithinLimits(step_start, step_end, time):
9999
while idx < 6:
100100
local velocity = norm(step_end[idx] - step_start[idx]) / time
101101
if velocity > JOINT_IGNORE_SPEED:
102-
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.")))
102+
local str = str_cat(
103+
str_cat("Velocity ", velocity), str_cat(
104+
str_cat(" required in joint ", idx), str_cat(
105+
str_cat(" to go from ", step_start[idx]), str_cat(
106+
str_cat(" to ", step_end[idx]), str_cat(
107+
str_cat(" within ", time), " seconds is exceeding the joint velocity limits. Ignoring commands until a valid command is received.")))))
103108
if violation_popup_counter == 0:
104109
# We want a popup when an invalid commant is sent. As long as we keep sending invalid
105110
# commands, we do not want to repeat the popup.
106-
popup(str, title="External Control error", blocking=False, error=True)
111+
popup(str, title="External Control speed limit", blocking=False, warning=True)
107112
end
108113
if violation_popup_counter * get_steptime() % 5.0 == 0:
109114
# We want to have a log printed regularly. We are receiving motion commands that are not
110115
# feasible. The user should have a chance to know about this.
111116
textmsg(str)
117+
textmsg("start configuration: ", step_start)
118+
textmsg("end configuration: ", step_end)
112119
end
113120
violation_popup_counter = violation_popup_counter + 1
114121
return False
@@ -143,8 +150,10 @@ end
143150

144151
def set_servo_setpoint(q):
145152
cmd_servo_state = SERVO_RUNNING
146-
cmd_servo_q_last = cmd_servo_q
147-
cmd_servo_q = q
153+
if targetWithinLimits(cmd_servo_q, q, steptime):
154+
cmd_servo_q_last = cmd_servo_q
155+
cmd_servo_q = q
156+
end
148157
end
149158

150159
def extrapolate():
@@ -156,7 +165,6 @@ end
156165
thread servoThread():
157166
textmsg("ExternalControl: Starting servo thread")
158167
state = SERVO_IDLE
159-
local q_last = get_joint_positions()
160168
while control_mode == MODE_SERVOJ:
161169
enter_critical
162170
q = cmd_servo_q
@@ -176,17 +184,11 @@ thread servoThread():
176184
end
177185

178186
q = extrapolate()
179-
if targetWithinLimits(q_last, q, steptime):
180-
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
181-
q_last = q
182-
end
187+
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
183188

184189
elif state == SERVO_RUNNING:
185190
extrapolate_count = 0
186-
if targetWithinLimits(q_last, q, steptime):
187-
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
188-
q_last = q
189-
end
191+
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
190192
else:
191193
extrapolate_count = 0
192194
sync()
@@ -555,7 +557,6 @@ end
555557
thread servoThreadP():
556558
textmsg("Starting pose servo thread")
557559
state = SERVO_IDLE
558-
local q_last = get_joint_positions()
559560
while control_mode == MODE_POSE:
560561
enter_critical
561562
q = cmd_servo_q
@@ -575,15 +576,11 @@ thread servoThreadP():
575576
end
576577

577578
q = extrapolate()
578-
if targetWithinLimits(q_last, q, steptime):
579-
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
580-
end
579+
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
581580

582581
elif state == SERVO_RUNNING:
583582
extrapolate_count = 0
584-
if targetWithinLimits(q_last, q, steptime):
585-
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
586-
end
583+
servoj(q, t=steptime, {{SERVO_J_REPLACE}})
587584
else:
588585
extrapolate_count = 0
589586
sync()
@@ -594,12 +591,6 @@ thread servoThreadP():
594591
stopj(STOPJ_ACCELERATION)
595592
end
596593

597-
def set_servo_pose(pose):
598-
cmd_servo_state = SERVO_RUNNING
599-
cmd_servo_q_last = cmd_servo_q
600-
cmd_servo_q = get_inverse_kin(pose, cmd_servo_q)
601-
end
602-
603594
def tool_contact_detection():
604595
# Detect tool contact in the directions that the TCP is moving
605596
step_back = tool_contact(direction = get_actual_tcp_speed())
@@ -718,6 +709,7 @@ while control_mode > MODE_STOPPED:
718709
join thread_move
719710
end
720711
if control_mode == MODE_SERVOJ:
712+
cmd_servo_q = get_joint_positions()
721713
thread_move = run servoThread()
722714
elif control_mode == MODE_SPEEDJ:
723715
thread_move = run speedThread()
@@ -727,6 +719,7 @@ while control_mode > MODE_STOPPED:
727719
elif control_mode == MODE_SPEEDL:
728720
thread_move = run speedlThread()
729721
elif control_mode == MODE_POSE:
722+
cmd_servo_q = get_joint_positions()
730723
thread_move = run servoThreadP()
731724
end
732725
end
@@ -756,7 +749,7 @@ while control_mode > MODE_STOPPED:
756749
set_speedl(twist)
757750
elif control_mode == MODE_POSE:
758751
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]
759-
set_servo_pose(pose)
752+
set_servo_setpoint(get_inverse_kin(pose, cmd_servo_q))
760753
elif control_mode == MODE_FREEDRIVE:
761754
if params_mult[2] == FREEDRIVE_MODE_START:
762755
textmsg("Entering freedrive mode")

0 commit comments

Comments
 (0)