The first Robotics API program

In your first Robotics API program, you will let the KUKA Light Weight Robot perform some simple motions. These motions will be defined in joint space, thus you will specify goal values for each single joint.

In order to run the program, you have to embed it in a executable Java application that is configured to use the Robotics API as a library. To create such an application, please refer to the instructions provided on the Robotics API website (http://www.roboticsapi.org).

Include the following method in one of your application’s classes and make sure it gets called:

public void firstRoboticsAPIApplication() { 
  try { 
    // every Robotics API application has to load a configuration file 
    // first 
    ApplicationLoader.loadConfigFile("config.xml"); 
 
    // simple access by name, defined in configuration file 
    LWR lwrLeft = RoboticsRegistry.get("LbrLeft", LWR.class); 
 
    // access the LWR's motion interface 
    MotionInterface lwrMotion = lwrLeft.use(MotionInterface.class); 
 
    // move the LWR around 
    lwrMotion.ptp(new double[] { 0, .2, 0, -.2, 0, 0, 0 }).execute(); 
    lwrMotion.ptp(new double[] { 0, -.2, 0, .2, 0, 0, 0 }).execute(); 
    lwrMotion.ptpHome().execute(); 
 
  } catch (MultipleIllegalConfigurationsException e) { 
    e.printStackTrace(); 
    for (int i = 0; i < e.getErrors().size(); i++) { 
      e.getErrors().get(i).printStackTrace(); 
    } 
  } catch (RoboticsException e) { 
    e.printStackTrace(); 
  } finally { 
    ApplicationLoader.unload(); 
  } 
}

For executing this example, you need a Robotics API configuration file named ’config.xml’. Create this file in the root of your Java project and fill it with the following content:

<?xml version="1.0" encoding="UTF-8"?> 
<RobotApplication xmlns="http://schema.isse.de/SoftRobot/RobotApplication.xsd"> 
  <Object type="org.roboticsapi.runtime.softrobot.SoftRobotRuntime" id="softrobot"> 
    <Parameter name="uri" value="http://127.0.0.1:8080/" /> 
  </Object> 
  <Object id="LwrLeft" type="org.roboticsapi.robot.kuka.lwr.LWR"> 
    <Parameter name="runtime" ref="softrobot" /> 
    <Parameter name="driver" 
      type="org.roboticsapi.runtime.softrobot.robot.kuka.lwr.driver.SoftRobotLWRDriver"> 
        <Parameter name="runtime" ref="softrobot" /> 
        <Parameter name="jointCount" value="7" /> 
      <Parameter name="deviceName" value="LwrLeft" /> 
    </Parameter> 
  </Object> 
  <Object type="org.roboticsapi.world.StaticConnection"> 
    <Parameter name="from" ref="Worldorigin"/> 
    <Parameter name="to" ref="LwrLeft" parameter="base" /> 
  </Object> 
</RobotApplication>

Make sure that you are running the SoftRobotRCC on your PC. Then start the program as Java application. If the robot drives are enabled, it will execute the three motions defined in the program. To get visual feedback, you can run the Robotics API Visualization as explained on the Robotics API website.

In this simple application, you have already used several concepts of the Robotics API: You accessed a Device, used a DeviceInterface of that device and also executed Activities created by that interface. Those concepts will be explained in detail in the next sections.