Breadcrumbs

thread_run()

Definition

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=Ture 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 Name

Data Type

Default Value

Description

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

Value

Description

int

Registered thread ID

Negative value

Failed

Exception

Exception

Description

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

Python
#----- 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)