Kuka LBR iiwa Programming Learn Module | UNSW Making UNSW Making UNSW Making Home Our Network Our Network Our Machines Our Makerspaces Get Started Badges Badges Badge Training Learn About About Safety News Login UNSW Making Home Learn Kuka LBR iiwa Programming Learn Module Kuka LBR iiwa Programming Learn Module A basic start to get you programming our robots. For this learning module, you will need: (Highly recommended) KUKA LBR iiwa Basic Learn Module Completing the Collaborative Robotics Badge to allow you access to the Design Futures Lab (Beneficial) - some knowledge of JAVA for programming in Sunrise (Beneficial) - some knowledge of Grasshopper for KUKA|prc Content Module 1 - Using Sunrise Module 2 - Using KUKA|prc Module 3 - Mapping I/O in Workbench Module 4 - Coming one day... SprutCAM Module 5 - Coming one day... ROS Module 1 ______________________________________________________________________ Using Sunrise to program the KUKA iiwa What is Sunrise Sunrise work bench is an IDE (integrated development environment) for programming KUKA’s range of collaborative robots. We use Sunrise to configure and manage the robots. It also provides tools for coding applications to run on the robots. Sunrise supports the Java programming language. Writing Java is a direct way of programming the Collaborative Robots, and we recommend it for Pick and Place applications. Whilst writing Java code can be tricky for non programmers (not to mention, experienced programmers also find Java quite tricky!) you don’t need a lot to get going with the basics. Writing Java on your own PC Whilst the only place you can compile and test your code is in Sunrise, it is possible to compose your code in any text editor, we recommend using visual studio code . For undertaking a major programming project though it would be best to try using an IDE. We would recommend using Eclipse IDE to write your Java code as it it the IDE that Sunrise is based on. Learn Java Online This module only shows you the basics needed for a simple application, if you are confused, something isn't working for you, or you would like to use more advanced programming language features like creating your own variables or using an IF statements we recommend learning the basics of Java programming. You would be surprised what progress you can make in an hour and how much of a professional benefit programming skills can be. UNSW students have access to linked in learning, and you get get a 30 Day trial of Code Academy Learn Java on LinkedIn Learning Learn Java on Code Academy Programming hints for absolute beginners Single line comments Comments are messages you leave yourself and other programmers in the code. They have no impact on the code itself. There are single line comments (indicated with a //) // I am a single line comment! Multi Line Comments Multi line comments are useful when you have a lot to say, but even more so when you want to temporarily disable some code without deleting it, in case you want to re enable it later. /*
And I am a
multi-line comment!
*/ Print Line Print line will pass a message to the Kuka Controller and display whilst your application is running. We like to include this for everything we do, it helps us determine what’s going on in the code as we run our programs. System.out.println("Hello, world!"); White Space and Indentation White space in the code is completely ignored. So do not worry about the way your code is visually structured on the screen. Try and keep it organised though using indenting and line breaks to help you see the different parts of your code The Anatomy of a Robot Application Sample Pick and Place Application Here is a sample application for a basic 'Pick and Place' application using the Robotiq Gripper 2F85 and the Vacuum Picker. You can use one of these as the basis of your application. See below for a description of the structure. Download PickAndPlace2FF85Gripper Download PickAndPlaceVacuum Package This is the name of the package (or folder) of which your application is located. package application; Import This section references the code (various classes and APIs etc ) used by the application. The robot needs this information to move, operate the gripper, send information to the controller etc. It's best not to take anything away from this list. If it's not needed in your application it will tell you but it doesn't effect the application. If you are planning to utilise more advanced classes and methods, you may need to import code here. + and - In many editors, you will see + and - signs to the left of your text that will allow you to expand and collapse the content. You can do this to avoid accidentally editing content. import javax.inject.Inject;
import robotiq.gripper.twoFingerF85.RobotiqGripper2F85;
import com.kuka.roboticsAPI.applicationModel.RoboticsAPIApplication;
import static com.kuka.roboticsAPI.motionModel.BasicMotions.*;
import com.kuka.roboticsAPI.controllerModel.Controller;
import com.kuka.roboticsAPI.deviceModel.LBR;
import com.kuka.roboticsAPI.geometricModel.ObjectFrame; Header This is the application header. This needs to exactly match your file name. { Notice the squiggly brackets? These encapsulate the entire class (and every class within this class) its important to ensure these brackets and the content get put in the correct place. Notice there's another bracket at the end of your application. } public class PickAndPlace2FF85Gripper extends RoboticsAPIApplication { Inject This is where new variables can be declared. Initialize This is where we set and initial values for variables needed throughout the application. (for basic pick and place applications you wont need to use this generally) @Inject
private Controller kukaController;
private LBR lBR_iiwa_14_R820_1;
private RobotiqGripper2F85 robotiqGripper;
@Override
public void initialize() {
kukaController = (Controller) getContext().getControllers().toArray()[0];
lBR_iiwa_14_R820_1 = (LBR) kukaController.getDevices().toArray()[0];
robotiqGripper = new RobotiqGripper2F85(kukaController); Run Finally! This is where the sequence of the program takes place. For beginners, this is the main section of code you will work in. Have a look at one of the blocks of code surrounded by white space, this is the basic structure we recommend: Start by printing to the Controller what your doing, this is super handy for bug fixing and just generally know what the robot is doing. System.out.println("Move To Pickup Position"); Then add a comment for your own reference so you remember what each part of the code is doing // Move to Pickup position Finally add the code for the movement you want to make. lBR_iiwa_14_R820_1.move(ptp(getApplicationData().getFrame("/PickAndPlace1/Pickup/PickupSafe")).setJointVelocityRel(0.4)); lBR_iiwa_14_R820_1.move(ptp(getApplicationData().getFrame("/PickAndPlace1/Pickup")).setJointVelocityRel(0.25)); You can see here the code is directing the iiwa robot to move point to point (ptp) to a frame (or point) you have created. The.setJointVelocityRel(0.4) on the end means the robot will complete this motion at 40% of it's full speed. public void run() {
robotiqGripper.activate();
robotiqGripper.waitForInitialization();
robotiqGripper.fullyOpen();
//Can be used to Fully open the gripper
lBR_iiwa_14_R820_1.move(ptpHome());
System.out.println("Move To Start Position");
// Move to Start position
lBR_iiwa_14_R820_1.move(ptp(getApplicationData().getFrame("/PickAndPlace1/Start")).setBlendingRel(.5).setJointVelocityRel(0.4));
System.out.println("Move To Pickup Position");
// Move to Pickup position
lBR_iiwa_14_R820_1.move(ptp(getApplicationData().getFrame("/PickAndPlace1/Pickup/PickupSafe")).setJointVelocityRel(0.4));
lBR_iiwa_14_R820_1.move(ptp(getApplicationData().getFrame("/PickAndPlace1/Pickup")).setJointVelocityRel(0.25));
System.out.println("Gripper Closing");
// Grip Box
robotiqGripper.moveToCM(65, 10, 1);
robotiqGripper.waitForMoveEnd(); Sample Blocks of Code Point to Point Motion System.out.println("Point to Point motion");
// This is an example ptp motion
lBR_iiwa_14_R820_1.move(ptp(getApplicationData().getFrame("/yourframe/inserthere")); Linear Motion System.out.println("Linear Motion");
// This is an example Linear Motion
lBR_iiwa_14_R820_1.move(lin(getApplicationData().getFrame("/yourframe/inserthere"))); Circular Motion System.out.println("Circular Motion");
// This is an example circular motion
lBR_iiwa_14_R820_1.move(circ(getApplicationData().getFrame("/yourframe/inserthere"), getApplicationData().getFrame("/yourframe/inserthere"))); Spline Motion System.out.println("Spline Motion");
// Example spline motion
Spline mySpline = new Spline(
spl(getApplicationData().getFrame("/yourframe/inserthere")),
spl(getApplicationData().getFrame("/yourframe/inserthere")),
spl(getApplicationData().getFrame("/yourframe/inserthere")),
spl(getApplicationData().getFrame("/yourframe/inserthere")));
lBR_iiwa_14_R820_1.move(mySpline); Spline with Circular and Linear Motions System.out.println("Spline Motion with circular and linear motions");
// Example Spline Motion with circular and linear motions included
Spline mySpline2 = new Spline (
spl(getApplicationData().getFrame("/yourframe/inserthere")),
spl(getApplicationData().getFrame("/yourframe/inserthere")),
spl(getApplicationData().getFrame("/yourframe/inserthere")),
spl(getApplicationData().getFrame("/yourframe/inserthere")),
circ(getApplicationData().getFrame("/yourframe/inserthere"),
getApplicationData().getFrame("/yourframe/inserthere")),
spl(getApplicationData().getFrame("/yourframe/inserthere")),
lin(getApplicationData().getFrame("/yourframe/inserthere")));
lBR_iiwa_14_R820_1.move(mySpline2); Blend and Velocity System.out.println("Example Linear Motion with Velocity set to 0.4");
// Example linear motion at 40% joint velocity
lBR_iiwa_14_R820_1.move(lin(getApplicationData().getFrame("/yourframe/inserthere")).setJointVelocityRel(0.4));
System.out.println("Example Point to Point Motion with Blend set to 0.5");
//Example Linear motion with a blend of 50% at a velocity of 25%
lBR_iiwa_14_R820_1.move(ptp(getApplicationData().getFrame("/yourframe/inserthere")).setBlendingRel(.5).setJointVelocityRel(0.25)); Module 2 ______________________________________________________________________ KUKA PRC What is KUKA prc? The International Association for Robots in Architecture has created a plug in for Grasshopper called KUKA|prc. The aim of the association and KUKA|prc is to make the programming of KUKA Industrial robots and now also KUKA collaborative robots accessible to the creative industry. PRC stands for Procedural Robot Control. KUKA|prc builds upon Grasshoppers accessible visual programming system which is part of the CAD software Rhino. It allows for parametric control with accurate simulation and quick optimisation. Rhino File Setup Rhino must always be configured for the metric system using millimetres when using KUKA|prc. The easiest way to do this is when starting a new file select “Small Objects – Millimeters” template. Once in Rhino select the Grasshopper icon from the right of the menu bar. If you have the KUKA|prc plug in loaded it will be appear as a tab in Grasshopper. The KUKA|prc User Interface The KUKA|prc menu is broken up into 5 shelves. These shelves are where the objects are listed by categories. Each shelf has sub tabs which show a limited numbers of items. To access all available components /parameters you may sometimes need to click on the black title bar at the bottom. There are six shelves which organise the components in KUKA|prc, they are: Core: The main robotic core component are shown in this box. There are also the components for the motion types (linear, spline, etc) Virtual Robot: The various KUKA robots are here. We will be using the KUKA iiwa Virtual Tools: Approach and Retract components are here (these determine how the robot should move after a toolpath has completed). There are also components for dividing up curves and surfaces and generating robotic motion based on that division. Toolpath Utilities: The tools (end effectors) are here. We'll mostly be using the Custom Tool component. Utilities: The components dealing with input and outputs are stored here Online: This assists in exporting your files The KUKA|prc CORE The component you always use in every definition is called the Core. It is what generates the KUKA Robot Language (KRL) code that runs on the robot. It also provides the graphical simulation of the robot motion inside Rhino. Everything else gets wired into this component. The Core component takes five inputs. These are: SIM - This is a numeric value. Attach a default slider with values from 0.00 to 1.00 to control the simulation. CMDS - This is the output of one of the KUKA|prc Command components. For example a 'Point to Point' motion command could be wired into this socket. TOOL - This is the tool (end effector) to use. It gets wired from one of the Tool components available in the Virtual Tools panel. Usually you'll use the KUKA|prc Custom Tool option and wire in a Mesh component that will show the tool geometry in the simulation. ROBOT - This is the robot to use. The code will be generated for this robot and the simulation will graphically depict this robot. You'll wire in one of the robots from the Virtual Robot panel. For our cobots you will wire in the LBR14 R820. COLLISION - This is an optional series of meshes that define collision geometry. Enable collision checking in the KUKA|prc settings to make use of this. Some users suggest that collision checking has a large, negative impact on KUKA|prc performance. There are two output as well: GEO: This is the geometry of the robot at the current position - as a set of meshes. You can right-click on this socket and choose 'Bake' to generate a mesh version of the robot for any position in the simulation. You could use this for renderings of the robot. ANALYSIS: This provides detailed analysis of the simulation values. This has to be enabled for anything to appear. You enable it in the Settings dialog, Advanced page, Output Analysis Values checkbox. Then use the Analysis component from the Utilities panel. For example if you wire a Panel component into the Axis Values socket you'll see all the axis values for each command that's run. Settings The gray KUKA|prc Settings label at the bottom of the Core component gives you access to its settings. Simply left click on the label and the dialog will appear. The settings are organised into pages which you select from along the top edge of the dialog (Settings, Advanced, and Analysis). The dialog is modeless which means you can operate Rhino while it is open. To see the effect of your changes in the viewport click the Apply button. Basic Setup There is a common set of components used in nearly all definitions for use with the robots. Here is an example of a very typical setup SIM SLIDER: The simulation Slider goes from 0.000 to 1.000. Dragging it moves the robot through all the motion specified by the Command input. It's often handy to drag the right edge of this slider to make it much wider than the default size. This gives you greater control when you scrub to watch the simulation. You may also want to increase the precision from a single decimal point to several (say 3 or 4). Without that precision you may not be able to scrub to all the points you want to visualize the motion going through. You can also add a Play/Pause component. This lets you simulate without dragging the time slider. CMDS: The components which gets wired into the CMDS slot of the Core is really the heart of your definition and will obviously depend on what you are intending the robot to do. In the example above a simple Linear Move component is wired in. TOOL: We normally use custom tools. Therefore a Mesh component gets wired into the KUKA|prc Custom Tool component (labelled TOOL above). This gets wired into the TOOL slot of the Core. The Mesh component points to a mesh representation of the tool drawn in the Rhino file. See the section below on Tool orientation and configuration. ROBOT: The robots we have are LBR14 R820 So that component is chosen form the Virtual Robots panel. It gets wired into the ROBOT slot of the Core. COLLISION: If you want to check for collisions between the robot and the workcell (table) wire in the meshes which represent the workcell. As noted above this has a large negative impact on performance so use this only when necessary. Robot Position and Orientation Start Position / End Position Initial Posture Motion Types Tool Setup Code Output The save your file ready to export to the robot. Under settings name the project and select a usb to save your file to. You should keep your name simple with no spaces Make sure under advanced > code that sunrise is the export code and that the create frames is not ticked if you want to run straight on the robot. Ticked if you want the info to create frames in java. Plug the USB straight into the robot and run the application PRCRun_Xml Module 3 ______________________________________________________________________ Mapping Inputs and Outputs (I/O) in Workbench What are Inputs and Outputs? Mapping I/O's in Workbench Loading I/O in Sunrise Setting up I/O's on the Pendant Module 4 ______________________________________________________________________ SprutCAM This module is coming later next year. In the meantime here's an introductory video about SprutCAM Module 5 ______________________________________________________________________ ROS - (Robot Operating System) This module is coming later next year. In the meantime here's a video explaining ROS Our Makerspaces Design Futures Lab Michael Crouch Innovation Centre (MCIC) Engineering Makerspaces Find Makerspaces Badges Machines Training Connect Get Started Get Involved Online Tutorials About About UNSW Making New to UNSW Making? Safety Contact Us × Date/Time: Location: Seats booked: