-
Notifications
You must be signed in to change notification settings - Fork 42
/
FRIOverlay.java
153 lines (134 loc) · 5.72 KB
/
FRIOverlay.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package application;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import com.kuka.connectivity.fastRobotInterface.ClientCommandMode;
import com.kuka.connectivity.fastRobotInterface.FRIConfiguration;
import com.kuka.connectivity.fastRobotInterface.FRIJointOverlay;
import com.kuka.connectivity.fastRobotInterface.FRISession;
import com.kuka.roboticsAPI.applicationModel.RoboticsAPIApplication;
import com.kuka.roboticsAPI.controllerModel.Controller;
import com.kuka.roboticsAPI.deviceModel.LBR;
import com.kuka.roboticsAPI.motionModel.PositionHold;
import com.kuka.roboticsAPI.motionModel.controlModeModel.JointImpedanceControlMode;
import com.kuka.roboticsAPI.uiModel.ApplicationDialogType;
import com.kuka.roboticsAPI.executionModel.CommandInvalidException;
/**
* Moves the LBR in a start position, creates an FRI-Session and executes a
* PositionHold motion with FRI overlay. During this motion joint angles and
* joint torques can be additionally commanded via FRI.
*/
public class FRIOverlay extends RoboticsAPIApplication
{
private Controller _lbrController;
private LBR _lbr;
private String _clientName;
@Override
public void initialize()
{
_lbrController = (Controller) getContext().getControllers().toArray()[0];
_lbr = (LBR) _lbrController.getDevices().toArray()[0];
// **********************************************************************
// *** change next line to the FRIClient's IP address ***
// **********************************************************************
_clientName = "192.170.10.1";
}
@Override
public void run()
{
// configure and start FRI session
FRIConfiguration friConfiguration = FRIConfiguration.createRemoteConfiguration(_lbr, _clientName);
// for torque mode, there has to be a command value at least all 5ms
friConfiguration.setSendPeriodMilliSec(5);
friConfiguration.setReceiveMultiplier(1);
getLogger().info("Creating FRI connection to " + friConfiguration.getHostName());
getLogger().info("SendPeriod: " + friConfiguration.getSendPeriodMilliSec() + "ms |"
+ " ReceiveMultiplier: " + friConfiguration.getReceiveMultiplier());
FRISession friSession = new FRISession(friConfiguration);
// wait until FRI session is ready to switch to command mode
try
{
friSession.await(10, TimeUnit.SECONDS);
}
catch (final TimeoutException e)
{
getLogger().error(e.getLocalizedMessage());
friSession.close();
return;
}
getLogger().info("FRI connection established.");
int modeChoice = getApplicationUI().displayModalDialog(ApplicationDialogType.QUESTION, "Choose control mode", "Torque", "Position", "Wrench");
ClientCommandMode mode = ClientCommandMode.TORQUE;
if (modeChoice == 0) {
getLogger().info("Torque control mode chosen");
mode = ClientCommandMode.TORQUE;
}
else if (modeChoice == 1) {
getLogger().info("Position control mode chosen");
mode = ClientCommandMode.POSITION;
}
else if (modeChoice == 2) {
getLogger().warn("Wrench control mode not supported yet. Using position control mode instead");
mode = ClientCommandMode.POSITION;
}
else {
getLogger().warn("Invalid choice: using position control mode");
mode = ClientCommandMode.POSITION;
}
FRIJointOverlay jointOverlay = new FRIJointOverlay(friSession, mode);
int choice = getApplicationUI().displayModalDialog(ApplicationDialogType.QUESTION, "Choose stiffness for actuators", "0", "20", "50", "150", "300", "500");
double stiffness = 0.;
if (choice == 0) {
getLogger().info("Stiffness of '0' chosen");
stiffness = 0.;
}
else if (choice == 1) {
getLogger().info("Stiffness of '20' chosen");
stiffness = 20.;
}
else if (choice == 2) {
getLogger().info("Stiffness of '50' chosen");
stiffness = 50.;
}
else if (choice == 3) {
getLogger().info("Stiffness of '150' chosen");
stiffness = 150.;
}
else if (choice == 4) {
getLogger().info("Stiffness of '300' chosen");
stiffness = 300.;
}
else if (choice == 5) {
getLogger().info("Stiffness of '500' chosen");
stiffness = 500.;
}
else {
getLogger().warn("Invalid choice: setting stiffness to '20'");
stiffness = 20.;
}
// start PositionHold with overlay
JointImpedanceControlMode ctrMode = new JointImpedanceControlMode(stiffness, stiffness, stiffness, stiffness, stiffness, stiffness, stiffness);
if (mode == ClientCommandMode.TORQUE)
ctrMode.setDampingForAllJoints(0.);
try {
PositionHold posHold = new PositionHold(ctrMode, -1, TimeUnit.SECONDS);
getLogger().info("Robot is ready for ROS control.");
_lbr.move(posHold.addMotionOverlay(jointOverlay));
}
catch(final CommandInvalidException e) {
getLogger().error("ROS has been disconnected.");
}
// done
friSession.close();
}
/**
* main.
*
* @param args
* args
*/
public static void main(final String[] args)
{
final FRIOverlay app = new FRIOverlay();
app.runApplication();
}
}