@@ -34,7 +34,7 @@ TRAJECTORY_MODE_CANCEL = -1
3434TRAJECTORY_POINT_JOINT = 0
3535TRAJECTORY_POINT_CARTESIAN = 1
3636TRAJECTORY_POINT_JOINT_SPLINE = 2
37- TRAJECTORY_DATA_DIMENSION = 3* 6 + 1
37+ TRAJECTORY_DATA_DIMENSION = 3 * 6 + 1
3838
3939TRAJECTORY_RESULT_SUCCESS = 0
4040TRAJECTORY_RESULT_CANCELED = 1
@@ -47,7 +47,7 @@ START_FORCE_MODE = 3
4747END_FORCE_MODE = 4
4848START_TOOL_CONTACT = 5
4949END_TOOL_CONTACT = 6
50- SCRIPT_COMMAND_DATA_DIMENSION = 26
50+ SCRIPT_COMMAND_DATA_DIMENSION = 28
5151
5252FREEDRIVE_MODE_START = 1
5353FREEDRIVE_MODE_STOP = -1
@@ -113,11 +113,11 @@ thread servoThread():
113113 end
114114
115115 q = extrapolate()
116- servoj(q, t= steptime, {{SERVO_J_REPLACE}})
116+ servoj(q, t = steptime, {{SERVO_J_REPLACE}})
117117
118118 elif state == SERVO_RUNNING:
119119 extrapolate_count = 0
120- servoj(q, t= steptime, {{SERVO_J_REPLACE}})
120+ servoj(q, t = steptime, {{SERVO_J_REPLACE}})
121121 else:
122122 extrapolate_count = 0
123123 sync()
@@ -144,7 +144,7 @@ thread speedThread():
144144 stopj(STOPJ_ACCELERATION)
145145end
146146
147- def cubicSplineRun(end_q, end_qd, time, is_last_point= False):
147+ def cubicSplineRun(end_q, end_qd, time, is_last_point = False):
148148 local str = str_cat(end_q, str_cat(end_qd, time))
149149 textmsg("Cubic spline arg: ", str)
150150
@@ -163,7 +163,7 @@ def cubicSplineRun(end_q, end_qd, time, is_last_point=False):
163163 end
164164end
165165
166- def quinticSplineRun(end_q, end_qd, end_qdd, time, is_last_point= False):
166+ def quinticSplineRun(end_q, end_qd, end_qdd, time, is_last_point = False):
167167 local str = str_cat(end_q, str_cat(end_qd, str_cat(end_qdd, time)))
168168 textmsg("Quintic spline arg: ", str)
169169
@@ -244,7 +244,7 @@ def jointSplineRun(coefficients1, coefficients2, coefficients3, coefficients4, c
244244 scaled_step_time = get_steptime() * scaling_factor
245245
246246 splineTimerTraveled = splineTimerTraveled + scaled_step_time
247-
247+
248248 jointSplineStep(coefficients1, coefficients2, coefficients3, coefficients4, coefficients5, splineTimerTraveled, get_steptime(), scaling_factor, is_slowing_down)
249249 end
250250 scaling_factor = 0.0
@@ -261,7 +261,7 @@ def jointSplineRun(coefficients1, coefficients2, coefficients3, coefficients4, c
261261 jointSplineStep(coefficients1, coefficients2, coefficients3, coefficients4, coefficients5, splineTotalTravelTime, timeLeftToTravel, scaling_factor, is_slowing_down)
262262end
263263
264- def jointSplineStep(coefficients1, coefficients2, coefficients3, coefficients4, coefficients5, splineTimerTraveled, timestep, scaling_factor, is_slowing_down= False):
264+ def jointSplineStep(coefficients1, coefficients2, coefficients3, coefficients4, coefficients5, splineTimerTraveled, timestep, scaling_factor, is_slowing_down = False):
265265 local last_spline_qd = spline_qd
266266 spline_qd = coefficients1 + 2.0 * splineTimerTraveled * coefficients2 + 3.0 * pow(splineTimerTraveled, 2) * coefficients3 + 4.0 * pow(splineTimerTraveled, 3) * coefficients4 + 5.0 * pow(splineTimerTraveled, 4) * coefficients5
267267 spline_qdd = 2.0 * coefficients2 + 6.0 * splineTimerTraveled * coefficients3 + 12.0 * pow(splineTimerTraveled, 2) * coefficients4 + 20.0 * pow(splineTimerTraveled, 3) * coefficients5
@@ -341,11 +341,11 @@ thread trajectoryThread():
341341 enter_critical
342342 while trajectory_points_left > 0:
343343 #reading trajectory point + blend radius + type of point (cartesian/joint based)
344- local raw_point = socket_read_binary_integer(TRAJECTORY_DATA_DIMENSION+1+ 1, "trajectory_socket", get_steptime())
344+ local raw_point = socket_read_binary_integer(TRAJECTORY_DATA_DIMENSION + 1 + 1, "trajectory_socket", get_steptime())
345345 trajectory_points_left = trajectory_points_left - 1
346346
347347 if raw_point[0] > 0:
348- local q = [ raw_point[1]/ MULT_jointstate, raw_point[2]/ MULT_jointstate, raw_point[3]/ MULT_jointstate, raw_point[4]/ MULT_jointstate, raw_point[5]/ MULT_jointstate, raw_point[6]/ MULT_jointstate]
348+ local q = [raw_point[1] / MULT_jointstate, raw_point[2] / MULT_jointstate, raw_point[3] / MULT_jointstate, raw_point[4] / MULT_jointstate, raw_point[5] / MULT_jointstate, raw_point[6] / MULT_jointstate]
349349 local tmptime = raw_point[INDEX_TIME] / MULT_time
350350 local blend_radius = raw_point[INDEX_BLEND] / MULT_time
351351 local is_last_point = False
@@ -355,34 +355,34 @@ thread trajectoryThread():
355355 end
356356 # MoveJ point
357357 if raw_point[INDEX_POINT_TYPE] == TRAJECTORY_POINT_JOINT:
358- movej(q, t= tmptime, r= blend_radius)
358+ movej(q, t = tmptime, r = blend_radius)
359359
360360 # reset old acceleration
361361 spline_qdd = [0, 0, 0, 0, 0, 0]
362362 spline_qd = [0, 0, 0, 0, 0, 0]
363363
364- # Movel point
364+ # Movel point
365365 elif raw_point[INDEX_POINT_TYPE] == TRAJECTORY_POINT_CARTESIAN:
366- movel(p[q[0], q[1], q[2], q[3], q[4], q[5]], t= tmptime, r= blend_radius)
366+ movel(p[q[0], q[1], q[2], q[3], q[4], q[5]], t = tmptime, r = blend_radius)
367367
368368 # reset old acceleration
369369 spline_qdd = [0, 0, 0, 0, 0, 0]
370370 spline_qd = [0, 0, 0, 0, 0, 0]
371371
372- # Joint spline point
372+ # Joint spline point
373373 elif raw_point[INDEX_POINT_TYPE] == TRAJECTORY_POINT_JOINT_SPLINE:
374374
375375 # Cubic spline
376376 if raw_point[INDEX_SPLINE_TYPE] == SPLINE_CUBIC:
377- qd = [ raw_point[7] / MULT_jointstate, raw_point[8] / MULT_jointstate, raw_point[9] / MULT_jointstate, raw_point[10] / MULT_jointstate, raw_point[11] / MULT_jointstate, raw_point[12] / MULT_jointstate]
377+ qd = [raw_point[7] / MULT_jointstate, raw_point[8] / MULT_jointstate, raw_point[9] / MULT_jointstate, raw_point[10] / MULT_jointstate, raw_point[11] / MULT_jointstate, raw_point[12] / MULT_jointstate]
378378 cubicSplineRun(q, qd, tmptime, is_last_point)
379379 # reset old acceleration
380380 spline_qdd = [0, 0, 0, 0, 0, 0]
381381
382- # Quintic spline
382+ # Quintic spline
383383 elif raw_point[INDEX_SPLINE_TYPE] == SPLINE_QUINTIC:
384- qd = [ raw_point[7] / MULT_jointstate, raw_point[8] / MULT_jointstate, raw_point[9] / MULT_jointstate, raw_point[10] / MULT_jointstate, raw_point[11] / MULT_jointstate, raw_point[12] / MULT_jointstate]
385- qdd = [ raw_point[13]/ MULT_jointstate, raw_point[14]/ MULT_jointstate, raw_point[15]/ MULT_jointstate, raw_point[16]/ MULT_jointstate, raw_point[17]/ MULT_jointstate, raw_point[18]/ MULT_jointstate]
384+ qd = [raw_point[7] / MULT_jointstate, raw_point[8] / MULT_jointstate, raw_point[9] / MULT_jointstate, raw_point[10] / MULT_jointstate, raw_point[11] / MULT_jointstate, raw_point[12] / MULT_jointstate]
385+ qdd = [raw_point[13] / MULT_jointstate, raw_point[14] / MULT_jointstate, raw_point[15] / MULT_jointstate, raw_point[16] / MULT_jointstate, raw_point[17] / MULT_jointstate, raw_point[18] / MULT_jointstate]
386386 quinticSplineRun(q, qd, qdd, tmptime, is_last_point)
387387 else:
388388 textmsg("Unknown spline type given:", raw_point[INDEX_POINT_TYPE])
400400
401401def clear_remaining_trajectory_points():
402402 while trajectory_points_left > 0:
403- raw_point = socket_read_binary_integer(TRAJECTORY_DATA_DIMENSION+ 2, "trajectory_socket")
403+ raw_point = socket_read_binary_integer(TRAJECTORY_DATA_DIMENSION + 2, "trajectory_socket")
404404 trajectory_points_left = trajectory_points_left - 1
405405 end
406406end
@@ -443,11 +443,11 @@ thread servoThreadP():
443443 end
444444
445445 q = extrapolate()
446- servoj(q, t= steptime, {{SERVO_J_REPLACE}})
446+ servoj(q, t = steptime, {{SERVO_J_REPLACE}})
447447
448448 elif state == SERVO_RUNNING:
449449 extrapolate_count = 0
450- servoj(q, t= steptime, {{SERVO_J_REPLACE}})
450+ servoj(q, t = steptime, {{SERVO_J_REPLACE}})
451451 else:
452452 extrapolate_count = 0
453453 sync()
@@ -513,6 +513,10 @@ thread script_commands():
513513 wrench = [raw_command[14] / MULT_jointstate, raw_command[15] / MULT_jointstate, raw_command[16] / MULT_jointstate, raw_command[17] / MULT_jointstate, raw_command[18] / MULT_jointstate, raw_command[19] / MULT_jointstate]
514514 force_type = raw_command[20] / MULT_jointstate
515515 force_limits = [raw_command[21] / MULT_jointstate, raw_command[22] / MULT_jointstate, raw_command[23] / MULT_jointstate, raw_command[24] / MULT_jointstate, raw_command[25] / MULT_jointstate, raw_command[26] / MULT_jointstate]
516+ force_mode_set_damping(raw_command[27] / MULT_jointstate)
517+ if (get_steptime() < 0.008):
518+ force_mode_set_gain_scaling(raw_command[28] / MULT_jointstate)
519+ end
516520 force_mode(task_frame, selection_vector, wrench, force_type, force_limits)
517521 elif command == END_FORCE_MODE:
518522 end_force_mode()
@@ -536,9 +540,6 @@ socket_open("{{SERVER_IP_REPLACE}}", {{SERVER_PORT_REPLACE}}, "reverse_socket")
536540socket_open("{{SERVER_IP_REPLACE}}", {{TRAJECTORY_SERVER_PORT_REPLACE}}, "trajectory_socket")
537541socket_open("{{SERVER_IP_REPLACE}}", {{SCRIPT_COMMAND_SERVER_PORT_REPLACE}}, "script_command_socket")
538542
539- force_mode_set_damping({{FORCE_MODE_SET_DAMPING_REPLACE}})
540- force_mode_set_gain_scaling({{FORCE_MODE_SET_GAIN_SCALING_REPLACE}})
541-
542543control_mode = MODE_UNINITIALIZED
543544thread_move = 0
544545thread_trajectory = 0
@@ -551,15 +552,15 @@ while control_mode > MODE_STOPPED:
551552 params_mult = socket_read_binary_integer(REVERSE_INTERFACE_DATA_DIMENSION, "reverse_socket", read_timeout)
552553 if params_mult[0] > 0:
553554 # Convert to read timeout from milliseconds to seconds
554- read_timeout = params_mult[1] / 1000.0
555+ read_timeout = params_mult[1] / 1000.0
555556 if control_mode != params_mult[REVERSE_INTERFACE_DATA_DIMENSION]:
556557 # Clear remaining trajectory points
557558 if control_mode == MODE_FORWARD:
558559 kill thread_trajectory
559560 clear_remaining_trajectory_points()
560561 stopj(STOPJ_ACCELERATION)
561562 socket_send_int(TRAJECTORY_RESULT_CANCELED, "trajectory_socket")
562- # Stop freedrive
563+ # Stop freedrive
563564 elif control_mode == MODE_FREEDRIVE:
564565 textmsg("Leaving freedrive mode")
565566 end_freedrive_mode()
@@ -590,10 +591,10 @@ while control_mode > MODE_STOPPED:
590591
591592 # Update the motion commands with new parameters
592593 if control_mode == MODE_SERVOJ:
593- q = [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]
594+ q = [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]
594595 set_servo_setpoint(q)
595596 elif control_mode == MODE_SPEEDJ:
596- qd = [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]
597+ qd = [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]
597598 set_speed(qd)
598599 elif control_mode == MODE_FORWARD:
599600 if params_mult[2] == TRAJECTORY_MODE_RECEIVE:
0 commit comments