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