-
Notifications
You must be signed in to change notification settings - Fork 0
/
play_trajectory_on_robot.m
73 lines (51 loc) · 1.43 KB
/
play_trajectory_on_robot.m
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
%% init ros
rosshutdown()
rosinit()
robot = Sawyer();
joint_sub = rossubscriber('/robot/joint_states', 'DataFormat','struct');
pubJointCmd = rospublisher('/robot/limb/right/joint_command')
pubGripper = rospublisher('/gripper_command')
% msgJointCmd = rosmessage(pubJointCmd)
% msgJointCmd = rosmessage('intera_core_msgs/JointCommand')
%% gripepr command test
msgGripper = rosmessage(pubGripper)
%open
msgGripper.Data = true;
send(pubGripper, msgGripper)
%gripper close
msgGripper.Data = false;
send(pubGripper, msgGripper)
%% load initial_trajectory and play
init_allMsg=load("initial_trajectory.mat").allMsg;
%go top initial position
gain=0.5;
th=0.2;
executeReference(gain, init_allMsg(1), joint_sub, robot, pubJointCmd, pubGripper, 2, th, false)
%play the trajectory: from top to grip position.
gain=2;
th=0.4;
executeReference(gain, init_allMsg, joint_sub, robot, pubJointCmd, pubGripper, 2, th, false)
%% now, load a trajectory and play
allMsg2=load("trajectory3.mat").allMsg;
%first play initial_trajectory
%now play the trajector (requrire to play initial_trajectory first)
gain=2;
th=0.4;
executeReference(gain, allMsg2, joint_sub, robot, pubJointCmd, pubGripper, 2, th, false)
% reverse_allMsg2=allMsg2(end:-1:1);
gain=2;
th=0.4;
executeReference(gain, allMsg2, joint_sub, robot, pubJointCmd, pubGripper, 2, th, true)
%% helper code
% First position:
% 21
% 22
% 23
% Second position:
% 31
% 32
% 33
% third position
% 41
% 42
% 43