Skip to content
Snippets Groups Projects
Commit 7928e6a4 authored by Emil Harlan's avatar Emil Harlan
Browse files

a

parent 5335dfb1
No related branches found
No related tags found
No related merge requests found
......@@ -17,17 +17,17 @@ class CommandExecutor(Node):
self.running_processes = {} # Dictionary to store the running processes with custom names
def execute_command_callback(self, msg):
name, command = msg.data.split(" ", 1) # Split the received string into command and name
self.get_logger().info(f"name: '{name}' command: '{command}'.")
name, command, parameter = msg.data.split(" ", 2) # Split the received string into command and name
self.get_logger().info(f"name: '{name}' command: '{command}' parameter: '{parameter}'."")
if command == "kill":
self.kill_node(name) # Call the kill_node method using 'self'
else:
# Execute the launch command in a separate thread
threading.Thread(target=self.execute_command, args=(name, command)).start()
threading.Thread(target=self.execute_command, args=(name, command, parameter)).start()
def execute_command(self, name, command):
def execute_command(self, name, command, parameter):
try:
process_handle = subprocess.Popen(["ros2", "launch", "robot_loc", command], text=True)
process_handle = subprocess.Popen(["ros2", "launch", "robot_loc", command, parameter], text=True)
self.running_processes[name] = process_handle
process_handle.wait() # Wait for the process to finish
if name in self.running_processes:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment