Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Robomaster_pi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Emil Harlan
Robomaster_pi
Commits
5c18be2d
Commit
5c18be2d
authored
1 year ago
by
Emil Harlan
Browse files
Options
Downloads
Patches
Plain Diff
a
parent
c6a47c20
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
robomaster_pi/launch_node.py
+49
-0
49 additions, 0 deletions
robomaster_pi/launch_node.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
50 additions
and
0 deletions
robomaster_pi/launch_node.py
0 → 100644
+
49
−
0
View file @
5c18be2d
import
rclpy
from
rclpy.node
import
Node
from
rclpy.subscription
import
Subscription
from
std_msgs.msg
import
String
from
subprocess
import
Popen
from
concurrent.futures
import
ThreadPoolExecutor
class
LaunchNode
(
Node
):
def
__init__
(
self
):
super
().
__init__
(
"
launch_node
"
)
# Subscribe to the launch_node topic
self
.
subscription
=
self
.
create_subscription
(
String
,
"
launch_node
"
,
self
.
on_message
,
10
)
# Create a dictionary to store the launched processes
self
.
launched_processes
=
{}
# Create a thread pool
self
.
thread_pool
=
ThreadPoolExecutor
(
max_workers
=
10
)
def
on_message
(
self
,
msg
):
# Get the launch command and name from the message
name
=
msg
.
name
command
=
msg
.
command
# If the launch command is "kill", send a SIGINT signal to the process with the given name
if
command
==
"
kill
"
:
if
name
in
self
.
launched_processes
:
os
.
kill
(
self
.
launched_processes
[
name
],
signal
.
SIGINT
)
del
self
.
launched_processes
[
name
]
else
:
# Otherwise, launch the process with the given command
self
.
thread_pool
.
submit
(
self
.
launch_process
,
name
,
command
)
def
launch_process
(
self
,
name
,
command
):
# Launch the process
process
=
Popen
(
command
)
self
.
launched_processes
[
name
]
=
process
def
main
():
rclpy
.
init
()
node
=
LaunchNode
()
rclpy
.
spin
(
node
)
rclpy
.
shutdown
()
if
__name__
==
"
__main__
"
:
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
5c18be2d
...
...
@@ -20,6 +20,7 @@ setup(
tests_require
=
[
'
pytest
'
],
entry_points
=
{
'
console_scripts
'
:
[
"
launch_node =robomaster_pi.launch_node:main
"
"
cmd_vel_combiner = robomaster_pi.cmd_vel_combiner:main
"
,
"
map_update = robomaster_pi.map_update:main
"
,
"
command_executer = robomaster_pi.command_executer:main
"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment