Skip to content

Commit ddef6e3

Browse files
Check and start ROS sim/real sketchup
needs tests
1 parent 2656e5b commit ddef6e3

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

run_this_first.m

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
UI = [];
88
UI.simulation = 1;
99
UI.port = 11311;
10+
UI.real_ros_master_ip = '172.31.1.21';
11+
UI.sim_ros_master_ip = 'localhost';
1012

1113
UI.timestep = 0.001;
1214
UI.motion_duration = 20;
@@ -17,9 +19,9 @@
1719

1820
% User eval
1921
if UI.simulation
20-
UI.ros_master_ip = 'localhost';
22+
UI.ros_master_ip = UI.sim_ros_master_ip;
2123
else
22-
UI.ros_master_ip = '172.31.1.21';
24+
UI.ros_master_ip = UI.real_ros_master_ip;
2325
end
2426

2527
for i=1:7
@@ -133,6 +135,7 @@
133135
end
134136

135137
end
138+
clear tmp
136139
disp('Inverse kinematics done.')
137140

138141
%%
@@ -175,6 +178,7 @@
175178
Quat_path_filtered(i,:) = rotm2quat(tmp(1:3,1:3));
176179
Euler_path_filtered(i,:) = quat2eul(Quat_path_filtered(i,:));
177180
end
181+
clear tmp
178182

179183
%% Null space
180184

@@ -185,7 +189,7 @@
185189
figure(1)
186190

187191
%% ROS
188-
rosinit(UI.masterURI)
192+
run ./scripts/Check_start_ROS.m
189193

190194
%% Simulink
191195
simulink_desired_joint_path = [];

scripts/Check_start_ROS.m

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ROS_STA = [];
2+
ROS_STA.ros_already_running = 0;
3+
ROS_STA.ros_started = 0;
4+
ROS_STA.ros_running = 0;
5+
ROS_STA.no_local_ros_core = 0;
6+
ROS_STA.current_port = NaN;
7+
ROS_STA.current_ros_master_ip = NaN;
8+
9+
try
10+
rosnode list
11+
ROS_STA.ros_already_running = 1;
12+
catch
13+
if UI.simulation && (~exist('core','var') || isempty(core) || ~isvalid(core))
14+
core = ros.Core(UI.port);
15+
end
16+
try
17+
rosinit(UI.masterURI)
18+
catch
19+
warning('Oopsie, rosshutdown then rosinit again..')
20+
rosshutdown
21+
rosinit(UI.masterURI)
22+
end
23+
ROS_STA.ros_started = 1;
24+
end
25+
26+
27+
if ROS_STA.ros_already_running || ROS_STA.ros_started
28+
ROS_STA.ros_running = 1;
29+
end
30+
31+
if ~exist('core','var') || isempty(core)
32+
ROS_STA.no_local_ros_core = 1;
33+
if UI.simulation
34+
error('Simulation selected, but no local core found.')
35+
end
36+
if ~ros.internal.NetworkIntrospection.isMasterReachable(UI.masterURI)
37+
error('Will the real ros master please stand up?')
38+
else
39+
[ROS_STA.current_ros_master_ip, ROS_STA.current_port] = ...
40+
ros.internal.NetworkIntrospection.getHostAndPortFromMasterURI(UI.masterURI);
41+
end
42+
else
43+
ROS_STA.no_local_ros_core = 0;
44+
[ROS_STA.current_ros_master_ip, ROS_STA.current_port] = ...
45+
ros.internal.NetworkIntrospection.getHostAndPortFromMasterURI(core.MasterURI);
46+
if UI.simulation
47+
if strcmp(ROS_STA.current_ros_master_ip, UI.real_ros_master_ip)
48+
error('Simulation selected, but ROS master ip is same as core.')
49+
end
50+
clear tmp
51+
end
52+
end
53+
54+
ROS_STA

0 commit comments

Comments
 (0)