Skip to content

Commit

Permalink
Enable force mode compatibility with various move types
Browse files Browse the repository at this point in the history
The joint positions used for checks and interpolations needs
to be without force mode modifies.
  • Loading branch information
urrsk committed Dec 10, 2024
1 parent 4daad9b commit a7349f3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions resources/external_control.urscript
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ JOINT_IGNORE_SPEED = 20.0
global violation_popup_counter = 0
global cmd_servo_state = SERVO_UNINITIALIZED
global cmd_servo_qd = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
global cmd_servo_q = get_actual_joint_positions()
global cmd_servo_q_last = get_actual_joint_positions()
global cmd_servo_q = get_joint_positions()
global cmd_servo_q_last = cmd_servo_q
global cmd_twist = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
global extrapolate_count = 0
global extrapolate_max_count = 0
Expand All @@ -78,6 +78,7 @@ global trajectory_points_left = 0
global spline_qdd = [0, 0, 0, 0, 0, 0]
global spline_qd = [0, 0, 0, 0, 0, 0]
global tool_contact_running = False
global force_mode_running = False
global trajectory_result = 0

# Global thread variables
Expand Down Expand Up @@ -158,7 +159,7 @@ end
thread servoThread():
textmsg("ExternalControl: Starting servo thread")
state = SERVO_IDLE
local q_last = get_target_joint_positions()
local q_last = get_joint_positions()
while control_mode == MODE_SERVOJ:
enter_critical
q = cmd_servo_q
Expand Down Expand Up @@ -221,13 +222,13 @@ def cubicSplineRun(end_q, end_qd, time, is_last_point=False, is_first_point=Fals
local str = str_cat(end_q, str_cat(end_qd, time))
textmsg("Cubic spline arg: ", str)

local start_q = get_target_joint_positions()
local start_q = get_joint_positions()
# Zero time means infinite velocity to reach the target and is therefore impossible
if time <= 0.0:
if is_first_point and time == 0.0:
# If users specify the current joint position with time 0 that may be fine, in that case just
# ignore that point
local distance = norm(end_q - get_target_joint_positions())
local distance = norm(end_q - start_q)
if distance < 0.01:
local splineTimerTraveled = 0.0
# USED_IN_TEST_SPLINE_INTERPOLATION write_output_float_register(1, splineTimerTraveled)
Expand Down Expand Up @@ -263,13 +264,13 @@ def quinticSplineRun(end_q, end_qd, end_qdd, time, is_last_point=False, is_first
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()
local start_q = get_joint_positions()
# Zero time means infinite velocity to reach the target and is therefore impossible
if time <= 0.0:
if is_first_point and time == 0.0:
# If users specify the current joint position with time 0 that may be fine, in that case just
# ignore that point
local distance = norm(end_q - get_target_joint_positions())
local distance = norm(end_q - start_q)
if distance < 0.01:
return False
end
Expand Down Expand Up @@ -553,7 +554,7 @@ end
thread servoThreadP():
textmsg("Starting pose servo thread")
state = SERVO_IDLE
local q_last = get_target_joint_positions()
local q_last = get_joint_positions()
while control_mode == MODE_POSE:
enter_critical
q = cmd_servo_q
Expand Down Expand Up @@ -655,8 +656,10 @@ thread script_commands():
force_mode_set_gain_scaling(raw_command[28] / MULT_jointstate)
end
force_mode(task_frame, selection_vector, wrench, force_type, force_limits)
force_mode_running = True
elif command == END_FORCE_MODE:
end_force_mode()
force_mode_running = False
elif command == START_TOOL_CONTACT:
tool_contact_running = True
elif command == END_TOOL_CONTACT:
Expand Down

0 comments on commit a7349f3

Please sign in to comment.