-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathrobot_interface.launch.py
More file actions
159 lines (145 loc) · 5.4 KB
/
Copy pathrobot_interface.launch.py
File metadata and controls
159 lines (145 loc) · 5.4 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from launch import LaunchDescription
from launch_ros.actions import LifecycleNode
import yaml
from launch.actions import RegisterEventHandler, EmitEvent
from launch_ros.event_handlers import OnStateTransition
from launch.event_handlers import OnProcessStart
from launch_ros.events.lifecycle import ChangeState
from launch.events import matches_action
from lifecycle_msgs.msg import Transition
def generate_launch_description():
launch_dir = os.path.dirname(os.path.abspath(__file__))
workspace_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(launch_dir)))))
config_file = os.path.join(workspace_dir, 'robot_config.yaml')
with open(config_file, 'r') as f:
config = yaml.safe_load(f)['robot_configuration']
robot_name = config['robot_name']
network_interface = config['network_interface']
prefix = robot_name + '/' if robot_name != '' else ''
controller_commands_node = LifecycleNode(
package = 'go2_pkg',
executable = 'go2_controller_commands.py',
name='controller_commands_node',
namespace=robot_name,
output='screen'
)
go2_read_node = LifecycleNode(
package = 'go2_pkg',
executable = 'go2_read.py',
parameters=[{'prefix': (prefix)}],
name='robot_read_node',
namespace=robot_name,
output='screen'
)
go2_write_node = LifecycleNode(
package = 'go2_pkg',
executable = 'go2_write.py',
parameters=[{'prefix': (prefix)}],
name='robot_write_node',
namespace=robot_name,
output='screen'
)
go2_video_stream_node = LifecycleNode(
package = 'go2_pkg',
executable = 'go2_video_stream.py',
parameters=[{'prefix': (prefix), 'network_interface': network_interface}],
name='robot_video_stream',
namespace=robot_name,
output='screen'
)
configure_handler_for_write = RegisterEventHandler(
OnProcessStart(
target_action=go2_write_node,
on_start=[EmitEvent(event=ChangeState(
lifecycle_node_matcher=matches_action(go2_write_node),
transition_id=Transition.TRANSITION_CONFIGURE,
))]
)
)
activate_handler_for_write = RegisterEventHandler(
OnStateTransition(
target_lifecycle_node=go2_write_node,
goal_state='inactive',
entities=[EmitEvent(event=ChangeState(
lifecycle_node_matcher=matches_action(go2_write_node),
transition_id=Transition.TRANSITION_ACTIVATE,
))]
)
)
configure_handler_for_read = RegisterEventHandler(
OnProcessStart(
target_action=go2_read_node,
on_start=[EmitEvent(event=ChangeState(
lifecycle_node_matcher=matches_action(go2_read_node),
transition_id=Transition.TRANSITION_CONFIGURE,
))]
)
)
activate_handler_for_read = RegisterEventHandler(
OnStateTransition(
target_lifecycle_node=go2_read_node,
goal_state='inactive',
entities=[EmitEvent(event=ChangeState(
lifecycle_node_matcher=matches_action(go2_read_node),
transition_id=Transition.TRANSITION_ACTIVATE,
))]
)
)
configure_handler_for_commands = RegisterEventHandler(
OnProcessStart(
target_action=controller_commands_node,
on_start=[EmitEvent(event=ChangeState(
lifecycle_node_matcher=matches_action(controller_commands_node),
transition_id=Transition.TRANSITION_CONFIGURE,
))]
)
)
activate_handler_for_commands = RegisterEventHandler(
OnStateTransition(
target_lifecycle_node=controller_commands_node,
goal_state='inactive',
entities=[EmitEvent(event=ChangeState(
lifecycle_node_matcher=matches_action(controller_commands_node),
transition_id=Transition.TRANSITION_ACTIVATE,
))]
)
)
configure_handler_for_video_stream = RegisterEventHandler(
OnProcessStart(
target_action=go2_video_stream_node,
on_start=[EmitEvent(event=ChangeState(
lifecycle_node_matcher=matches_action(go2_video_stream_node),
transition_id=Transition.TRANSITION_CONFIGURE,
))]
)
)
activate_handler_for_video_stream = RegisterEventHandler(
OnStateTransition(
target_lifecycle_node=go2_video_stream_node,
goal_state='inactive',
entities=[EmitEvent(event=ChangeState(
lifecycle_node_matcher=matches_action(go2_video_stream_node),
transition_id=Transition.TRANSITION_ACTIVATE,
))]
)
)
return LaunchDescription(
[
go2_read_node ,
go2_write_node,
controller_commands_node,
go2_video_stream_node,
# Handlers
# configure_handler_for_write,
# activate_handler_for_write,
# configure_handler_for_read,
# activate_handler_for_read,
# configure_handler_for_commands,
# activate_handler_for_commands,
# configure_handler_for_video_stream,
# activate_handler_for_video_stream,
]
)