From 79f1f0596b8a1660bbdb753532d8d220347f014b Mon Sep 17 00:00:00 2001 From: HamzaKady Date: Thu, 28 Nov 2024 15:25:22 +0100 Subject: [PATCH] Pipeline second version --- roboteam_ai/src/RL/receiveActionCommand.cpp | 1 + roboteam_ai/src/RL/sentActionCommand2.py | 31 +++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 roboteam_ai/src/RL/sentActionCommand2.py diff --git a/roboteam_ai/src/RL/receiveActionCommand.cpp b/roboteam_ai/src/RL/receiveActionCommand.cpp index 75ee97e02..e5c86e40a 100644 --- a/roboteam_ai/src/RL/receiveActionCommand.cpp +++ b/roboteam_ai/src/RL/receiveActionCommand.cpp @@ -3,6 +3,7 @@ #include int main() { + std::string input; // Read each line from stdin diff --git a/roboteam_ai/src/RL/sentActionCommand2.py b/roboteam_ai/src/RL/sentActionCommand2.py new file mode 100644 index 000000000..fb8560b30 --- /dev/null +++ b/roboteam_ai/src/RL/sentActionCommand2.py @@ -0,0 +1,31 @@ +import os +import sys +import subprocess + +def send_action_command(num_attacker, num_defender, num_waller): + # Path to the C++ executable + current_dir = os.path.dirname(os.path.abspath(__file__)) + cpp_executable_path = os.path.join(current_dir, "receiveActionCommand") # Adjust if necessary + + # Start the subprocess + process = subprocess.Popen( + [cpp_executable_path], + stdin=subprocess.PIPE, # Open a pipe to the C++ program + text=True # Use text mode for easier communication + ) + + # Format the data as a comma-separated string + message = f"{num_defender},{num_attacker},{num_waller}\n" + + # Write the message to the subprocess stdin + process.stdin.write(message) + process.stdin.flush() + + print(f"Sent: {message.strip()}") + + # Close the stdin to signal EOF to the subprocess + process.stdin.close() + process.wait() + +if __name__ == "__main__": + send_action_command(2, 3, 1)