-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.m
69 lines (51 loc) · 1.61 KB
/
main.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
% Generate path with specific segments
% Plot created path on Rviz
clear all;
%% set paramters
rosinit;
segments_3d = [6 0 0 0 0 0 0 0 3.2 0 0 0
-6.2 0 0 0 1.2 0 0 0 3.2 0 0 0
];
transit_pose_3d = [2.5 0.5 3.5
-2.8 3.2 3.2
];
params.t0 = 0;
params.T = 2; % segment duration
params.kr = 4; % derivative order
params.frame = 100; % number of frames
params.num_st = 4; % number of constrained states
%% generate trajectory
path = create_3d_qp_trajectory(segments_3d,transit_pose_3d,params);
%% plot
run_trajectory(segments_3d,transit_pose_3d,path);
%%
pose_pub = rospublisher('/pose','geometry_msgs/PoseStamped');
path_pub = rospublisher('/trajectory','nav_msgs/Path');
pause(2);
pose_count = size(path,1);
pose_msg = rosmessage(pose_pub);
path_msg = rosmessage(path_pub);
for i=1:pose_count
path_array_msg(i) = rosmessage('geometry_msgs/PoseStamped');
path_array_msg(i).Pose.Position.X = path(i,2);
path_array_msg(i).Pose.Position.Y = path(i,3);
path_array_msg(i).Pose.Position.Z = path(i,4);
end
path_msg.Header.FrameId = 'map';
path_msg.Poses = path_array_msg;
send(path_pub,path_msg);
t = timer('StartDelay', 4, 'Period', 0.02, 'TasksToExecute', size(path,1), ...
'ExecutionMode', 'fixedRate');
t.TimerFcn = @pub_timer_callback;
t.StartFcn = @init_timer_func;
t.UserData.path = path;
t.UserData.pose_msg = pose_msg;
t.UserData.path_msg = path_msg;
t.UserData.pose_pub = pose_pub;
t.UserData.path_pub = path_pub;
start(t);
function init_timer_func(obj,event)
hdata = obj.UserData;
hdata.i = 1;
obj.Userdata = hdata;
end