Skip to main content
Skip table of contents

thread_run(th_func_name, loop=False)

Features

This function creates and executes a thread. The features executed by the thread are determined by the functions specified in th_func_name.


Note

The following constraints are applied when using the thread command.

  • Up to 4 threads can be used.
  • The following motion command cannot be used to move the robot in the thread.
    • movej, amovej, movejx, amovejx, movel, amovel, movec, amovec, movesj, amovesj,
    • movesx, amovesx, moveb, amoveb, move_spiral, amove_spiral,
    • move_periodic, amove_periodic, move_home
  • The thread commands do not operate normally when the loop=True during thread_run and the block is an indefinite loop within the thread function. (The thread is normally stopped when the stop command is executed through the TP.)

Parameters

Parameter NameData TypeDefault ValueDescription

th_func_name

callable

-

Name of the function run by the thread

loop

bool

False

Flag indicates whether the thread will be repeated

  • True: Repeated calling of th_func_name
    (interval 0.01second)
  • False: One-time calling of th_func_name

Return

ValueDescription

int

Registered thread ID

Negative value

Failed

Exception

ExceptionDescription

DR_Error (DR_ERROR_TYPE)

Parameter data type error occurred

DR_Error (DR_ERROR_VALUE)

Parameter value is invalid

DR_Error (DR_ERROR_RUNTIME)

C extension module error occurred

DR_Error (DR_ERROR_STOP)

Program terminated forcefully

Example

PY
#----- Thread -------------------------------------- 
def fn_th_func():
	if check_motion()==0:	# No motion in action
		set_digital_output(1, OFF)
	else:
		set_digital_output(1, ON)

#----- Main routine ----------------------------------
th_id = thread_run(fn_th_func, loop=True) # Thread run

while 1: 
	# do something…
	wait(0.1)
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.