100% found this document useful (1 vote)
27 views34 pages

MELFA V robot programing (1)

The document provides a detailed overview of the MELFA-BASIC V programming language, outlining its functions related to robot operation control, including joint, linear, and circular interpolation movements. It includes command words, statement examples, and program examples for each type of movement, as well as related functions for speed control and signal input/output. The document serves as a guide for programming robot movements and controlling operations effectively.

Uploaded by

Harsh Surti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
27 views34 pages

MELFA V robot programing (1)

The document provides a detailed overview of the MELFA-BASIC V programming language, outlining its functions related to robot operation control, including joint, linear, and circular interpolation movements. It includes command words, statement examples, and program examples for each type of movement, as well as related functions for speed control and signal input/output. The document serves as a guide for programming robot movements and controlling operations effectively.

Uploaded by

Harsh Surti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

4MELFA-BASIC V

4 MELFA-BASIC V
In this chapter, the functions and the detailed language specification of the programming language "MELFA-
BASIC V" are explained.

4.1 MELFA-BASIC V functions


The outline of the programming language "MELFA-BASIC V" is explained in this section. The basic move-
ment of the robot, signal input/output, and conditional branching methods are described.

Table 4-1:List of items described


Item Details Related instructions, etc.

1 4.1.1Robot operation control (1)Joint interpolation movement Mov

2 (2)Linear interpolation movement Mvs

3 (3)Circular interpolation movement Mvr, Mvr2, Mvr3, Mvc

4 (4)Continuous movement Cnt


5 (5)Acceleration/deceleration time and speed control Accel, Oadl

6 (6)Confirming that the target position is reached Fine, Mov and Dly

7 (7)High path accuracy control Prec

8 (8)Hand and tool control HOpen, HClose, Tool


9 4.1.2Pallet operation -------------- Def Plt, Plt

10 4.1.3Program control (1)Unconditional branching, conditional branching, GoTo, If Then Else, Wait, etc
waiting

11 (2)Repetition For Next, While WEnd

12 (3)Interrupt Def Act, Act

13 (4)Subroutine GoSub, CallP, On GoSub, etc

14 (5)Timer Dly

15 (6)Stopping End(Pause for one cycle), Hlt

16 4.1.4Inputting and outputting (1)Input signals M_In, M_Inb, M_Inw, etc


external signals
17 (2)Output signals M_Out, M_Outb, M_Outw, etc

18 4.1.5Communication Note1) -------------- Open, Close, Print, Input, etc

19 4.1.6Expressions and operations (1)List of operator +, -, *, / , <>, <, >, etc

20 (2)Relative calculation of position data (multiplication) P1 * P2

21 (3)Relative calculation of position data (Addition) P1 + P2

22 4.1.7Appended statement -------------- Wth, WthIf

Note1) Cannot use in CR750-Q series.

For the detailed description of each instruction, please refer to Page 162, "4.13 Detailed explanation of com-
mand words".

MELFA-BASIC V functions 4-92


4MELFA-BASIC V

4.1.1 Robot operation control


(1) Joint interpolation movement
The robot moves with joint axis unit interpolation to the designated position. (The robot interpolates with a
joint axis unit, so the end path is irrelevant.)

*Command word
Command word Explanation
Mov The robot moves to the designated position with joint interpolation. It is possible to specify the
interpolation form using the TYPE instruction. An appended statement Wth or WthIf can be
designated

*Statement example
Statement example Explanation
Mov P1 ....................................................... ' Moves to P1.
Mov P1+P2................................................. ' Moves to the position obtained by adding the P1 and P2 coordinate elements. Refer to Page 117.
Mov P1*P2.................................................. ' Moves to the position relatively converted from P1 to P2. Refer to Page 117.
Mov P1,-50 *1)............................................ ' Moves from P1 to a position retracted 50mm in the hand direction.
Mov P1 Wth M_Out(17)=1......................... ' Starts movement toward P1, and simultaneously turns output signal bit 17 ON.
Mov P1 WthIf M_In(20)=1, Skip................. ' If the input signal bit 20 turns ON during movement to P1, the movement to P1 is stopped, and the
program proceeds to the next stop.
Mov P1 Type 1, 0 ........................................ ' Specify either roundabout (or shortcut) when the operation angle of each axis exceeds 180 deg..
(Default value: Long way around)

*Program example
Robot movement Hand *1) Specification of for-
:Robot movement
CAUTION ward/backward movement
:Movement position of the hand
(1)
The statement examples and program examples
P1
are for a vertical 6-axis robot (e.g., RV-6SD).The
hand advance/retrace direction relies on the
(2) 10
0m Z axis direction (+/- direction) of the tool coor-
m
(6) dinate set for each model.
(5) Refer to the tool coordinate system shown in
50mm

(3) "Confirmation of movement" in the separate


(4) Turn output "From Robot unit setup to maintenance", and
P3
P2
signal bit 17 ON.
designate the correct direction.
Program example
Program Explanation
1 Mov P1 ’(1) Moves to P1.
2 Mov P2, -50 *1) ’(2) Moves from P2 to a position retracted 50mm in the hand direction.
3 Mov P2 ’(3) Moves to P2
4 Mov P3, -100 Wth M_Out (17) = 1 ’(4) Starts movement from P3 to a position retracted 100mm in the hand direction, and turns ON output
signal bit 17.
5 Mov P3 ’(5) Moves to P3
6 Mov P3, -100 *1) ’(6) Returns from P3 to a position retracted 100mm in the hand direction.
7 End ’Ends the program.

4-93 MELFA-BASIC V functions


4MELFA-BASIC V

*Related functions
Function Explanation page
Designate the movement speed........................................................ Page 98, "(5) Acceleration/deceleration time and speed control"
Designate the acceleration/deceleration time. ................................. Page 98, "(5) Acceleration/deceleration time and speed control"
Confirm that the target position is reached. ...................................... Page 100, "(6) Confirming that the target position is reached"
Continuously move to next position without stopping at target posi-
tion..................................................................................................... Page 97, "(4) Continuous movement"
Move linearly. ................................................................................... Page 94, "(2) Linear interpolation movement"
Move while drawing a circle or arc. ................................................... Page 95, "(3) Circular interpolation movement"
Add a movement command to the process....................................... Page 274, " Wth (With)"

(2) Linear interpolation movement


The end of the hand is moved with linear interpolation to the designated position.

*Command word
Command word Explanation
Mvs The robot moves to the designated position with linear interpolation. It is possible to specify the
interpolation form using the TYPE instruction. An appended statement Wth or WthIf can be
designated.

*Statement example
Statement example Explanation
Mvs P1 ................................................................ ' Moves to P1
Mvs P1+P2.......................................................... ' Moves to the position obtained by adding the P1 and P2 coordinate elements. Refer to Page
117.
Mvs P1*P2........................................................... ' Moves to the position relatively converted from P1 to P2.
Mvs P1, -50 *1).................................................... ' Moves from P1 to a position retracted 50mm in the hand direction.
Mvs ,-50 *1) ......................................................... ' Moves from the current position to a position retracted 50mm in the hand direction.
Mvs P1 Wth M_Out(17)=1................................... ' Starts movement toward P1, and simultaneously turns output signal bit 17 ON.
Mvs P1 WthIf M_In(20)=1, Skip.......................... ' If the input signal bit 20 turns ON during movement to P1, the movement to P1 is stopped, and
the program proceeds to the next stop.
Mvs P1 Type 0, 0................................................. ' Moves to P1 with equivalent rotation
Mvs P1 Type 9, 1................................................. ' Moves to P1 with 3-axis orthogonal interpolation.

*Program example
Robot movement *1) Specification of forward/
Hand :Robot movement
:Movement position
CAUTION backward movement of the
hand
10 The statement examples and program examples
(1) 0m are for a vertical 6-axis robot (e.g., RV-6SD).The
m
hand advance/retrace direction relies on the
(6)
(5)
Z axis direction (+/- direction) of the tool coor-
(4)Turn output dinate set for each model.
50mm

(2) signal bit 17 ON. Refer to the tool coordinate system shown in
(3)
"Confirmation of movement" in the separate
P2
"From Robot unit setup to maintenance", and
P1 designate the correct direction.

MELFA-BASIC V functions 4-94


4MELFA-BASIC V

Program example
Program Explanation
1 Mvs P1, -50 *1) ' (1) Moves with linear interpolation from P1 to a position retracted 50mm in the hand
direction.
2 Mvs P1 ' (2) Moves to P1 with linear interpolation.
3 Mvs ,-50 *1) ' (3) Moves with linear interpolation from the current position (P1) to a position retracted
50mm in the hand direction.
4 Mvs P2, -100 Wth M_Out(17)=1 *1) (4) Output signal bit 17 is turned on at the same time as the robot starts moving.
5 Mvs P2 (5) Moves with linear interpolation to P2.
6 Mvs , -100 *1) (6) Moves with linear interpolation from the current position (P2) to a position retracted
50mm in the hand direction.
7 End ’Ends the program.

*Related functions
Function Explanation page
Designate the movement speed. .............................................................. Page 98, "(5) Acceleration/deceleration time and speed
control"
Designate the acceleration/deceleration time. ......................................... Page 98, "(5) Acceleration/deceleration time and speed control"
Confirm that the target position is reached. ............................................. Page 100, "(6) Confirming that the target position is reached"
Continuously move to next position without stopping at target position.... Page 97, "(4) Continuous movement"
Move with joint interpolation...................................................................... Page 93, "(1) Joint interpolation movement"
Move while drawing a circle or arc. ........................................................... Page 95, "(3) Circular interpolation movement"
Add a movement command to the process............................................... Page 274, " Wth (With)"

(3) Circular interpolation movement


The robot moves along an arc designated with three points using three-dimensional circular interpolation.
If the current position is separated from the start point when starting circular movement, the robot will move
to the start point with linear operation and then begin circular interpolation.

*Command word
Command word Explanation
Mvr Designates the start point, transit point and end point, and moves the robot with circular
interpolation in order of the start point - transit point - end point. It is possible to specify the
interpolation form using the TYPE instruction. An appended statement Wth or WthIf can be
designated.
Mvr2 Designates the start point, end point and reference point, and moves the robot with circular
interpolation from the start point - end point without passing through the reference point. It is
possible to specify the interpolation form using the TYPE instruction. An appended statement Wth
or WthIf can be designated.
Mvr3 Designates the start point, end point and center point, and moves the robot with circular
interpolation from the start point to the end point. The fan angle from the start point to the end
point is 0 deg. < fan angle < 180 deg. It is possible to specify the interpolation form using the
TYPE instruction. An appended statement Wth or WthIf can be designated.
Mvc Designates the start point (end point), transit point 1 and transit point 2, and moves the robot with
circular interpolation in order of the start point - transit point 1 - transit point 2 - end point. An
appended statement Wth or WthIf can be designated.

4-95 MELFA-BASIC V functions


4MELFA-BASIC V

*Statement example
Statement example Explanation
Mvr P1, P2, P3 ................................................................. ' Moves with circular interpolation between P1 - P2 - P3.
Mvr P1, P2, P3 Wth M_Out (17) = 1................................ ' Circular interpolation between P1 - P2 - P3 starts, and the output signal bit 17 turns ON.
Mvr P1, P2, P3 WthIf M_In (20) = 1, Skip ....................... ' If the input signal bit 20 turns ON during circular interpolation between P1 - P2 - P3,
circular interpolation to P1 is stopped, and the program proceeds to the next step.
Mvr P1, P2, P3 TYPE 0, 1................................................ ' Moves with circular interpolation between P1 - P2 - P3.
Mvr2 P1, P3, P11 ............................................................. ' Circular interpolation is carried out from P1 to P3 in the direction that P11 is not passed.
P11 is the reference point.
Mvr3 P1, P3, P10 ............................................................. ' Moves with circular interpolation from P1 to P3 in the direction with the smallest fan
angle. P10 is the center point.
Mvc P1, P2, P3................................................................. ' Moves with circular movement from P1 - P2 - P3 - P1.
*Program example
Robot movement
Hand :Robot movement
:Movement position

P4 P11
P6 (5)
P1 (2) (Reference P10
point)
P5
(1) P9
Turn output
signal bit
18 ON.
(3)
P3 P8
P7 (Center point)
P2

(4)
Program example
Program Explanation
1 Mvr P1, P2, P3 Wth M_Out(18) = 1 ' (1) Moves between P1 - P2 - P3 as an arc. The robot current position before movement is
separated from the start point, so first the robot will move with linear operation to the start point. (P1)
output signal bit 18 turns ON simultaneously with the start of circular movement.
2 Mvr P3, P4, P5 ' (2) Moves between P3 - P4 - P5 as an arc.
3 Mvr2 P5, P7, P6 ' (3) Moves as an arc over the circumference on which the start point (P5), reference point (P6) and
end point (P7) in the direction that the reference point is not passed between the start point and end
point.
4 Mvr3 P7, P9, P8 ' (4) Moves as an arc from the start point to the end point along the circumference on which the
center point (P8), start point (P7) and end point (P9) are designated.
5 Mvc P9, P10, P11 ' (5) Moves between P9 - P10 - P11 - P9 as an arc. The robot current position before movement is
separated from the start point, so first the robot will move with linear operation to the start point.(1
cycle operation)
6 End ' Ends the program.

*Related functions
Function Explanation page
Designate the movement speed. .................................................................... Page 98, "(5) Acceleration/deceleration time and speed
control"
Designate the acceleration/deceleration time. ............................................... Page 98, "(5) Acceleration/deceleration time and speed
control"
Confirm that the target position is reached. ................................................... Page 100, "(6) Confirming that the target position is reached"
Continuously move to next position without stopping at target position.......... Page 97, "(4) Continuous movement"
Move with joint interpolation............................................................................ Page 93, "(1) Joint interpolation movement"
Move linearly. .................................................................................................. Page 94, "(2) Linear interpolation movement"
Add a movement command to the process. ................................................... Page 274, " Wth (With)"

MELFA-BASIC V functions 4-96


4MELFA-BASIC V

(4) Continuous movement


The robot continuously moves to multiple movement positions without stopping at each movement position.
The start and end of the continuous movement are designated with the command statement. The speed can
be changed even during continuous movement.
*Command word
Command word Explanation
Cnt Designates the start and end of the continuous movement.

*Statement example
Statement example Explanation
Cnt 1 ................................................................................. Designates the start of the continuous movement.
CNT 1, 100, 200 ............................................................... Designates the start of the continuous movement, and designates that the start point
neighborhood distance is 100mm, and the end point neighborhood distance is 200mm.
CNT 0 ............................................................................... Designates the end of the continuous movement.
*Program example
Robot movement
Hand :Robot movement
:Movement position CAUTION
The robot moves continuously for less than the smaller distance
of either the proximity distance when moving toward P6 (200 mm) *1) Specification of forward/backward move-
(1) or the proximity distance to the starting point of the path to P1 (100 mm). ment of the hand
The statement examples and program exam-
P1 100mm ples are for a vertical 6-axis robot (e.g., RV-
(5) 6SD).The hand advance/retrace direction
relies on the Z axis direction (+/- direction) of
200mm

P6 the tool coordinate set for each model.


(2) Refer to the tool coordinate system shown in
P2 "Confirmation of movement" in the separate
"From Robot unit setup to maintenance", and
(4) designate the correct direction.

CAUTION
100mm

P5
P3 The robot's locus of movement may change
with specified speed.
(3) Especially as for the corner section, short cut
P4 distance may change. Therefore, when
Default value beginning automatic operation, moves at low
speed at first, and you should gather speed
The robot moves continuously for less than the smaller distance of either slowly with being careful of interference with
the proximity distance when moving toward P5 (default value) or the proximity peripheral equipment.
distance to the starting point of the path to P6 (200 mm).

Program example
Program Explanation
1 Mov P1 ' (1) Moves with joint interpolation to P1.
2 Cnt 1 ' Validates continuous movement. (Following movement is continuous movement.)
3 Mvr P2, P3, P4 ' (2) Moves linearly to P2, and continuously moves to P4 with arc movement.
4 Mvs P5 ' After arc movement, moves linearly to P5.
5 Cnt 1, 200, 100 ' (3) Sets the continuous movement's start point neighborhood distance to 200mm,
and the end point neighborhood distance to 100mm.
6 Mvs P6 ' (4) After moving to previous P5, moves in succession linearly to P6.
7 Mvs P1 ' (5) Continuously moves to P1 with linear movement.
8 Cnt 0 ' Invalidates the continuous movement.
9 End ' Ends the program.

*Related functions
Function Explanation page
Designate the movement speed. ........................................................ Page 98, "(5) Acceleration/deceleration time and speed control"
Designate the acceleration/deceleration time. ................................... Page 98, "(5) Acceleration/deceleration time and speed control"
Confirm that the target position is reached. ....................................... Page 100, "(6) Confirming that the target position is reached"
Move with joint interpolation................................................................ Page 93, "(1) Joint interpolation movement"
Move linearly. ...................................................................................... Page 94, "(2) Linear interpolation movement"
Move while drawing a circle or arc. ..................................................... Page 95, "(3) Circular interpolation movement"

4-97 MELFA-BASIC V functions


4MELFA-BASIC V

(5) Acceleration/deceleration time and speed control


The percentage of the acceleration/deceleration in respect to the maximum acceleration/deceleration, and
the movement speed can be designated.
*Command word
Command word Explanation
Accel Designates the acceleration during movement and the deceleration as a percentage (%) in
respect to the maximum acceleration/deceleration speed.
Ovrd Designates the movement speed applied on the entire program as a percentage (%) in respect
to the maximum speed.
JOvrd Designates the joint interpolation speed as a percentage (%) in respect to the maximum speed.

Spd Designate the linear and circular interpolation speed with the hand end speed (mm/s).

Oadl This instruction specifies whether the optimum acceleration/deceleration function should be
enabled or disabled.

*Statement example
Statement example Explanation
Accel................................................................................. Sets both the acceleration and deceleration to 100%.
Accel 60, 80...................................................................... Sets the acceleration to 60% and the deceleration to 80%.
(For maximum acceleration/deceleration is 0.2 sec.
acceleration 0.2/0.6=0.33 sec. deceleration 0.2/0.8=0.25 sec. )
Ovrd 50............................................................................. Sets the joint interpolation, linear interpolation and circular interpolation to 50% of the
maximum speed.
JOvrd 70........................................................................... Set the joint interpolation operation to 70% of the maximum speed.
Spd 30 .............................................................................. Sets the linear interpolation and circular interpolation speed to 30mm/s.
Oadl ON ........................................................................... This instruction enables the optimum acceleration/deceleration function.
*Movement speed during joint interpolation
Controller (T/B) setting value x Ovrd command setting value x JOvrd command setting value.
*Movement speed during linear and circular interpolation
Controller (T/B) setting value x Ovrd command setting value x Spd command setting value.
*Program example
Robot movement *1) Specification of forward/
Hand
:Robot movement CAUTION backward movement of the
:Movement position
hand
P1 The statement examples and program examples
(1)....Maximum speed
are for a vertical 6-axis robot (e.g., RV-6SD).The
hand advance/retrace direction relies on the
(6)70%
Z axis direction (+/- direction) of the tool coor-
(2)..........Maximum speed dinate set for each model.
Refer to the tool coordinate system shown in
50mm

(3)....50% "Confirmation of movement" in the separate


(5)Maximum speed
"From Robot unit setup to maintenance", and
P2 (4)120mm/s P3 designate the correct direction.

MELFA-BASIC V functions 4-98


4MELFA-BASIC V

Program example
Program Explanation
1 Ovrd 100 ' Sets the movement speed applied on the entire program to the maximum speed.
2 Mvs P1 ' (1) Moves at maximum speed to P1.
3 Mvs P2, -50 *1) ' (2) Moves at maximum speed from P2 to position retracted 50mm in hand direction.
4 Ovrd 50 ' Sets the movement speed applied on the entire program to half of the maximum speed.
5 Mvs P2 ' (3) Moves linearly to P2 with a speed half of the default speed.
6 Spd 120 ' Sets the end speed to 120mm/s. (Since the override is 50%, it actually moves at 60 mm/s.)
7 Ovrd 100 ' Sets the movement speed percentage to 100% to obtain the actual end speed of 120mm/s.
8 Accel 70, 70 ' Sets the acceleration and deceleration to 70% of the maximum speed.
9 Mvs P3 ' (4) Moves linearly to P3 with the end speed 120mm/s.
10 Spd M_NSpd ' Returns the end speed to the default value.
11 JOvrd 70 ' Sets the speed for joint interpolation to 70%.
12 Accel ' Returns both the acceleration and deceleration to the maximum speed.
13 Mvs , -50 *1) ' (5) Moves linearly with the default speed for linear movement from the current position (P3) to a position
retracted 50mm in the hand direction.
14 Mvs P1 ' (6) Moves to P1 at 70% of the maximum speed.
15 End ' Ends the program.

*Related functions
Function Explanation page
Move with joint interpolation............................................................................ Page 93, "(1) Joint interpolation movement"
Move linearly. .................................................................................................. Page 94, "(2) Linear interpolation movement"
Move while drawing a circle or arc. ................................................................. Page 95, "(3) Circular interpolation movement"
Continuously move to next position without stopping at target position.......... Page 97, "(4) Continuous movement"

4-99 MELFA-BASIC V functions


4MELFA-BASIC V

(6) Confirming that the target position is reached


The positioning finish conditions can be designated with as No. of pulses. (Fine instruction) This designation
is invalid when using continuous movement.
*Command word
Command word Explanation
Fine Designates the positioning finish conditions with a No. of pulses. Specify a small number of pulses
to allow more accurate positioning.
Mov and Dly After the Mov movement command, command the Dly instruction (timer) to complete positioning .

*Statement example
Statement example Explanation
Fine100 ............................................................................ Sets the positioning finish conditions to 100 pulses.
Mov P1 ............................................................................. Moves with joint interpolation to P1. (The movement completes at the command value
level.)
Dly 0.1 .............................................................................. Positioning after the movement instruction is performed by the timer.

*Program example
Robot movement *1) Specification of forward/
Hand
:Robot movement CAUTION backward movement of the
:Movement position
hand
The statement examples and program examples
P1 (1)
are for a vertical 6-axis robot (e.g., RV-6SD).The
hand advance/retrace direction relies on the
10
(2)
0 m Z axis direction (+/- direction) of the tool coor-
m
(5) (8)
dinate set for each model.
50mm

(3) (6) Refer to the tool coordinate system shown in


"Confirmation of movement" in the separate
(4) Turns output signal bit 17 ON
P2 at finish of positioning to P2. (7) Turns output signal bit 17 "From Robot unit setup to maintenance", and
OFF at finish of positioning to P3.
P3 designate the correct direction.

Program example
Program Explanation
1 Cnt 0 ' The Fine instruction is valid only when the Cnt instruction is OFF.
2 Mvs P1 ' (1) Moves with joint interpolation to P1.
3 Mvs P2, -50 *1) ' (2) Moves with joint interpolation from P2 to position retracted 50mm in hand direction.
4 Fine 50 ' Sets positioning finish pulse to 50.
5 Mvs P2 ' (3) Moves with linear interpolation to P2
(Mvs completes if the positioning complete pulse count is 50 or less.)
6 M_Out(17)=1 ' (4) Turns output signal 17 ON when positioning finish pulse reaches 50 pulses.
7 Fine 1000 ' Sets positioning finish pulse to 1000.
8 Mvs P3, -100 *1) ' (5) Moves linearly from P3 to position retracted 100mm in hand direction.
9 Mvs P3 ' (6) Moves with linear interpolation to P3.
10 Dly 0.1 ' Performs the positioning by the timer.
11 M_Out(17)=0 ' (7) Turns output signal 17 off.
12 Mvs , -100 *1) ' (8) Moves linearly from current position (P3) to position retracted 100mm in hand direction.
13 End ' Ends the program.

*Related functions
Function Explanation page
Move with joint interpolation............................................................................ Page 95, "(3) Circular interpolation movement"
Move linearly. .................................................................................................. Page 94, "(2) Linear interpolation movement"
Continuously move to next position without stopping at target position.......... Page 97, "(4) Continuous movement"

MELFA-BASIC V functions 4-100


4MELFA-BASIC V

(7) High path accuracy control


It is possible to improve the motion path tracking when moving the robot. This function is limited to certain
types of robot. Currently, the Prec instruction is available for vertical multi-joint type 5-axis and 6-axis robots.
*Command word
Command word Explanation
Prec This instruction specifies whether the high path accuracy mode should be enabled or disabled.

*Statement example
Statement example Explanation
Prec On ............................................................................ Enables the high path accuracy mode.
Prec Off............................................................................. Disables the high path accuracy mode.
*Program example
Robot movement *1) Specification of for-
:Robot movement
CAUTION ward/backward movement
Hand of the hand
:Movement position
*1) The statement examples and program exam-
ples are for a vertical 6-axis robot (e.g., RV-
6SD).The hand advance/retrace direction
(1)
P4 (5) P3 relies on the Z axis direction (+/- direction) of
the tool coordinate set for each model.
(7)
(2) (6) Refer to the tool coordinate system shown in
(4) "Confirmation of movement" in the separate
(3) "From Robot unit setup to maintenance", and
P1 P2
designate the correct direction.

•Program example
Program Explanation
1 Mov P1, -50 *1) ' (1) Moves with joint interpolation from P1 to position retracted 50mm in hand direction.
2 Ovrd 50 ' Sets the movement speed to half of the maximum speed.
3 Mvs P1 ' (2) Moves with linear interpolation to P1.
4 Prec On ' The high path accuracy mode is enabled.
5 Mvs P2 ' (3) Moves the robot from P1 to P2 with high path accuracy.
6 Mvs P3 ' (4) Moves the robot from P2 to P3 with high path accuracy.
7 Mvs P4 ' (5) Moves the robot from P3 to P4 with high path accuracy.
8 Mvs P1 ' (6) Moves the robot from P4 to P1 with high path accuracy.
9 Prec Off ' The high path accuracy mode is ÇÑisableÇÑ.
10 Mvs P1, -50 *1) ' (7) Returns the robot to the position 50 mm behind P1 in the hand direction using linear
interpolation.
11 End ' Ends the program.

The Prec instruction improves the tracking accuracy of the robot's hand tip, but low-
CAUTION ers the acceleration/deceleration of the robot movement, which means that the cycle
time may become longer. The tracking accuracy will be further improved if the Cnt
instruction is not included. However, the hand tip speed cannot be guaranteed in this
case.

4-101 MELFA-BASIC V functions


4MELFA-BASIC V

(8) Hand and tool control


The hand open/close state and tool shape can be designated.
*Command word
Command word Explanation
HOpen Opens the designated hand.

HClose Closes the designated hand.

Tool Sets the shape of the tool being used, and sets the control point.

*Statement example
Statement example Explanation
HOpen 1........................................................................... Opens hand 1.
HOpen 2........................................................................... Opens hand 2.
HClose 1........................................................................... Closes hand 1.
HClose 2........................................................................... Closes hand 2.
Tool (0, 0, 95, 0, 0, 0) ...................................................... Sets the robot control point to the position 95 mm from the flange plane in the extension
direction.

*Program example
Robot movement *1) Specification of for-
Hand :Robot movement CAUTION ward/backward movement
:Movement position of the hand
The statement examples and program examples
(1) are for a vertical 6-axis robot (e.g., RV-6SD).The
hand advance/retrace direction relies on the
(5) Z axis direction (+/- direction) of the tool coor-
P1 dinate set for each model.
(2) P2 (6)
(4) (8) Refer to the tool coordinate system shown in
Workpiece
"Confirmation of movement" in the separate
"From Robot unit setup to maintenance", and
(3) Grasps (7) Releases designate the correct direction.
workpiece workpiece

•Program example
Program Explanation
1 Tool(0, 0, 95, 0, 0, 0) ’Sets the hand length to 95 mm.
2 Mvs P1, -50 *1) ’(1) Moves with joint interpolation from P1 to position retracted 50mm in hand direction.
3 Ovrd 50 ’Sets the movement speed to half of the maximum speed.
4 Mvs P1 ’(2) Moves with linear interpolation to P1. (Goes to grasp workpiece.)
5 Dly 0.5 ’ Wait for the 0.5 seconds for the completion of arrival to the target position.
6 HClose 1 ’(3) Closes hand 1. (Grasps workpiece.)
7 Dly 0.5 ’Waits 0.5 seconds.
8 Ovrd 100 ’Sets movement speed to maximum speed.
9 Mvs , -50 *1) ’(4) Moves linearly from current position (P1) to position retracted 50mm in hand direction. (Lifts up
workpiece.)
10 Mvs P2, -50 *1) ’(5) Moves with joint interpolation from P2 to position retracted 50mm in hand direction.
11 Ovrd 50 ’Sets movement speed to half of the maximum speed.
12 Mvs P2 ’(6) Moves with linear interpolation to P2. (Goes to place workpiece.)
13 Dly 0.5 ’ Wait for the 0.5 seconds for the completion of arrival to the target position.
14 HOpen 1 ’(7) Opens hand 1. (Releases workpiece.)
15 Dly 0.5 ’Waits 0.5 seconds.
16 Ovrd 100 ’ Sets movement speed to maximum speed.
17 MVS , -50 *1) ’(8) Moves linearly from current position (P2) to position retracted 50mm in hand direction.
(Separates from workpiece.)
18 End ’Ends the program.

*Related functions
Function Explanation page
Appended statement....................................................................................... Page 274, " Wth (With)"

MELFA-BASIC V functions 4-102


4MELFA-BASIC V

4.1.2 Pallet operation


When carrying out operations with the workpieces neatly arranged (palletizing), or when removing work-
pieces that are neatly arranged (depalletizing), the pallet function can be used to teach only the position of
the reference workpiece, and obtain the other positions with operations.
*Command word
Command word Explanation
Def Plt Defines the pallet to be used.

Plt Obtains the designated position on the pallet with operations.

*Statement example
Statement example Explanation
Def Plt 1, P1, P2, P3, P4, 4, 3, 1 ...................................... Defines to operate pallet No. 1 with a start point = P1, end point A = P2, end point B = P3
and diagonal point = P4, a total of 12 work positions (quantity A = 4, quantity B = 3), and
a pallet pattern = 1(Zigzag).
Def Plt 2, P1, P2, P3, , 8, 5, 2........................................... Defines to operate pallet No. 2 with a start point = P1, end point A = P2, and end point B
= P3, a total of 40 work positions (quantity A = 8, quantity B = 5), and a pallet pattern = 2
(Same direction).
Def Plt 3, P1, P2, P3, , 5, 1, 3........................................... Define that pallet No. 3 is an arc pallet having give five work positions on an arc
designated with start point = P1, transit point = P2, end point = P3 (total three points).
(Plt1, 5) ............................................................................. Operate the 5th position on pallet No. 1.
(Plt1, M1) .......................................................................... Operate position in pallet No. 1 indicated with the numeric variable M1.
The relation of the position designation and a pallet pattern is shown below.

End point B Diagonal point End point B Diagonal point


Transit point
12 11 10 10 11 12 3
2 4 End point
Start point
1 5
7 8 9 7 8 9

6 5 4 4 5 6

1 2 3 1 2 3

Start point End point A Start point End point A


Zigzag Same direction Arc pallet
Pallet pattern = 1 (zigzag) Pallet pattern = 2 (same direction) Pallet pattern = 3 (arc pallet)

4-103 MELFA-BASIC V functions


4MELFA-BASIC V

<Precautions on the posture of position data in a pallet definition>

CAUTION Please read "*Explanation" below if you use position data whose posture compo-
nents (A, B and C) are approximately +/-180 degrees as the start point, end points A
and B, or the diagonal point.

*Explanation
At a position where a posture component (A, B and C) reaches 180 degrees, the component value can
become either +180 degrees or -180 degrees even if the posture is the same. This is due to internal opera-
tion errors, and there is no consistency in which sign is employed.
If this position is used for the start point, end points A and B or diagonal point of the pallet definition and the
same posture component values include both +180 degrees and -180 degrees, the hand will rotate and
move in unexpected ways because the pallet gird positions are calculated by dividing the distance between
-180 degrees and +180 degrees.
Whether a posture component is +180 degrees or -180 degrees, the posture will be the same. Use the
same sign, either + or -, consistently for position data used to define a pallet.
Note also that similar phenomena can occur if posture components are close to +/-180 degrees (e.g., +179
degrees and -179 degrees) as well, if different signs are used. In this case, add or subtract 360 degrees to/
from the posture components and correct the values such that the sign becomes the same. (For example,
to change the sign of -179 degrees to +, add 360 degrees and correct the value to +181 degrees.)
"•Program example 1" shows an example where the posture components of the end points (P3 and P4) and
diagonal point (P5) are adjusted according to the start point (P2) when the hand direction is the same in all
grid points of a pallet (values of the A, B and C axes are identical) (line numbers 10 to 90). "•Program exam-
ple 2" shows an example where values are corrected to have the same sign as the start point (P2) when the
posture components of a pallet definition position are close to +/-180 degrees and the C-axis values of the
end points (P3 and P4) and diagonal point (P5) are either less than -178 degrees or greater than +178
degrees (line numbers 10 to 100). (+/-178 degrees are set as the threshold values of correction.) Use these
program examples as reference for cases where the pallet precision is not very high and the hand direction
thus must be corrected slightly.

*Program example
Robot movement P1
(workpiece supply position) P4 P5
(End point B) (Diagonal point)

13 14 15

Palletize
10 11 12
*1) Specification of forward/
CAUTION backward movement of the
7 8 9
hand
The statement examples and program examples are for a
5 pcs.

4 5 6
vertical 6-axis robot (e.g., RV-6SD).The hand advance/
retrace direction relies on the Z axis direction (+/- direc-
tion) of the tool coordinate set for each model. 1 2 3
Refer to the tool coordinate system shown in "Confirma-
tion of movement" in the separate "From Robot unit setup 3 pcs.
P2 P3
to maintenance", and designate the correct direction. (Start point) Pallet pattern = 2(same direction) (End point A)

MELFA-BASIC V functions 4-104


4MELFA-BASIC V

CAUTION The value of the start point of the pallet definition is employed for the structure flag of
grid points (FL1 of position data) calculated by pallet operation (Plt instruction).
For this reason, if position data with different structure flags are used for each point of
the pallet definition, the desired pallet operation cannot be obtained.
Use position data whose structure flag values are all the same for the start point, end
points A and B and the diagonal point of the pallet definition. The value of the start
position of the pallet definition is employed for the multi-rotation flag of grid points
(FL2 of position data) as well. If position data with different multi-rotation flags are
used for each point of the pallet definition, the hand will rotate and move in unex-
pected ways depending on the robot positions the pallet operation goes through and
the type of interpolation instruction (joint interpolation, line interpolation, etc.). In such
cases, use the TYPE argument of the interpolation instruction to set the detour/short
cut operation of the posture properly and ensure that the hand moves as desired.

4-105 MELFA-BASIC V functions


4MELFA-BASIC V

•Program example 1
The hand direction is the same in all grid points of a pallet (values of the A, B and C axes are identical)
Program Explanation
1 P3.A=P2.A ’Assigns the posture component (A) of P2 to the posture component (A) of P3.
2 P3.B=P2.B ’Assigns the posture component (B) of P2 to the posture component (B) of P3.
3 P3.C=P2.C ’Assigns the posture component (C) of P2 to the posture component (C) of P3.
4 P4.A=P2.A ’Assigns the posture component (A) of P2 to the posture component (A) of P4.
5 P4.B=P2.B ’Assigns the posture component (B) of P2 to the posture component (B) of P4.
6 P4.C=P2.C ’Assigns the posture component (C) of P2 to the posture component (C) of P4.
7 P5.A=P2.A ’Assigns the posture component (A) of P2 to the posture component (A) of P5.
8 P5.B=P2.B ’Assigns the posture component (B) of P2 to the posture component (B) of P5.
9 P5.C=P2.C ’Assigns the posture component (C) of P2 to the posture component (C) of P5.
10 Def Plt 1, P2, P3, P4, P5, 3, 5, 2 ’Defines the pallet. Pallet No. = 1, start point = P2, end point A = P3, end point B = P4,
diagonal point = P5, quantity A = 3, quantity B = 5, pallet pattern = 2 (Same direction).
11 M1=1 ’Substitutes value 1 in numeric variable M1. (M1 is used as a counter.
12 *LOOP ’Designates label LOOP at the jump destination.
13 Mov P1, -50 *1) ’Moves with joint interpolation from P1 to a position retracted 50mm in hand direction.
14 Ovrd 50 ’Sets movement speed to half of the maximum speed.
15 Mvs P1 ’Moves linearly to P1. (Goes to grasp workpiece.)
16 HClose 1 ’Closes hand 1. (Grasps workpiece.)
17 Dly 0.5 ’Waits 0.5 seconds.
18 Ovrd 100 ’Sets movement speed to maximum speed.
19 Mvs , -50 *1) ’Moves linearly from current position (P1) to a position retracted 50mm in hand direction. (Lifts
up workpiece.)
20 P10=(Plt1,M1) ’Operates the position in pallet No. 1 indicated by the numeric variable M1, and substitutes
the results in P10.
21 Mov P10, -50 *1) ’Moves with joint interpolation from P10 to a position retracted 50mm in hand direction.
22 Ovrd 50 ’Sets movement speed to half of the maximum speed.
23 Mvs P10 ’Moves linearly to P10. (Goes to place workpiece.)
24 HOpen 1 ’Opens hand 1. (Places workpiece.)
25 Dly 0.5 ’Waits 0.5 seconds.
26 Ovrd 100 ’Sets movement speed to maximum speed.
27 Mvs , -50 ’Moves linearly from current position (P10) to a position retracted 50mm in hand direction.
(Separates from workpiece.)
28 M1=M1+1 ’Increments numeric variable M1 by 1. (Advances the pallet counter.)
29 If M1<=15 Then *LOOP ’If numeric variable M1 value is less than 15, jumps to label LOOP and repeat process. If
more than 15, goes to next step.
30 End ’Ends the program.

MELFA-BASIC V functions 4-106


4MELFA-BASIC V

•Program example 2
Correction when posture components are close to +/-180 degrees
Program Explanation
1 If Deg(P2.C)<0 Then GoTo *MINUS ’Checks the sign of the posture component (C) of P2 and, if it is -
(negative), jump to the label MINUS line.
2 If Deg(P3.C)<-178 Then P3.C=P3.C+Rad(+360) ’If the posture component (C) of P3 is close to -180 degrees,
adds 360 degrees to correct it to a positive value.
3 If Deg(P4.C)<-178 Then P4.C=P4.C+Rad(+360) ’If the posture component (C) of P4 is close to -180 degrees,
adds 360 degrees to correct it to a positive value.
4 If Deg(P5.C)<-178 Then P5.C=P5.C+Rad(+360) ’If the posture component (C) of P5 is close to -180 degrees,
adds 360 degrees to correct it to a positive value.
5 GoTo *DEFINE ’Jumps unconditionally to the label DEFINE line.
6 *MINUS ’Specifies the label MINUS line as the jump destination.
7 If Deg(P3.C)<+178 Then P3.C=P3.C-Rad(+360) ’If the posture component (C) of P3 is close to +180 degrees,
adds 360 degrees to correct it to a negative value.
8 If Deg(P4.C)<+178 Then P4.C=P4.C-Rad(+360) ’If the posture component (C) of P4 is close to +180 degrees,
adds 360 degrees to correct it to a negative value.
9 If Deg(P5.C)<+178 Then P5.C=P5.C-Rad(+360) ’If the posture component (C) of P5 is close to +180 degrees,
adds 360 degrees to correct it to a negative value.
10 *DEFINE ’Specifies the label DEFINE line as the jump destination.
11 Def Plt 1, P2, P3, P4, P5, 3, 5, 2 ’Defines the pallet. Pallet No. = 1, start point = P2, end point A =
P3, end point B = P4, diagonal point = P5, quantity A = 3,
quantity B = 5, pallet pattern = 2 (Same direction).
12 M1=1 ’Substitutes value 1 in numeric variable M1. (M1 is used as a
counter.
13 *LOOP ’Designates label LOOP at the jump destination.
14 Mov P1, -50 *1) ’Moves with joint interpolation from P1 to a position retracted
50mm in hand direction.
15 Ovrd 50 ’Sets movement speed to half of the maximum speed.
16 Mvs P1 ’Moves linearly to P1. (Goes to grasp workpiece.)
17 HClose 1 ’Closes hand 1. (Grasps workpiece.)
18 Dly 0.5 ’Waits 0.5 seconds.
19 Ovrd 100 ’Sets movement speed to maximum speed.
20 Mvs , -50 *1) ’Moves linearly from current position (P1) to a position retracted
50mm in hand direction. (Lifts up workpiece.)
21 P10=(Plt1,M1) ’Operates the position in pallet No. 1 indicated by the numeric
variable M1, and substitutes the results in P10.
22 Mov P10, -50 *1) ’Moves with joint interpolation from P10 to a position retracted
50mm in hand direction.
23 Ovrd 50 ’Sets movement speed to half of the maximum speed.
24 Mvs P10 ’Moves linearly to P10. (Goes to place workpiece.)
25 HOpen 1 ’Opens hand 1. (Places workpiece.)
26 Dly 0.5 ’Waits 0.5 seconds.
27 Ovrd 100 ’Sets movement speed to maximum speed.
28 Mvs , -50 ’Moves linearly from current position (P10) to a position retracted
50mm in hand direction. (Separates from workpiece.)
29 M1=M1+1 ’Increments numeric variable M1 by 1. (Advances the pallet
counter.)
30 If M1<=15 Then *LOOP ’If numeric variable M1 value is less than 15, jumps to label
LOOP and repeat process. If more than 15, goes to next step.
31 End ’Ends the program.

4-107 MELFA-BASIC V functions


4MELFA-BASIC V

4.1.3 Program control


The program flow can be controlled with branching, interrupting, subroutine call, and stopping, etc.

(1) Unconditional branching, conditional branching, waiting


The flow of the program to a specified step can be set as unconditional or conditional branching.
*Command word
Command word Explanation
GoTo Jumps unconditionally to the designated step.
On GoTo Jumps according to the value of the designated variable. The value conditions follow the
integer value order.
If Then Else Executes the command corresponding to the designated conditions.. The value conditions
(Instructions written in one can be designated randomly. There is only one type of condition per command statement.
step) If the conditions are met, the instruction after Then is executed. If the conditions are not
met, the instruction after Else is executed. They are written in one step.
Several steps can be processed according to the specified variables and specified
If Then
conditions of the values. It is possible to specify any conditions for values. Only one type
Else
of condition is allowed for one instruction. If the conditions are met, the steps following
End If
Then until the Else step are executed. If the conditions are not met, the steps after Else
(Instructions written in
until End IF are executed.
several steps)

Select Jumps according to the designated variable and the designated conditions of that value.
Case The value conditions can be designated randomly.
End Select Multiple types of conditions can be designated per command statement.
Wait Waits for the variable to reach the designated value.
*Statement example
Statement example Explanation
GoTo *FN.................................................... Jumps unconditionally to the label FN step.
ON M1 GoTo *L1, *L2, *L3 ......................... If the numeric variable M1 value is 1, jumps to step *L1, if 2 jumps to step *L2, and if 3 jumps to step
*L3. If the value does not correspond, proceeds to next step.
If M1=1 Then *L1........................................ If the numeric variable M1 value is 1, branches to step *L1. If not, proceeds to the next step.
If M1=1 Then *L2 Else *L2 ......................... If the numeric variable M1 value is 1, branches to step *L1. If not, branches to step *L2.
If M1=1 Then .............................................. If the numerical variable of M1 is 1, the instructions M2 = 1 and M3 = 2 are executed. If the value of M1
M2=1 is different from 1, the instructions M2 = -1 and M3 = -2 are executed.
M3=2
Else
M2=-1
M3=-2
EndIf
Select M1 ................................................... Branches to the Case statement corresponding to the value of numeric variable M1.
Case 10..................................................... If the value is 10, executes only between Case 10 and the next Case 11.
:
Break
Case IS 11................................................. If the value is 11, executes only between Case 11 and the next Case IS <5.
:
Break
Case IS <5 ................................................ If the value is smaller than 5, executes only between Case IS <5 and next Case 6 TO 9.
:
Break
Case 6 TO 9 .............................................. If value is between 6 and 9, executes only between Case 6 TO 9 and next Default.
:
Break
Default ....................................................... If value does not correspond to any of the above, executes only between Default and next End Select.
:
Break Ends the Select Case statement.
End Select ..................................................
Wait M_In(1)=1 Waits for the input signal bit 1 to turn ON.

MELFA-BASIC V functions 4-108


4MELFA-BASIC V

*Related functions
Function Explanation page
Repetition ........................................................................................... Page 109, "(2) Repetition"
Interrupt.............................................................................................. Page 110, "(3) Interrupt"
Subroutine.......................................................................................... Page 111, "(4) Subroutine"
External signal input........................................................................... Page 113, "(1) Input signals"

(2) Repetition
Multiple command statements can be repeatedly executed according to the designated conditions.
*Command word
Command word Explanation
For Next Repeat between For statement and Next statement until designated conditions are satisfied.

While WEnd Repeat between While statement and WEnd statement while designated conditions are
satisfied.

*Statement example
Statement example Explanation
For M1=1 To 10 ................................................................ Repeat between For statement and Next statement 10 times.
: The initial numeric variable M1 value is 1, and is incremented by one with each
Next repetition.

For M1=0 To 10 Step 2 ..................................................... Repeat between For statement and Next statement 6 times.
: The initial numeric variable M1 value is 0, and is incremented by two with each
Next repetition.

While (M1 >= 1) And (M1 <= 10) ...................................... Repeat between While statement and WEnd statement while the value of the numeric
: variable M1 is 1 or more and less than 10.
WEnd
*Related functions
Function Explanation page
Unconditional branching, branching................................................... Page 108, "(1) Unconditional branching, conditional branching,
waiting"
Interrupt.............................................................................................. Page 110, "(3) Interrupt"
Input signal wait ................................................................................. Page 113, "(1) Input signals"

4-109 MELFA-BASIC V functions


4MELFA-BASIC V

(3) Interrupt
Once the designated conditions are established, the command statement being executed can be interrupted
and a designated step branched to.
*Command word
Command word Explanation
Def Act Defines the interrupt conditions and process for generating interrupt.

Act Designates the validity of the interrupt.

Return If a subroutine is called for the interrupt process, returns to the interrupt source line.

*Statement example
Statement example Explanation
Def Act 1, M_In(10)=1 GoSub *SUB1 .............................. If input signal bit 10 is turned on for interrupt number 1, the subroutine on step *SUB1 is
defined to be called after the robot decelerates and stops. The deceleration time
depends on the Accel and Ovrd instructions.
Def Act 2, M_In(11)=1 GoSub *SUB2, L .......................... If input signal bit 11 is turned on for interrupt number 2, the subroutine on step *SUB2 is
defined to be called after the statement currently being executed is completed.
Def Act 3, M_In(12)=1 GoSub *SUB3, S.......................... If input signal bit 12 is turned on for interrupt number 3, the subroutine on step *SUB3 is
defined to be called after the robot decelerates and stops in the shortest time and
distance possible.
Act 1=1 ............................................................................. Enables the priority No. 1 interrupt.
Act 2=0 ............................................................................. Disables the priority No. 1 interrupt.
Return 0............................................................................ Returns to the step where the interrupt occurred.
Return 1............................................................................ Returns to the step following the step where the interrupt occurred.
*Related functions
Function Explanation page
Unconditional branching, branching................................................... Page 108, "(1) Unconditional branching, conditional branching,
waiting"
Subroutine.......................................................................................... Page 111, "(4) Subroutine"
Communication .................................................................................. Page 114, "4.1.5 Communication"

MELFA-BASIC V functions 4-110


4MELFA-BASIC V

(4) Subroutine
Subroutine and subprograms can be used.
By using this function, the program can be shared to reduce the No. of steps, and the program can be cre-
ated in a hierarchical structure to make it easy to understand.
*Command word
Command word Explanation
GoSub Calls the subroutine at the designated step or designated label.

On GoSub Calls the subroutine according to the designated variable number. The value conditions follow
the integer value order. (1,2,3,4,.......)

Return Returns to the step following the step called with the GoSub command.

CallP Calls the designated program. The next step in the source program is returned to at the End
statement in the called program. Data can be transferred to the called program as an argument.

FPrm An argument is transferred with the program called with the CallP command.

*Statement example
Statement example Explanation
GoSub ....................................................... Calls the subroutine from step.
On GoSub................................................... Calls the subroutine from label GET.
ON M1 GoSub *L1, *L2, *L3....................... If the numeric variable M1 value is 1, calls the subroutine at step *L1, if 2 calls the subroutine at step
*L2, and if 3 calls the subroutine at step *L3. If the value does not correspond, proceeds to next step.
Return......................................................... Returns to the step following the step called with the GoSub command.
CallP "10" ................................................... Calls the No. 10 program.
CallP "20", M1, P1 ...................................... Transfers the numeric variable M1 and position variable P1 to the No. 20 program, and calls the
program.
FPrm M10, P10 .......................................... Receives the numeric variable transferred with the CallP in M10 of the subprogram, and the position
variable in P10.

*Related functions
Function Explanation page
Interrupt........................................................................................ Page 110, "(3) Interrupt"
Communication ............................................................................ Page 114, "4.1.5 Communication"
Unconditional branching............................................................... Page 108, "(1) Unconditional branching, conditional branching, waiting"

4-111 MELFA-BASIC V functions


4MELFA-BASIC V

(5) Timer
The program can be delayed by the designated time, and the output signal can be output with pulses at a
designated time width.
*Command word
Command word Explanation
Dly Functions as a designated-time timer.

*Statement example
Statement example Explanation
Dly 0.05 ............................................................................. Waits for only 0.05 seconds.
M_Out(10)=1 Dly 0.5......................................................... Turns on output signal bit 10 for only 0.5 seconds.
*Related functions
Function Explanation page
Pulse signal output............................................................................. Page 113, "(1) Input signals"

(6) Stopping
The program execution can be stopped. The moving robot will decelerate to a stop.
*Command word
Command word Explanation
Hlt This instruction stops the robot and pauses the execution of the program. When the program is
started, it is executed from the next step.

End This instruction defines the end of one cycle of a program. In continuous operation, the program
is executed again from the start step upon the execution of the End instruction. In cycle
operation, the program ends upon the execution of the End instruction when the cycle is
stopped.

*Statement example
Statement example Explanation
Hlt ..................................................................................... Interrupt execution of the program.
If M_In(20)=1 Then Hlt ..................................................... Pauses the program if input signal bit 20 is turned on.
Mov P1 WthIf M_In(18)=1, Hlt.......................................... Pauses the program if input signal bit 18 is turned on while moving toward P1.
End................................................................................... Terminates the program even in the middle of the execution.
*Related functions
Function Explanation page
Appended statement.......................................................................... Page 274, " Wth (With)"

MELFA-BASIC V functions 4-112


4MELFA-BASIC V

4.1.4 Inputting and outputting external signals


This section explains the general methods for signal control when controlling the robot via an external
device (e.g., PLC).
(1) Input signals
Signals can be retrieved from an external device, such as a programmable logic controller.
The input signal is confirmed with a robot status variable (M_In(), etc.) Refer to Page 150, "4.6 Robot status
variables" for details on the robot status variables.
*Command word
Command word Explanation
Wait Waits for the input signal to reach the designated state.

*System variables
M_In, M_Inb, M_Inw, M_DIn

*Statement example
Statement example Explanation
Wait M_In(1)=1 ................................................................. Waits for the input signal bit 1 to turn ON.
M1=M_Inb(20) .................................................................. Substitutes the input signal bit 20 to 27, as an 8-bit state, in numeric variable M1.
M1=M_Inw(5).................................................................... Substitutes the input signal bit 5 to 20, as an 16-bit state, in numeric variable M1.
*Related functions
Function Explanation page
Signal output ................................................................................ Page 113, "(2) Output signals"
Branching with input signal .......................................................... Page 108, "(1) Unconditional branching, conditional branching, waiting"
Interrupting with input signal ........................................................ Page 110, "(3) Interrupt"

(2) Output signals


Signals can be output to an external device, such as a programmable logic controller.
The signal is output with the robot status variable (M_Out(), etc.). Refer to Page 150, "4.6 Robot status vari-
ables" for details on the robot status variables.
*Command word
Command word Explanation
Clr Clears the general-purpose output signal according to the output signal reset pattern in the
parameter.

*System variables
M_Out, M_Outb, M_Outw, M_DOut

*Statement example
Statement example Explanation
Clr 1 ........................................................................... Clears based on the output reset pattern.
M_Out(1)=1 ............................................................... Turns the output signal bit 1 ON.
M_Outb (8)=0 ............................................................ Turns the 8 bits, from output signal bit 8 to 15, OFF.
M_Outw (20)=0.......................................................... Turns the 16 bits, from output signal bit 20 to 35, OFF.
M_Out(1)=1 Dly 0.5 ................................................... Turns the output signal bit 1 ON for 0.5 seconds. (Pulse output)
M_Outb (10)=&H0F ................................................... Turns the 4 bits, from output signal bit 10 to 13 ON, and turns the four bits from 14 to 17 OFF.
*Related functions
Function Explanation page
Signal input ........................................................................................ Page 113, "(1) Input signals"
Timer .................................................................................................. Page 112, "(5) Timer"

4-113 MELFA-BASIC V functions


4MELFA-BASIC V

4.1.5 Communication
Data can be exchanged with an external device, such as a personal computer.
Cannot use in CRnQ series.
*Command word
Command word Explanation
Open Opens the communication line.
Close Closes the communication line.
Print# Outputs the data in the AscII format. CR is output as the end code.
Input# Inputs the data in the AscII format. The end code is CR.
Defines the subroutine to be called when an interrupt is generated from the communication line.
On Com GoSub
The interrupt is generated when data is input from an external device.
Com On Enables the interrupt process from the communication line.
Com Off Disables the interrupt process from the communication line. The interrupt will be invalid even if it
occurs.
Com Stop Stops the interrupt process from the communication line. If there is an interrupt, it is saved, and
is executed after enabled.

*Statement example
Statement example Explanation
Open "COM1:" AS #1................................ Opens the communication line COM1 as file No. 1.
Close #1 .................................................... Closes file No. 1.
Close ......................................................... Closes all files that are open.
Print#1,"TEST" .......................................... Outputs the character string "TEST" to file No. 1.
Print#2,"M1=";M1 ...................................... Output the character string "M1=" and then the M1 value to file No. 2.
Output data example: "M1 = 1" + CR (When M1 value is 1)
Print#3,P1.................................................. Outputs the position variable P1 coordinate value to file No. 3.
Output data example: "(123.7, 238.9, 33.1, 19.3, 0, 0)(1, 0)" +CR
(When X = 123.7, Y=238.9, Z=33.1, A=19.3, B=0, C=0, FL1=1, FL2=0)
Print#1,M5,P5............................................ Outputs the numeric variable M5 value and position variable coordinate value to file No. 1.
M5 and P5 are separated with a comma (hexadecimal, 2C).
Output data example: "8, (123.7, 238.9, 33.1, 19.3, 0, 0)(1, 0)"+CR
(When M5=8, P5 X=123.7, Y=238.9, Z=33.1, A=19.3, B=0, C=0, FL1=1, FL2=0)
Input#1,M3 ................................................ Converts the input data into a value, and substitutes it in numeric variable M3.
Input data example: "8" + CR (when value 8 is to be substituted)
Input#1,P10............................................... Converts the input data into a value, and substitutes it in position variable P10.
Input data example: "8, (123.7, 238.9, 33.1, 19.3, 0, 0)(1, 0)"+CR
(P5 will be X= 123.7, Y=238.9, Z=33.1, A=19.3, B=0, C=0, FL1=1, FL2=0)
Input#1,M8,P6........................................... Converts the first data input into a value, and substitutes it in numeric variable M8. Converts the data
following the command into a coordinate value, and substitutes it in position variable P6. M8 and P6 are
separated with a comma (hexadecimal, 2C)
Input data example: "7,(123.7, 238.9, 33.1, 19.3, 0, 0)(1, 0)"+CR
(The data will be M8 = 7, P6 X=123.7, Y=238.9, Z=33.1, A=19.3, B=0, C=0, FL1=1, FL2=0)
On Com(1) GoSub *SUB3......................... Defines to call step *SUB3 subroutine when data is input in communication line COM1.
On Com(2) GoSub *RECV ........................ Defines to call subroutine at label RECV step when data is input in communication line COM2.
Com(1) On................................................. Enables the interrupt from communication line COM1.
Com(2) Off................................................. Disables (prohibits) the interrupt from communication line COM2.
Com(1) Stop .............................................. Stops (holds) the interrupt from communication line COM1.
*Related functions
Function Explanation page
Subroutine........................................................................................................ Page 111, "(4) Subroutine"
Interrupt............................................................................................................ Page 110, "(3) Interrupt"

MELFA-BASIC V functions 4-114


4MELFA-BASIC V

4.1.6 Expressions and operations


The following table shows the operators that can be used, their meanings, and statement examples.
(1) List of operator
Class Operator Meaning Statement example
Substituti = The right side is P1=P2 ’Substitute P2 in position variable P1.
on substituted in the left P5=P_Curr ’Substitute the current coordinate value in current position variable P5.
side. P10.Z=100.0 ’Set the position variable P10 Z coordinate value to 100.0.
M1=1 ’Substitute value 1 in numeric variable M1.
STS$="OK" ’Substitute the character string OK in the character string variable
STS$.
Numeric + Add P10=P1+P2 ’GSubstitute the results obtained by adding the P1 and P2 coordinate
value Mov P8+P9 elements to position variable P10.
operation M1=M1+1 ’Move to the position obtained by adding the position variable P8 and
STS$="ERR"+"001" P9 coordinate elements.
’Add 1 to the numeric variable M1.
’Add the character string 001 to the character string ERR and
substitute in character string variable STS$.
- Subtract P10=P1-P2 ’Substitute the results obtained by subtracting the P2 coordinate
Mov P8-P9 element from P1 in position variable P10.
M1=M1-1 ’ Move to the position obtained by subtracting the P9 coordinate
element from the position variable P8.
’Subtract 1 from the numeric variable M1.
* Multiply P1=P10*P3 ’Substitute the relative conversion results from P10 to P3 in position
M1=M1*5 variable P1.
’Multiple the numeric variable M1 value by 5.
/ Divide P1=P10/P3 ’Substitute the reverse relative conversion results from P10 to P3 in
M1=M1/2 position variable P1.
’Divide the numeric variable M1 value by 2.
^ Exponential operation M1=M1^2 ’Square the numeric variable M1 value.
\ Integer division M1=M1\3 ’Divide the numeric variable M1 value by 3 and make an integer
(round down).
MOD Remainder operation M1=M1 Mod 3 ’Divide the numeric variable M1 value by 3 and leave redundant.
- Sign reversal P1=-P1 ’Reverse the sign for each coordinate element in position variable P1.
M1=-M1 ’Reverse the sign for the numeric variable M1 value.
Comparis = Compare whether If M1=1 Then *L1 ’Branch to step *L1 if numeric variable M1 value is 1.
on equal If STS$="OK" Then *L2 ’Branch to step *L2 if character string in character string variable STS$ is
operation OK.
<> Compare whether not If M1<>2 Then *L3 ’Branch to step *L3 if numeric variable M1 value is 2.
or equal If STS$<>"OK" Then *L4 ’Branch to step *L4 if character string in character string variable STS$
>< is not OK.
< Compare whether If M1< 10 Then *L3 ’Branch to step *L3 if numeric variable M1 value is less than 10.
smaller If Len(STS$)<3 Then *L4 ’Branch to step *L4 if No. of characters in character string STS$
variable is less than 3.
> Compare whether If M1>9 Then *L3 ’Branch to step *L3 if numeric variable M1 value is more than 9.
larger If Len(STS$)>2 Then *L4 ’Branch to step *L4 if No. of characters in character string variable
STS$ is more than 2.
=< Compare whether If M1<=10 Then *L3 ’Branch to step *L3 if numeric variable M1 value is equal to or less
or equal to or less than If Len(STS$)<=5 Then *L4 than 10.
<= ’Branch to step *L4 if No. of characters in character string variable
STS$ is equal to or less then 5.
=> Compare whether If M1=>11 Then *L3 ’Branch to step *L3 if numeric variable M1 value is equal to or more
or equal to or more than If Len(STS$)>=6 Then *L4 than 11.
>= ’Branch to step *L4 if No. of characters in character string variable
STS$ is equal to or more than 6.

4-115 MELFA-BASIC V functions


4MELFA-BASIC V

Class Operator Meaning Statement example


Logical And Logical AND operation M1=M_Inb(1) And &H0F ’Convert the input signal bit 1 to 4 status and substitute in numeric
operation variable M1. (Input signal bits 5 to 8 remain OFF.)
Or Logical OR operation M_Outb(20)=M1 Or &H80 ’Output the numeric variable M1 value to output signal bit 20 to 27.
Output bit signal 27 is always ON at this time.
Not NOT operation M1=Not M_Inw(1) ’Reverse the status of input signal bit 1 to 16 to create a value, and
substitute in numeric variable M1.
Xor Exclusive OR N2=M1 Xor M_Inw(1) ’Obtain the exclusive OR of the states of M1 and the input signal bits 1
operation to 16, convert into a value and substitute in numeric variable M2.
<< Logical left shift M1=M1<<2 ’Shift numeric variable M1 two bits to the left.
operation
>> Logical right shift M1=M1>>1 ’Shift numeric variable M1 bit to the right.
operation.
Note1) Please refer to Page 117, "Relative calculation of position data (multiplication)".
Note 2) Please refer to Page 117, "Relative calculation of position data (Addition)".

MELFA-BASIC V functions 4-116


4MELFA-BASIC V

(2) Relative calculation of position data (multiplication)


Numerical variables are calculated by the usual four arithmetic operations. The calculation of position vari-
ables involves coordinate conversions, however, not just the four basic arithmetic operations. This is
explained using simple examples.

An example of relative calculation (multiplication)


M ultip lication b etween P variab les
1 P2=(10,5,0,0,0,0)(0,0)
(relative calculation in the tool coord inate system ) 2 P100=P1*P2
3 Mov P1
Tool coord inate system at P1 4 Mvs P100
X P1=(200,150,100,0,0,45)(4,0)
X1
P100
10mm In this example, the hand tip is moved relatively within the
P1 tool coordinate system at teaching position P1. The
5mm P1 values of the X and Y coordinates of P2 become the
Y1 amount of movement within the tool coordinate system.
The relative calculation is given by multiplication of the P
variables. Be aware that the result becomes different if the
order of multiplication is different. The variable that speci-
Y fies the amount of relative movement (P2) should be
Rob ot coord inate system entered lastly.
If the posture axis parts of P2 (A, B, and C) are 0, the pos-
ture of P1 is used as is. If there are non-zero values avail-
able, the new posture is determined by rotating the hand
around the Z, Y, and X axes (in the order of C, B, and A)
relative to the posture of P1. Multiplication corresponds to
addition within the tool coordinate system, while division
corresponds to subtraction within the tool coordinate sys-
tem.

(3) Relative calculation of position data (Addition)


An example of relative calculation(Addition)
Ad d ition of P variab les 1 P2=(5,10,0,0,0,0)(0,0)
(relative calculation in the rob ot coord inate system ) 2 P100=P1+P2
3 Mov P1
4 Mvs P100
X P1=(200,150,100,0,0,45)(4,0)

P100 5mm In this example, the hand is moved relatively within the
robot coordinate system at teaching position P1. The val-
P1
ues of the X and Y coordinates of P2 become the amount
of movement within the robot coordinate system. The rela-
tive calculation is given by addition of the P variables.
If a value is entered for the C-axis coordinate of P2, it is
possible to change the C-axis coordinate of P100. The
Y 10mm resulting value will be the sum of the C-axis coordinate of
Rob ot coord inate system P1 and the C-axis coordinate of P2.

CAUTION)
In the example above, the explanation is made in two dimensions for the sake of simplicity. In actuality, the
calculation is made in three dimensions. In addition, the tool coordinate system changes depending on the
posture.

4-117 MELFA-BASIC V functions


4MELFA-BASIC V

4.1.7 Appended statement


A process can be added to a movement command.
*Appended statement
Appended statement Explanation
Wth Unconditionally adds a process to the movement command.

WthIf Conditionally adds a process to the movement command.

*Statement example
Statement example Explanation
Mov P1 Wth M_Out(20)=1................................................ Turns output signal bit 20 ON simultaneously with the start of movement to P1.
Mov P1 WITHIF M_In(20)=1, Hlt...................................... Stops if the input signal bit 20 turns ON during movement to P1.
Mov P1 WthIf M_In(19)=1, Skip ....................................... Stops movement to P1 if the input signal bit 19 turns ON during movement to P1, and
then proceeds to the next step.

*Related functions
Function Explanation page
Joint interpolation movement ............................................................. Page 93, "(1) Joint interpolation movement"
Linear interpolation movement........................................................... Page 94, "(2) Linear interpolation movement"
Circular interpolation movement ........................................................ Page 95, "(3) Circular interpolation movement"
Stopping ............................................................................................. Page 112, "(6) Stopping"

MELFA-BASIC V functions 4-118


4MELFA-BASIC V

4.2 The difference between MELFA-BASIC V and MELFA-BASIC IV


4.2.1 About MELFA-BASIC V
By the CR750 series controller, MELFA-BASIC V is mounted in the robot programming language. It is
easier to use MELFA-BASIC V than conventional MELFA-BASIC IV.
Explains the difference in the following

4.2.2 The feature of MELFA-BASIC V


MELFA-BASIC V has the following features as compared with MELFA-BASIC IV.
(1) The line number is unnecessary The conventional line number is automatically added as a step num-
ber. Thereby, operation of giving the line number is unnecessary and the efficiency of programming
improves. And the loss in debugging by the mistake of the line number will be reduced.
(2) Usage of the small letter is enabled at the command, the variable name, etc. Thereby, the readability
improves sharply.
(3) The command and the function were added and the function was improved.

4.2.3 Comparison with MELFA-BASIC IV


Comparison of MELFA-BASIC V and IV is shown in Table 4-2.

Table 4-2:Comparison with MELFA-BASIC IV


Item MELFA-BASIC V MELFA-BASIC IV
Program name The English capital letter and numeral of the less than 12 characters
(Recommend the less than four characters because of the O/P display)
The character which can be *Alphabetic character * Alphabetic character
used (the capital letter, the small letter) (it is only the capital letter.) (Usage
* Numeral only to the comment and character
* Mark string data is possible for the small
letter)
* Numeral
* Mark
Step number (line number) Add automatically by program regis- It is necessary to input as a line num-
tration as a step number. ber at programming.
The length of the one line Less than 240 characters Less than 127 characters
Variable name The less than 16 characters. The The less than eight characters. All
English capital letter and the English the alphabetic characters used for
small letter can be used for the vari- the variable name are converted into
able name. the capital letter.
Although the capital letter and the
small letter are handled as the same
variable, converts into the notation
registered first in read-out.
Label name The less than 16 characters. The The less than eight characters. All
English capital letter and the English the alphabetic characters used for
small letter can be used for the label the label name are converted into the
name. capital letter.
Although the capital letter and the
small letter are handled as the same
label name, converts into the notation
registered first in read-out
Command word The definition is given combining the The capital letter defines all.
English capital letter and the English Registration is also registered with
Function small letter. Although it can register the capital letter.
without difference of the capital letter
System status variable
and the small letter, converts into the
notation which defines by the system
in read-out.
The jump destination specified Specify with the label. Specify by the label or the line num-
method of the branch instruc- ber.
tion (GoTo, GoSub)

4-119 The difference between MELFA-BASIC V and MELFA-BASIC IV


4MELFA-BASIC V

4.3 Multitask function


4.3.1 What is multitasking?
The multitask function is explained in this section.
Multitasking is a function that runs several programs as parallel, to shorten the tact time and enable control
of peripheral devices with the robot program.
Multitasking is executed by placing the programs, to be run in parallel, in the items called "slots" (There is a
total of 32 task slots. The maximum factory default setting is 8.).

The execution of multitask operation is started by activating it from the operation panel or by a dedicated
input signal, or by executing an instruction related to multitask operation.

The execution environment for multitasking is shown in Fig. 4-1.

Multitask slot environment


Slot 1 Slot 2 Slot n
Program

Program

Program
:::::

XRUN
XLOAD
XRST
XSTP
XCLR

User base program


External variables, user-defined external variables

Fig.4-1:Multitask slot environment

Execution of a program
A program is executed by placing it in an item called a "slot" and running it. For example, when running
one program (when normally selecting and running the program with the controller's operation panel), the
controller system unconditionally places the program selected with the operation panel in slot 1.

Multitask function 4-120


4MELFA-BASIC V

4.3.2 Executing a multitask


Table 4-3:The multitask can be executed with the following three methods.
Types of execution Explanation

1 Execution from a program This method starts parallel operation of the programs from a random
position in the program using a MELFA-BASIC IV command. The pro-
grams to be run in parallel can be designated, and a program running in
parallel can be stopped.
This method is effective when selecting the programs to be run in paral-
lel according to the program flow.
The related commands include the "XLoad (X Load)", "XRun (X Run)",
"XStp (X Stop)", "XRst (X Reset)" and "XClr (X Clear)" commands. Refer
to Page 162, "4.13 Detailed explanation of command words" in this man-
ual for details.
2 Execution from controller In this execution type, depending on the setting of the information of the
operation panel or external "SLT*" parameter, the start operation starts concurrent execution or con-
input/output signal stant concurrent execution, or starts concurrent execution at error occur-
rence. It is necessary to set the "SLT*" parameter in advance.
This method does not rely on the program flow, and is effective for carry-
ing out simultaneous execution with a preset format, or for sequential
execution.
3 Executing automatically It is possible to start constant execution immediately after turning the
when the power is turned controller's power on. If ALWAYS is specified for the start condition of
on the SLT* parameter, the program is executed in constant execution
mode immediately after the controller's power is turned on.
This eliminates the trouble of starting the programs in task slots used for
monitoring input/output signals from the PLC side.
In addition, it is possible to execute a program from within another pro-
gram that controls movement continuously. In this case, set the value of
the "ALWENA" parameter to 1 in order to execute X** instructions such
as XRun and XLoad, the Servo instruction, and the Reset instruction.

4.3.3 Operation state of each slot


The operation state of each slot changes as shown in Fig. 4-2 according to the operations and commands.
Each state can be confirmed with the robot status variable or external output signal.

Program
selection state Program reset
Start (PSA) XRst
XRST
XRun
XRUN

Cycle stop

Running Waiting
(RUN) (WAI)
Stop
XStp
XSTP
Start
XRun
XRUN
Fig.4-2:Operation state of each slot

4-121 Multitask function


4MELFA-BASIC V

<About parameters related to task slots>


The parameters SLT1 to SLT32 contain information about the name of the program to be executed, opera-
tion mode, start condition, and priority for each of the 32 task slots (set to 8 slots at the factory default set-
ting).
Please refer to Page 384, "5 Functions set with parameters" for details.

*Designation format
Parameter name = 1. program name, 2. operation format, 3. starting conditions, 4. order of priority

*Various setting values and meanings


Item of parameter Default value Setting value Explanation
1. Program name SLT1: Program Possible to set a registered Use the parameter to specify the execution of predeter-
selected on the program mined programs in multitask operation. If the programs to
operation panel. be executed vary depending on conditions, it is possible to
SLT2 to 32: Name specify the program using the XLoad and XRun instructions
of the program to in another program. The programs selected on the opera-
be specified with a tion panel are set if SLT1 is specified.
parameter.
2. Operation format REP REP : Continuous operation If REP is specified, the program is executed again from the
top after the program ends when the final line of the pro-
gram is reached, or by execution of the End instruction.
CYC : One cycle operation If CYC is specified, the program ends after being executed
for one cycle and the selected status is canceled. Change
the SLOTON setting of the parameter if it is desired to keep
the program in the selected status. Please refer to the sec-
tion for SLOTON in Page 384, "5 Functions set with param-
eters" for details.
3. Starting conditions START START : Execution of a pro- Select START when it is desired to start normally. Note1)
gram using the START but-
ton on the operation panel
or the I/O START signal
ALWAYS : Execution of a Use ALWAYS when it is desired to execute the program in
program when the control- constant execution mode. Note, however, that it is not pos-
ler's power is turned on sible to execute movement instructions such as Mov during
constant execution of a program. Programs in constant exe-
cution mode can be stopped via the XStp instruction. They
cannot be stopped via the operation panel and external
input signals, or emergency stop.
Error : Execution of a pro- Specify Error when it is desired to execute a program in
gram when the controller is case an error occurs. It is not possible to execute instruc-
in error status tions for moving the robot, such as the Mov instruction. The
operation mode (REP/CYC) is one-cycle operation (CYC)
regardless of the setting value.
4. Order of priority 1 1 to 31: Number of lines If this number is increased, the number of lines executed at
(number of lines exe- executed at one time at mul- one time for the task slot is increased. For example, if 10 is
cuted in priority) titask operation specified for SLT1, 5 for SLT2, and 1 for SLT3, then after 10
lines of the program specified in SLT1 have been executed,
five lines of the program specified in SLT2 are executed,
and then one line of the program specified in SLT3 is exe-
cuted. Afterward this cycle will be repeated.

Note1) The start operation conducted from the operation panel or by sending the dedicated input signal
START will start the execution of programs of all the task slots whose start conditions are set to
"START" at the same time.
To start the program independently, start in slot units with the dedicated input signal (S1 START to
S32START). In this case, the line No. is preassigned to the same dedicated input/output parameter.
Refer to Page 477, "6.2 Sequencer link I/O function" in this manual for details on the assignment of
the dedicated input/output.

*Setting example
An example of the parameter settings for designating the following items in slot 2 is shown below.
Designation details) Program name: 5
Operation format: Continuous operation
Starting conditions: Always
Order of priority: 10
SLT2=5, REP, ALWAYS, 10

Multitask function 4-122


4MELFA-BASIC V

4.3.4 Precautions for creating multitask program


(1) Relationship between number of tasks and processing time
During multitask operation, it appears as if several robot programs are being processed concurrently. How-
ever, in reality, only one line is executed at any one time, and the processing switches from program to pro-
gram (it is possible to change the number of lines being executed at a time. See the section for the "SLTn"
parameter in Page 384, "5 Functions set with parameters"). This means that if the number of tasks
increases, the overall program execution time becomes longer. Therefore, when using multitask operation,
the number of tasks should be kept to a minimum. However, programs of other tasks executing movement
instructions (the Mov and Mvs instructions) are processed at any time.

(2) Specification of the maximum number of programs executed concurrently


The number of programs to be run in parallel is set with parameter TASKMAX. (The default value is 8.) To
run more than 8 programs in parallel, change this parameter.

(3) How to pass data between programs via external variables


Data is passed between programs being executed in multitask operation via program external variables
such as M_00 and P_00 (refer to Page 139, "4.4.22 External variables") and the user-defined external vari-
ables (refer to Page 140, "4.4.24 User-defined external variables").
An example is shown below. In this example, the on/off status of input signal 8 is judged by the program
specified in task slot 2. Then this program notifies the program specified in task slot 1 that the signal is
turned on by means of the external variable M_00.
<Slot 1>
1 M_00=0 ; Substitute 0 in M_00
2 *L
3 If M_00=0 Then *L ; Wait for M_00 value to change from 0.
4 M_00=0 ; Substitute 0 in M_00
5 Mov P1 ; Proceed with the target work.
6 Mov P2
:
10 GoTo *L ; Repeat from step 2.

<Slot 2> (Program of signals and variables)


1 If M_In(8) <> 1 Then *A1 ; Branch to line 30 if input signal 8 is not ON.
2 M_00=1 ; Substitute 1 in M_00
3 *A1
4 Mov P1 ; Proceed with the target work.
:

(4) Confirmation of operating status of programs via robot status variables


The status of the program running with multitask can be referred to from any slot using the robot status vari-
ables (M_Run, M_Wai, M_Err).
Example) M1 = M_Run (2) The operation status of slot 2 is obtained.
Refer to Page 150, "4.6 Robot status variables" for details on the robot status variables.

(5) The program that operates the robot is basically executed in slot 1.
The program that describes the robot arm's movement, such as with the Mov commands, is basically set
and executed in slot 1. To run the program in a slot other than slot 1, the robot arm acquisition and release
command (GetM, RelM) must be used. Refer to Page 162, "4.13 Detailed explanation of command words"
in this manual for details on the commands.

4-123 Multitask function


4MELFA-BASIC V

(6) How to perform the initialization processing via constantly executed programs
Programs specified in task slots whose start condition is set to ALWAYS are executed continuously (repeat-
edly) if the operation mode is set to REP. Therefore, in order to perform the initialization processing via such
programs, they should be programmed in such a way that the initialization processing is not executed more
than once, for example by setting an initialization complete flag and perform a conditional branch based on
the flag's status. (This consideration is not necessary for task programs whose operation mode is set to
CYC (1 cycle operation) because they are executed only once.)

Mechanism 1 is assigned to slot 1


In the default state, mechanism 1 (robot arm of standard system) is automatically assigned to slot 1.
Because of this, slot 1 can execute the movement command even without acquiring mechanism 1 (with-
out executing GetM command). However, when executing the movement command in a slot other than
slot 1, the slot 1 mechanism acquisition state must be released (RelM command executed), and the
mechanism must be acquired with the slot that is to execute the movement command (execute the GetM
command).

4.3.5 Precautions for using a multitask program


(1) Starting the multitask
When starting from the operation panel or with the dedicated input signal START, the programs in all slots
for which the "start request execution" is set in the slot parameter start conditions will start simultaneously.
When starting with the dedicated input signals S1START to S32START, the program can be started in each
slot. In this case, the line No. is preassigned to the same dedicated input/output parameter. Refer to Page
484, "6.3 Dedicated input/output" for details on the assignment of the dedicated input/output.

(2) Display of operation status


The LEDs of the [START] and [STOP] switches on the operation panel and the dedicated input/output sig-
nals START and STOP display the operation conditions of programs specified in task slots for which the
start conditions are set to "START" in the corresponding "SLT*" parameter. If at least one program is operat-
ing, the LED of the [START] switch lights up and the dedicated output signal START turns on. If all the pro-
grams stop, the LED of the [STOP] switch is lit and the dedicated output signal STOP turns on.
The dedicated output signals S1START to S32START and S1STOP to S32STOP output the operation sta-
tus for each of the task slots. If it is necessary to know the individual operation status, signal numbers can
be assigned to the dedicated input/output parameters and their status checked with the status of the exter-
nal signals.
For a detailed description of assignment of dedicated input/output, please refer to Page 484, "6.3 Dedicated
input/output" of this manual.
The status of programs whose start condition is set to ALWAYS or Error does not affect the LEDs of the
[START] and [STOP] switches. The operation status of programs in constant execution mode can be
checked using the monitoring tool of the PC support software (optional).

Multitask function 4-124


4MELFA-BASIC V

4.3.6 Example of using multitask


An example of the multitask execution is given in this section.
(1) Robot work details.
The robot programs are the "movement program" and "position data lead-in program".
The "movement program" is executed with slot 1, and the "position data lead-in program" is executed with
slot 2. If a start command is output to the sensor while the robot is moving, a request for data will be made
to the personal computer via the position data lead-in program. The personal computer sends the position
data to the robot based on the data request. The robot side leads in the compensation data via the position
data lead-in program.

<Process flow>
<Slot1> <Slot2> <Sensor>

Operation program Position data lead Personal computer


-in program
RS-
Start Start Start
232C

Workpiece pickup P1
Data reception
Sensor start P4
Sensor start
Sensor recognition
Data reception

Above mounting P2
position Data reception
Position data
transmission
Data confirmation
Position data
setting
Workpiece mounting P20

Background execution

P1: Workpiece pickup position (Vacuum timer Dly 0.05)


P2: Workpiece placing position (Release timer Dly 0.05)
P3: Vision pre-position (Do not stop at penetration point Cnt)
P4: Vision shutter position (Do not stop at penetration point Cnt)
P_01: Vision compensation data
P20: Position obtained by adding P2 to vision compensation data (relative operation)

P1

P3 :No acceleration/deceleration

P2
P4 : No acceleration/deceleration
Position to move vision

Y
0

4-125 Multitask function

You might also like