150
150
151
151
def set_servo_setpoint(q):
152
152
cmd_servo_state = SERVO_RUNNING
153
- cmd_servo_q_last = cmd_servo_q
154
- 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
155
157
end
156
158
157
159
def extrapolate():
163
165
thread servoThread():
164
166
textmsg("ExternalControl: Starting servo thread")
165
167
state = SERVO_IDLE
166
- local q_last = get_joint_positions()
167
168
while control_mode == MODE_SERVOJ:
168
169
enter_critical
169
170
q = cmd_servo_q
@@ -183,17 +184,11 @@ thread servoThread():
183
184
end
184
185
185
186
q = extrapolate()
186
- if targetWithinLimits(q_last, q, steptime):
187
- servoj(q, t=steptime, {{SERVO_J_REPLACE}})
188
- q_last = q
189
- end
187
+ servoj(q, t=steptime, {{SERVO_J_REPLACE}})
190
188
191
189
elif state == SERVO_RUNNING:
192
190
extrapolate_count = 0
193
- if targetWithinLimits(q_last, q, steptime):
194
- servoj(q, t=steptime, {{SERVO_J_REPLACE}})
195
- q_last = q
196
- end
191
+ servoj(q, t=steptime, {{SERVO_J_REPLACE}})
197
192
else:
198
193
extrapolate_count = 0
199
194
sync()
562
557
thread servoThreadP():
563
558
textmsg("Starting pose servo thread")
564
559
state = SERVO_IDLE
565
- local q_last = get_joint_positions()
566
560
while control_mode == MODE_POSE:
567
561
enter_critical
568
562
q = cmd_servo_q
@@ -582,15 +576,11 @@ thread servoThreadP():
582
576
end
583
577
584
578
q = extrapolate()
585
- if targetWithinLimits(q_last, q, steptime):
586
- servoj(q, t=steptime, {{SERVO_J_REPLACE}})
587
- end
579
+ servoj(q, t=steptime, {{SERVO_J_REPLACE}})
588
580
589
581
elif state == SERVO_RUNNING:
590
582
extrapolate_count = 0
591
- if targetWithinLimits(q_last, q, steptime):
592
- servoj(q, t=steptime, {{SERVO_J_REPLACE}})
593
- end
583
+ servoj(q, t=steptime, {{SERVO_J_REPLACE}})
594
584
else:
595
585
extrapolate_count = 0
596
586
sync()
@@ -601,12 +591,6 @@ thread servoThreadP():
601
591
stopj(STOPJ_ACCELERATION)
602
592
end
603
593
604
- def set_servo_pose(pose):
605
- cmd_servo_state = SERVO_RUNNING
606
- cmd_servo_q_last = cmd_servo_q
607
- cmd_servo_q = get_inverse_kin(pose, cmd_servo_q)
608
- end
609
-
610
594
def tool_contact_detection():
611
595
# Detect tool contact in the directions that the TCP is moving
612
596
step_back = tool_contact(direction = get_actual_tcp_speed())
@@ -725,6 +709,7 @@ while control_mode > MODE_STOPPED:
725
709
join thread_move
726
710
end
727
711
if control_mode == MODE_SERVOJ:
712
+ cmd_servo_q = get_joint_positions()
728
713
thread_move = run servoThread()
729
714
elif control_mode == MODE_SPEEDJ:
730
715
thread_move = run speedThread()
@@ -734,6 +719,7 @@ while control_mode > MODE_STOPPED:
734
719
elif control_mode == MODE_SPEEDL:
735
720
thread_move = run speedlThread()
736
721
elif control_mode == MODE_POSE:
722
+ cmd_servo_q = get_joint_positions()
737
723
thread_move = run servoThreadP()
738
724
end
739
725
end
@@ -763,7 +749,7 @@ while control_mode > MODE_STOPPED:
763
749
set_speedl(twist)
764
750
elif control_mode == MODE_POSE:
765
751
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]
766
- set_servo_pose( pose)
752
+ set_servo_setpoint(get_inverse_kin( pose, cmd_servo_q) )
767
753
elif control_mode == MODE_FREEDRIVE:
768
754
if params_mult[2] == FREEDRIVE_MODE_START:
769
755
textmsg("Entering freedrive mode")
0 commit comments