GRL_TeachMode.java
Go to the documentation of this file.
1 package grl.driver;
2 
3 import static com.kuka.roboticsAPI.motionModel.BasicMotions.positionHold;
4 import static com.kuka.roboticsAPI.motionModel.BasicMotions.ptp;
5 
8 import grl.TeachMode;
10 import grl.flatbuffer.ArmState;
12 
13 import java.nio.ByteBuffer;
14 import java.util.concurrent.TimeUnit;
15 import java.util.concurrent.TimeoutException;
16 
17 import org.zeromq.ZMQ;
18 
19 import com.google.flatbuffers.Table;
20 import com.kuka.connectivity.fastRobotInterface.FRIConfiguration;
21 import com.kuka.connectivity.fastRobotInterface.FRIJointOverlay;
22 import com.kuka.connectivity.fastRobotInterface.FRISession;
23 import com.kuka.connectivity.motionModel.smartServo.ISmartServoRuntime;
24 import com.kuka.roboticsAPI.applicationModel.RoboticsAPIApplication;
25 import com.kuka.roboticsAPI.controllerModel.Controller;
26 import com.kuka.roboticsAPI.controllerModel.recovery.IRecovery;
27 import com.kuka.roboticsAPI.deviceModel.JointPosition;
28 import com.kuka.roboticsAPI.deviceModel.LBR;
29 import com.kuka.roboticsAPI.geometricModel.CartDOF;
30 import com.kuka.roboticsAPI.geometricModel.LoadData;
31 import com.kuka.roboticsAPI.geometricModel.PhysicalObject;
32 import com.kuka.roboticsAPI.geometricModel.Tool;
33 import com.kuka.roboticsAPI.motionModel.HandGuidingMotion;
34 import com.kuka.roboticsAPI.motionModel.IMotionContainer;
35 import com.kuka.roboticsAPI.motionModel.MotionBatch;
36 import com.kuka.roboticsAPI.motionModel.controlModeModel.AbstractMotionControlMode;
37 import com.kuka.roboticsAPI.motionModel.controlModeModel.CartesianImpedanceControlMode;
38 import com.kuka.roboticsAPI.motionModel.controlModeModel.JointImpedanceControlMode;
39 import com.kuka.roboticsAPI.motionModel.controlModeModel.PositionControlMode;
40 
41 
42 /**
43  * Creates a FRI Session.
44  */
45 public class GRL_TeachMode extends RoboticsAPIApplication
46 {
47  private ProcessDataManager _processDataManager = null; // Stores variables that can be modified by teach pendant in "Process Data" Menu
48  private Controller _lbrController;
49  private LBR _lbr;
50  private StartStopSwitchUI _startStopUI = null;
51  private ISmartServoRuntime theSmartServoRuntime = null;
52  private AbstractMotionControlMode _activeMotionControlMode;
53  private UpdateConfiguration _updateConfiguration;
54  private IRecovery _pausedApplicationRecovery = null;
55  private PhysicalObject _toolAttachedToLBR;
56  /**
57  * gripper or other physically attached object
58  * see "Template Data" panel in top right pane
59  * of Sunrise Workbench. This can't be created
60  * at runtime so we create one for you.
61  */
62  private Tool _flangeAttachment;
63 
64  @Override
65  public void initialize()
66  {
67  _startStopUI = new StartStopSwitchUI(this);
68  _processDataManager = new ProcessDataManager(this);
69  _lbrController = (Controller) getContext().getControllers().toArray()[0];
70  _lbr = (LBR) _lbrController.getDevices().toArray()[0];
71 
72  // TODO: fix these, right now they're useless
73  //_flangeAttachment = getApplicationData().createFromTemplate("FlangeAttachment");
74  //_updateConfiguration = new UpdateConfiguration(_lbr,_flangeAttachment);
75  _pausedApplicationRecovery = getRecovery();
76 
77  LoadData _loadData = new LoadData();
78  _loadData.setMass(_processDataManager.getEndEffectorWeight());
79  _loadData.setCenterOfMass(_processDataManager.getEndEffectorX(),
80  _processDataManager.getEndEffectorY(),
81  _processDataManager.getEndEffectorZ());
82  _toolAttachedToLBR = new Tool("Tool", _loadData);
83  _toolAttachedToLBR.attachTo(_lbr.getFlange());
84  }
85 
86  @Override
87  public void run()
88  {
89 
90  int statesLength = 0;
91  byte [] data = null;
92  ByteBuffer bb = null;
93 
94  getLogger().info("States initialized...");
95  JointPosition destination = new JointPosition(
96  _lbr.getJointCount());
97 
98 
99  IMotionContainer currentMotion = null;
100 
101  boolean stop = false;
102  boolean newConfig = false;
103 
104  // TODO: Let user set mode (teach/joint control from tablet as a backup!)
105  //this.getApplicationData().getProcessData("DefaultMode").
106 
107 
108  getLogger().warn("Enabling Teach Mode (grav comp)");
109 
110  JointImpedanceControlMode controlMode2 = new JointImpedanceControlMode(7); // TODO!!
111  controlMode2.setStiffnessForAllJoints(0.1);
112  controlMode2.setDampingForAllJoints(0.7);
113  _lbr.moveAsync(positionHold(controlMode2, -1, TimeUnit.SECONDS));
114 
115  HandGuidingMotion handGuidingMotion = new HandGuidingMotion();
116  for (int i = 0; i < 10; i++) {
117  try {
118  _lbr.move(handGuidingMotion);
119  } catch(Exception e) {
120  break;
121  }
122  }
123  }
124 
125 
126 
127 /**
128  * main.
129  *
130  * @param args
131  * args
132  */
133 public static void main(final String[] args)
134 {
135  final GRL_TeachMode app = new GRL_TeachMode();
136  app.runApplication();
137 }
138 
139 }
static void main(final String[] args)