-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataCollection
78 lines (61 loc) · 2.41 KB
/
DataCollection
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
package lbr_fri_ros2;
import com.kuka.roboticsAPI.applicationModel.RoboticsAPIApplication;
import com.kuka.roboticsAPI.applicationModel.tasks.RoboticsAPITask;
import com.kuka.roboticsAPI.controllerModel.Controller;
import com.kuka.roboticsAPI.deviceModel.LBR;
import static com.kuka.roboticsAPI.motionModel.HRCMotions.*;
import com.kuka.roboticsAPI.sensorModel.DataRecorder;
import com.kuka.roboticsAPI.sensorModel.DataRecorder.AngleUnit;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class LBRServer extends RoboticsAPIApplication {
private Controller kuka;
private LBR lbr;
@Override
public void initialize() {
kuka = getController("KUKA_Sunrise_Cabinet_1");
lbr = (LBR) getDevice(kuka, "LBR_iiwa_14_R820_1");
}
private DataRecorder initDataRecorder() {
// Set filename with timestamp
final String fmt = "yyyy-MM-dd_HH-mm-ss";
final String timestamp = new SimpleDateFormat(fmt).format(new Date());
final String fname = String.format("%s.log", timestamp);
// Recorder intrinsic settings
final long timeout = 120; // seconds
final int sampleRate = 100; // ms
// Data recorder builder
DataRecorder recorder = new DataRecorder(fname, timeout, TimeUnit.SECONDS, sampleRate)
.addInternalJointTorque(lbr)
.addCartesianForce(lbr.getFlange(), null)
.addCartesianTorque(lbr.getFlange(), null)
.addCurrentJointPosition(lbr, AngleUnit.Degree);
recorder.enable();
return recorder;
}
@Override
public void run() {
// Create the data recorder object
final DataRecorder recorder = initDataRecorder();
recorder.startRecording();
// Enable hand guiding
lbr.setESMState("1");
getLogger().info("Now HandGuiding");
lbr.move(handGuiding());
// Stop recording and wait for the file to be available
recorder.stopRecording();
recorder.awaitFileAvailable(3, TimeUnit.SECONDS);
// Log the filename for future reference
getLogger().info("Logged data filename: " + recorder.getFileName());
}
@Override
public void dispose() {
lbr.setESMState("1");
super.dispose();
}
public static void main(String[] args) {
LBRServer app = new LBRServer();
app.runApplication();
}
}