Skip to content

Commit a706252

Browse files
committed
restart controller_node if error and fix namespaced
1 parent effdee5 commit a706252

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

rosbot_controller/config/diff_drive_controller.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
tf_frame_prefix_enable: false
1616
use_namespace_as_sensor_name_prefix: true
1717

18-
sensor_name: <robot_namespace>/imu
18+
sensor_name: imu
1919
frame_id: imu_link
2020
static_covariance_orientation: [1.9e-3, 0.0, 0.0, 0.0, 1.9e-3, 0.0, 0.0, 0.0, 1.9e-3] # Values taken from datasheet
2121
static_covariance_angular_velocity: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0e-3] # Values measured experimentally

rosbot_controller/config/mecanum_drive_controller.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
tf_frame_prefix_enable: false
1616
use_namespace_as_sensor_name_prefix: true
1717

18-
sensor_name: <robot_namespace>/imu
18+
sensor_name: imu
1919
frame_id: imu_link
2020
static_covariance_orientation: [1.9e-3, 0.0, 0.0, 0.0, 1.9e-3, 0.0, 0.0, 0.0, 1.9e-3] # Values taken from datasheet
2121
static_covariance_angular_velocity: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0e-3] # Values based on diff_drive

rosbot_controller/launch/controller.launch.py

+45-23
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Import necessary modules
1617
from launch import LaunchDescription
17-
from launch.actions import DeclareLaunchArgument
18+
from launch.actions import DeclareLaunchArgument, TimerAction
1819
from launch.conditions import UnlessCondition
1920
from launch.substitutions import (
2021
Command,
@@ -27,13 +28,13 @@
2728
from launch_ros.substitutions import FindPackageShare
2829
from nav2_common.launch import ReplaceString
2930

30-
3131
def generate_launch_description():
32+
# Declare launch arguments
3233
namespace = LaunchConfiguration("namespace")
3334
declare_namespace_arg = DeclareLaunchArgument(
3435
"namespace",
3536
default_value="",
36-
description="Namespace for all topics and tfs",
37+
description="Namespace for all topics and TFs",
3738
)
3839

3940
mecanum = LaunchConfiguration("mecanum")
@@ -71,7 +72,7 @@ def generate_launch_description():
7172
[
7273
"'mecanum_drive_controller.yaml' if ",
7374
mecanum,
74-
" else 'diff_drive_controller.yaml'",
75+
" == 'True' else 'diff_drive_controller.yaml'",
7576
]
7677
)
7778

@@ -106,29 +107,35 @@ def generate_launch_description():
106107
simulation_engine,
107108
" namespace:=",
108109
namespace,
110+
# Uncomment the line below if you need to include the 'use_ros2_control' parameter
111+
# " use_ros2_control:=True",
109112
]
110113
)
111114
robot_description = {"robot_description": robot_description_content}
112115

113-
robot_controllers_config = PathJoinSubstitution(
116+
# Controller configurations
117+
# robot_controllers_config = PathJoinSubstitution(
118+
robot_controllers = PathJoinSubstitution(
114119
[
115120
FindPackageShare("rosbot_controller"),
116121
"config",
117122
controller_config_name,
118123
]
119124
)
120125

121-
namespaced_robot_controllers_config = ReplaceString(
122-
source_file=robot_controllers_config,
123-
replacements={"<robot_namespace>": namespace, "//": "/"},
124-
)
126+
# namespaced_robot_controllers_config = ReplaceString(
127+
# source_file=robot_controllers_config,
128+
# replacements={"<robot_namespace>": namespace, "//": "/"},
129+
# )
125130

131+
# Define nodes
126132
control_node = Node(
127133
package="controller_manager",
128134
executable="ros2_control_node",
129135
parameters=[
130136
robot_description,
131-
namespaced_robot_controllers_config,
137+
# namespaced_robot_controllers_config,
138+
robot_controllers,
132139
],
133140
remappings=[
134141
("imu_sensor_node/imu", "/_imu/data_raw"),
@@ -140,6 +147,8 @@ def generate_launch_description():
140147
],
141148
condition=UnlessCondition(use_sim),
142149
namespace=namespace,
150+
respawn=True,
151+
respawn_delay=2.0,
143152
)
144153

145154
robot_state_pub_node = Node(
@@ -150,6 +159,7 @@ def generate_launch_description():
150159
namespace=namespace,
151160
)
152161

162+
# Create spawner nodes
153163
joint_state_broadcaster_spawner = Node(
154164
package="controller_manager",
155165
executable="spawner",
@@ -158,9 +168,9 @@ def generate_launch_description():
158168
"--controller-manager",
159169
controller_manager_name,
160170
"--controller-manager-timeout",
161-
"120",
162-
"--namespace",
163-
namespace,
171+
"10",
172+
# "--namespace",
173+
# namespace,
164174
],
165175
)
166176

@@ -172,9 +182,9 @@ def generate_launch_description():
172182
"--controller-manager",
173183
controller_manager_name,
174184
"--controller-manager-timeout",
175-
"120",
176-
"--namespace",
177-
namespace,
185+
"10",
186+
# "--namespace",
187+
# namespace,
178188
],
179189
)
180190

@@ -186,12 +196,27 @@ def generate_launch_description():
186196
"--controller-manager",
187197
controller_manager_name,
188198
"--controller-manager-timeout",
189-
"120",
190-
"--namespace",
191-
namespace,
199+
"10",
200+
# "--namespace",
201+
# namespace,
192202
],
193203
)
194204

205+
# Wrap the spawner nodes in a TimerAction to delay execution by 2 seconds
206+
delayed_spawner_nodes = TimerAction(
207+
period=1.0,
208+
actions=[
209+
control_node,
210+
joint_state_broadcaster_spawner,
211+
robot_controller_spawner,
212+
imu_broadcaster_spawner,
213+
],
214+
)
215+
216+
# Set 'use_sim_time' parameter
217+
# set_use_sim_time = SetParameter('use_sim_time', value=use_sim)fr
218+
219+
# Assemble the LaunchDescription
195220
return LaunchDescription(
196221
[
197222
declare_namespace_arg,
@@ -200,10 +225,7 @@ def generate_launch_description():
200225
declare_use_gpu_arg,
201226
declare_simulation_engine_arg,
202227
SetParameter("use_sim_time", value=use_sim),
203-
control_node,
204228
robot_state_pub_node,
205-
joint_state_broadcaster_spawner,
206-
robot_controller_spawner,
207-
imu_broadcaster_spawner,
229+
delayed_spawner_nodes, # Add the delayed spawner nodes here
208230
]
209231
)

0 commit comments

Comments
 (0)