• No results found

Scheduling of Program Execution Tasks

The V+ system appears to execute all the program tasks at the same time.

However, this is actually achieved by rapidly switching between the tasks many times each second, with each task receiving a fraction of the total time available.

This is referred to as concurrent execution. The following sections describe how execution time is divided among the different tasks.

NOTE: The default task configuration will work for most

applications: You will not have to alter task execution priorities. The default configuration is optimized for Adept’s AIM software.

System Timing and Time Slices

The amount of time a particular program task receives is determined by two parameters: its assignment to the various time slices and its priority within the time slice. A brief description of the system timing will help you to understand what a time slice is and how one can be selected.

NOTE: Do not confuse task priority (described here) with program priority (described in ”Asynchronous Processing” on page 62).

Task priority governs the processing of the various system tasks within a time slice. Program priority governs the execution of programs within a task.

Each system cycle is divided into 16 time slices of one millisecond each. The time slices are numbered 0 through 15. A single occurrence of all 16 time slices is referred to as a major cycle. For a robot or motion system, each of these cycles corresponds to one output from the V+ trajectory generator to the digital servos.

Specifying Tasks, Time Slices, and Priorities

Tasks 0 through 6 (0 through 27 with optional V+ Extensions software) can be used, and their configuration can be tailored to suit the needs of specific applications.

Each program task configured for use requires dedicated system memory, which is unavailable to user programs. Therefore, the number of tasks available should be made no larger than necessary, especially if memory space for user programs is critical.

Chapter 2 Scheduling of Program Execution Tasks When application programs are executed, their program tasks are normally assigned default time slices and priorities according to the current system configuration. These defaults can be overridden temporarily for any user program task. This is done by specifying the desired time-slice and priority parameters in the EXECUTE, PRIME, or XSTEP command used to initiate

execution. The temporary values remain in effect until the program task is started again, by a new EXECUTE, PRIME, or XSTEP command. (See the V+ Language Reference Guide for details on these instructions.)

Task Scheduling

Tasks are scheduled to run with a specified priority in one or more time slices.

Tasks may have priorities from –1 to 64, and the priorities may be different in each time slice. The priority meanings are:

–1 Do not run in this slice even if no other task is ready to run.

0 Do not run in this slice unless no task from this slice is ready to run.

1 - 64 Run in this slice according to specified priority. Higher priority tasks may lock out lower ones. Priorities are broken into the following ranges:

1 - 31 Normal user task priorities.

32-62 Used by V+ device drivers and system tasks.

63 Used by the trajectory generator. Do not use 63 or 64 unless you have very short task execution times. Use of these priorities may cause jerks in robot trajectories.

Whenever the current task becomes inactive (e.g., due to an I/O operation, a WAIT instruction, or completion of the task programs), V+ searches for a new task to run. The search begins with the highest priority task in the current time slice and proceeds through that slice in order of descending priority. If multiple programs are waiting to run in the task, they are run according to the relative program priorities. If a runnable task is not found, the next higher slice is checked.

All time slices are checked, wrapping around from slice 15 to slice 0 until the original slice is reached. If no runnable tasks are encountered, the V+ null task executes.

Whenever a 1ms interval expires, V+ performs a similar search of the next time slice. If the next time slice does not contain a runnable task, the currently

executing task continues.

Chapter 2 Scheduling of Program Execution Tasks If more than one task in the same time slice have the same priority, they become part of a round-robin scheduling group. Whenever a member of a round-robin group is selected by the normal slice searching, the group is scanned to find the member of the group that ran most recently. The member that follows the most recent is run instead of the one that was originally selected. If a task is in more than one round-robin group in different slices, then all such tasks in both slices appear to be in one big group. This property can cause a task to be run in a slice you did not expect. For example:

Slice 1: Task A priority 10, Task B priority 10 Slice 5: Task B priority 15, Task C priority 15

All three tasks, A, B, and C, are in the same round-robin group because task B appears in both. Therefore, task C may run in slice 1 at priority 10, or task A may run in slice 5 at priority 15, depending on which member of the group ran most recently.

The RELEASE program instruction may be used to bypass the normal scheduling process by explicitly passing control to another task. That task then gets to run in the current time slice until it is rescheduled by the 1ms clock. A task may also RELEASE to anyone, which means that a normal scan is made of all other tasks to find one that is ready to run. During this scan, members of the original task’s round-robin group (if any) are ignored. Therefore, RELEASE to anyone cannot be used to pass control to a different member of the current group.

AWAIT program instruction with no argument suspends a task until the start of the next major cycle (slice 0). At that time, the task becomes runnable and will execute if selected by the normal scheduling process. A WAIT with an expression performs a release to anyone if the expression is FALSE.

On systems that include the V+ extensions, the V+ task profiler can be used to determine how the various tasks are interacting. It provides a means of

determining how much time is being used by each task, either on an average basis or as a snapshot of several consecutive cycles.

Chapter 2 Scheduling of Program Execution Tasks Within each time slice, the task with highest priority can be locked out only by a servo interrupt. Tasks with lower priority can run only if the higher-priority task is inactive or waiting. A user task waits whenever any of the following occurs:

• The program issues an input or output request that causes a wait.

• The program executes a robot motion instruction while the robot is still moving in response to a previous motion instruction.

• The program executes a WAIT or WAIT.EVENT program instruction.

If a program is executing continuously without performing any of the above operations, it will lock out any lower-priority tasks in its time slice. Thus,

programs that execute in a continuous loop should generally execute a WAIT (or WAIT.EVENT) instruction occasionally (for example, once each time through the loop). This should not be done, of course, if timing considerations for the

application preclude such execution delays.

If a program potentially has a lot of critical processing to perform, its task should be in multiple slices, and the task should have the highest priority in these slices.

This will guarantee the task’s getting all the time needed in the multiple slices, plus (if needed) additional unused time in the major cycle.

Figure 2-4 on page 68 shows the task scheduler algorithm. This flow chart assumes that the servo task is configured to run every 1ms and no task issues a RELEASE instruction. (Actually, at the point marked run servos?, any system level interrupts are processed—in motion systems the servo task is generally the most likely to interrupt and is the most time-consuming system task.)

Chapter 2 Scheduling of Program Execution Tasks

Chapter 2 Scheduling of Program Execution Tasks

Execution Priority Example

The following example shows how the task priority scheme works. The example makes the following simplifying assumptions:

• Task 0 runs in all time slices at priority 20

• Task 1 runs in all time slices at priority 10

• Task 2 runs in all time slices at priority 20

• All system tasks are ignored (systems tasks are described in the next section)

• All system interrupts are ignored

Figure 2-5 on page 70 shows three tasks executing concurrently. Note that since no LOCK or REACT_ instructions are issued, the program priority remains 0 for the entire segment. (See ”Program Interrupt Instructions” on page 137 for descriptions of the REACT routines, the LOCK instruction, and another program execution example.)

The illustration shows the timelines of executing programs. A solid line indicates a program is running and a dotted line indicates a program is waiting. The Y axis shows the program priority. The X axis is divided into 1-millisecond time slices.

The sequence of events for Priority Example 1 is:

➊ prog_a issues a WAIT.EVENT. This suspends prog_a and passes execution to the next highest task which is task 2 running prog_c.

➋ prog_c runs until it issues a RELEASE instruction. Since the

RELEASE has no arguments, execution is passed to the next highest task with a program to run. Since task 0 is waiting on a SET.EVENT, the next task is task 1.

➌ Task 2 issues a SET.EVENT to task 0 and runs until the end of a time slice at which time task 0 runs. Tasks 0 and 2 have the same priority so they swap execution. (If two tasks with equal priority are ready to run, the least recently run task runs.)

➍ prog_c waits for a disk I/O operation to complete. The next highest priority task is 2 which runs until the I/O operation completes and task 0 becomes the least recently run task.

➎ prog_a completes, passing control to task 2.

➏ prog_c completes, passing control to task 1.

Chapter 2 Scheduling of Program Execution Tasks Notice that unless both task 0 and task 2 are waiting or do not have a program to run, or task 0 or task 2 RELEASEs to task 1, task 1 is effectively blocked from execution.

Figure 2-5. Priority Example 1

The numbers in this example are referenced in the text on page 69.

0 5 10

0 5 10

0 5 10

= task waiting

= task running

Program Priority

➊ ➍ ➎

➋ ➌ ➏

O n e V + M a j o r C y c l e

task 0 running prog_a, task priority = 20

task 1 running prog_b, task priority = 10

task 2 running prog_c, task priority = 20 1 millisecond time slices

Chapter 2 Default Task Configuration