Technical Article

ABB Robot Example Programming Tutorial

March 01, 2022 by Shawn Dietrich

ABB robots are programmed using the RAPID language. Investigate an example of the code and structure elements in this part 2 of the robotics programming article series.

ABB IRB 1600 robot
Figure 1. ABB IRB 1600 industrial robot. Image used courtesy of ABB

ABB robotics are introduced in Part 1 of this robotics programming article series.

Robot Applications

Today’s modern industrial robots can be used in many different applications. With the ability to attach a variety of different end effectors, the robot can perform virtually any task. Industrial robots are now being used in almost every manufacturing industry in the world; there are even robotic restaurants popping up where the robot prepares your food right in front of you.

 

ABB robot welding

Figure 2. ABB welding robot cell. Image used courtesy of ABB

 

Example Task

For an example task, I’m going to use a common application used in industrial automation, picking a part from a conveyor and placing it on a dial table. Conveyors are used to transfer assemblies and components to different parts of the machine to be worked on.

With the addition of a rotary dial table, one index position of the dial will have an empty fixture ready to be loaded, one assembly currently ready to be processed, and one finished assembly to be unloaded. The robotic application is to get the unfinished assembly from the conveyor to the dial table loading fixture.

 

Robot grippers

Figure 3. Robots are used for handling all kinds of materials - hard, soft, large, small, heavy, and light. Image used courtesy of RobotWorx

Robot Code

Main Module

The main module is where we will keep all the procedures, or PROC, that deal with the overall robot function and any global variables. From the top down, I like to group similar data types together and define them here. Declare tool data and gripper data here but not robot positions - save that for the motion module.

The WHILE Loop

The while loop is essentially an infinite loop that calls the different robot functions like PICK or PLACE using a series of program numbers that come from the PLC. The loop starts by looking at a digital input program execution variable (diExe) as a yes/no conditional statement. If the number is zero, then we retrieve the correct program number from the PLC. Once the program execution variable is no longer zero we can retrieve and call the specific robot function.

 

WHILE diExe = 0 DO

! Code to retrieve program # from PLC

ENDWHILE

 

An alternative method of looping is by using a GOTO jump from the last line to the first line if a condition is met - in this case, the condition being diExe being false.

 

LoopStart:

! Code to retrieve program # from PLC

If NOT(diExe) GOTO LoopStart;

 

Retrieving A Program Number From The PLC

With modern industrial robots having options for Ethernet/IP, PROFINET, or even EtherCAT sending program numbers to robots is a very simple task. We simply need to map a bit, integer, or even a floating-point number from the Fieldbus map to a variable. For error checking purposes, I like to echo back the value the PLC is sending the robot and have a execute flag to start the process.

When capturing the program number from the PLC we want to verify that get the correct number, so we set up our WHILE loop to save the PLC number to a variable then send that variable back out to the PLC. Then we check the execute variable, if it’s still 0, jump back to the beginning of the loop again. The execute flag is set to 1 by the PLC when the echo matches the program number. Once that flag is set the robot can then call the specific task through the state machine created in the main while loop.

A few key commands of interest include gi and go, referring to group inputs and outputs, which are combinations of discrete digital signals from a PLC combined into a single integer - a perfect recipe for command signals when only a few digital channels are available. ‘Command’ is an input from the PLC, and SetGo is a function that sends the CmdEcho reply back as a group output to the PLC for confirmation.

 

WHILE diExe = 0 DO

  nCmd:=giCommand;

  SetGo goCmdEcho, nCmd;

ENDWHILE

 

Or alternative example using GOTO:

 

LoopStart:

  nCmd:=giCommand;

  SetGo goCmdEcho, nCmd;

If NOT(diExe) GOTO LoopStart;

 

Using a CASE statement is a way to easily and efficiently organize various functions via program numbers as well as set faults or teach pendant messages when invalid program numbers are called.

 

TEST nCmd

CASE 1 :

  FuncFirst();

CASE 2 :

  FuncSecond();

DEFAULT ;

  TPWrite("Invalid Program")\Num:=diExe;

ENDTEST

 

Robot Zones

At the bottom of the main module, I like to put all the world zone declarations and function calls. World zones are a great way of telling the PLC about the robot’s position without interrupting the program flow. These declarations can also be used to recover the robot to a known safe position. There are two data types required for each world zone: wzstationary (a declaration of an allowable work envelope for the robot), and shapedata (the size of the allowable area).

 

Pneumatic gripper

Figure 4. A typical pneumatic gripper used for pick-and-place and work holding tasks.

 

Once the zone variables are defined, you need to create a procedure that will call the world zone shape functions. There are three different shapes of world zones; sphere, box, and cylinder, with an event call for each shape. After the zone is defined and the robot enters this zone an output or variable can be set to true. If the robot goes outside the allowable limits, motion can stop and/or the signal can be inverted.

 

!****************************************************************

! World Zones

!****************************************************************

! Called by Power_On Event

PROC WorldZones()

  WZSphDef\Inside,shpwzHome,pHome.trans,50;

  WZDOSet\Stat,wzHome\Inside,shpwzHome,doAtHome,1;

  WZBoxDef\Outside,shpwzDial,poswzDialLow,poswzDialHigh;

  WZDOSet\Stat,wzClearDial\Inside,shpwzClearDial,doClearDial,1;

ENDPROC

 

No Step Module

ABB has the ability to define how the module will behave at runtime. You can set a module to be a “No Step” module, meaning that the user cannot step through the program one line at a time on the teach pendant. I’ll typically use this style of module for calculations or for functions that will return some value - try not to use it for functions that contain motion. Any code in this module must be tested for correct operation because you will not be able to step through the code to debug it.

 

!*****************************************************************

! Get Pick Position

!*****************************************************************

FUNC robtarget GetPosition(\switch Pick,\switch Place)

  IF Present(Pick) THEN

    TEST nPartType

    CASE 1:

      RETURN pPick_5S3H_RH;

    CASE 2:

      RETURN pPick_5S5H_RH;

    CASE 3:

      RETURN pPick_6S5H_RH;

    DEFAULT:

      BitSet dnFltPend1,2;

    SetGO go03FaultBits1,dnFltPend1;

      TPWrite("Wrong Part type")\num:=nPartType;

    ENDTEST

  ENDIF

 

The Motion Module

This is where all the procedures that deal with moving the robot will reside. The motion module will start with initialization procedures, like sending the robot home or to a service position and ensuring the gripper is in the correct state according to whether a part is or is not in the gripper.

Next, I issue a ‘pounce’ move position, which is a position that is clear of the station tooling but close to the area where the robot will be working to decrease wasted time. When teaching positions, ensure that the robot can move to any pounce position and to the home position without any physical interruptions. Use offsets commands to move from the pounce position to the final work position, with the final work position being a taught position.

 

Vacuum ejector

Figure 5. Vacuum ejectors are used along with vacuum grippers to lift flat objects.

 

An offset command simply adjusts the position of the robot in one or more cartesian axes from the taught position. For example, if you teach a position at x0,y0 then apply an offset of x10,y0 the robot will move to x10,y0. The final move to the taught pick position should be a fine linear move and the robot program pointer will wait at that position until the robot has come to a momentary full stop. Once stopped, we can close the gripper around the part and proceed to retrace our path back to a pounce position.

 

PROC mPickPallet()

!Check Part Present

  CheckGripper\Empty;

!If Gripper Faulted End Command

  IF dnFltPend1<>0 OR dnFltPend2<>0 THEN

    FaultMsg;

    SetCmdDone;

    RETURN;

  ENDIF

!Open Gripper

  Gripper\Open;

!If Gripper Faulted End Command

  IF dnFltPend1<>0 OR dnFltPend2<>0 THEN

    FaultMsg;

    SetCmdDone;

    RETURN;

  ENDIF

!Get Pick Position

  pPallet_Pick:=GetPosition(\Pick);

  MoveL pPallet_App,v2000,z200,tGrip;

  MoveL Offs(pPallet_Pick,-20,0,120),v2000,z50,tGrip\WObj:=wobjPallet;

  MoveL Offs(pPallet_Pick,-20,0,-5),v200,z10,tGrip\WObj:=wobjPallet;

  MoveL offs(pPallet_Pick,0,0,-5),v200,z10,tGrip\WObj:=wobjPallet;

  MoveL pPallet_Pick,v500,fine,tGrip\WObj:=wobjPallet;

  Gripper\close;

!If Gripper Faulted End Command

  IF bDryCycle=FALSE AND dnFltPend1<>0 OR dnFltPend2<>0 THEN

    FaultAck;

    gripper\Open;

    IF dnFltPend1<>0 OR dnFltPend2<>0 THEN

      FaultMsg;

      SetCmdDone;

      RETURN;

    ENDIF

    MoveL Offs(pPallet_Pick,0,0,150),v500,z50,tGrip\WObj:=wobjPallet;

    MoveL pPallet_App,v2000,z200,tGrip;

    MoveL pHome,v2000,z200,tGrip;

  ENDIF

  setdo do48PartPicked,1;

  MoveL Offs(pPallet_Pick,0,0,150),v500,z50,tGrip\WObj:=wobjPallet;

  MoveL pPallet_App,v2000,z200,tGrip;

  SetCmdDone;

ENDPROC

 

Conclusion

The above example of picking up parts and moving them to a new location is a common robot task, but robot functions are only limited by the imagination of the designer. With the right end effector and the right robot model, a robot can complete virtually any task.