From 2fc239e50620fe57c2989e7af9d8ce388a969758 Mon Sep 17 00:00:00 2001 From: Kirill Mitkovskii Date: Fri, 22 Sep 2023 20:13:48 +0200 Subject: [PATCH 1/3] [cli-tool]: add subcommands add, remove, status, result --- README.md | 8 +++- .../data/{config.json => global_config.json} | 0 cli_tool/src/cycleon/cmd.py | 44 +++++++++++++++---- .../src/cycleon/network/message/response.py | 5 ++- 4 files changed, 46 insertions(+), 11 deletions(-) rename cli_tool/data/{config.json => global_config.json} (100%) diff --git a/README.md b/README.md index 835c0a6..7cfbb37 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Current project is under active development and is not ready yet to be in use. ~/cycle_on/service$ cmake --build build ~/cycle_on/service$ (cd build && ctest) -~/cycle_on/service$ ./build/src/hello_world +~/cycle_on/service$ ./build/src/service ``` ### cli-tool notes @@ -26,7 +26,11 @@ $ python3 -m pip install build $ python3 -m pip install setuptools $ python3 -m pip install --user virtualenv --force-reinstall -~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py data/config.json +~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py add --reuse_global_config +~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py remove id +~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py status id +~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py result id + ~/cycle_on/cli_tool$ python3 -m pytest test/ ~/cycle_on/cli_tool$ python3 -m build ~/cycle_on/cli_tool$ python3 -m pip install dist/cycleon-0.0.1-py3-none-any.whl --force-reinstall diff --git a/cli_tool/data/config.json b/cli_tool/data/global_config.json similarity index 100% rename from cli_tool/data/config.json rename to cli_tool/data/global_config.json diff --git a/cli_tool/src/cycleon/cmd.py b/cli_tool/src/cycleon/cmd.py index 01b7fa0..b154268 100644 --- a/cli_tool/src/cycleon/cmd.py +++ b/cli_tool/src/cycleon/cmd.py @@ -8,9 +8,10 @@ def process(args): + GLOBAL_CONFIG_PATH = 'data/global_config.json' config_reader = ConfigReader() config_reader.implementation = JsonConfig() - config = config_reader.Open(args.config) + config = config_reader.Open(GLOBAL_CONFIG_PATH) client = Client() client.interface = TcpClient( @@ -18,19 +19,46 @@ def process(args): port=config.network.port) client.adapter = JsonTcpAdapter() - # ToDo: add low-level client cmd execute - action_id = client.Add(config.action) - print(f'action_id: {action_id}') - # client.Remove(action_id) - # status = client.GetStatus(action_id) - # result = client.GetResult(action_id) + if args.command == 'add': + action_id = client.Add(config.action) + print(f'added with action_id: {action_id}') + elif args.command == 'remove': + client.Remove(int(args.id)) + print(f'removed action_id: {args.id}') + elif args.command == 'status': + status = client.GetStatus(int(args.id)) + print(f'status of action_id {args.id}: {status}') + elif args.command == 'result': + result = client.GetResult(int(args.id)) + print(f'result of action_id {args.id}: {result}') + else: + raise RuntimeError(f'unsupported command "{args.command}"') # ToDo: add high-level scenario group execution def main(): parser = argparse.ArgumentParser() - parser.add_argument('config', help='path to config file') + # parser.add_argument('--config', help='path to global config file', required=True) + + subparsers = parser.add_subparsers(help='sub-command', required=True, dest='command') + + add_cmd_subparser = subparsers.add_parser('add', help='request new action to perform') + add_config_group = add_cmd_subparser.add_mutually_exclusive_group(required=True) + add_config_group.add_argument('--reuse_global_config', action='store_true', + help='get action from global config') + add_config_group.add_argument('--config', type=str, + help='path to config file with action to perform') + + remove_cmd_subparser = subparsers.add_parser('remove', help='cancel selected action') + remove_cmd_subparser.add_argument('id', help='unique index of the action') + + status_cmd_subparser = subparsers.add_parser('status', help='get status of selected action') + status_cmd_subparser.add_argument('id', help='unique index of the action') + + result_cmd_subparser = subparsers.add_parser('result', help='get result of selected action') + result_cmd_subparser.add_argument('id', help='unique index of the action') + args = parser.parse_args() process(args) diff --git a/cli_tool/src/cycleon/network/message/response.py b/cli_tool/src/cycleon/network/message/response.py index 61845ae..0d2328e 100644 --- a/cli_tool/src/cycleon/network/message/response.py +++ b/cli_tool/src/cycleon/network/message/response.py @@ -5,7 +5,7 @@ class Type(Enum): INVALID = 0 ADD_ACTION = 1 - # REMOVE_ACTION = 2 + REMOVE_ACTION = 2 GET_ACTION_STATUS = 3 GET_ACTION_RESULT = 4 @@ -28,6 +28,9 @@ class Result: def __init__(self) -> None: self._type = ResultType.INVALID self._message = '' + + def __str__(self) -> str: + return f'({self._type},{self._message})' @property def type(self) -> ResultType: From b168c83f4779945ca55e012d4c36e23e04df6226 Mon Sep 17 00:00:00 2001 From: Kirill Mitkovskii Date: Sat, 23 Sep 2023 11:21:57 +0200 Subject: [PATCH 2/3] [service]: fix launching and terminating deteched process --- README.md | 11 +++++++++++ cli_tool/data/global_config.json | 13 ++++++------- service/CMakeLists.txt | 1 + service/src/runner/child.cc | 11 +++++++++-- service/src/runner/child.hpp | 2 ++ service/src/server/CMakeLists.txt | 1 + 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7cfbb37..71f187a 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Typically a software team has a production code to be tested; a simulation tool Current project is under active development and is not ready yet to be in use. +Help wanted: +* Windows integration +* Cmake review + ## Notes ### service notes @@ -20,6 +24,13 @@ Current project is under active development and is not ready yet to be in use. ~/cycle_on/service$ ./build/src/service ``` +### service integration + +``` +~/cycle_on/$ sudo bash docker/installers/install_essentials.sh +~/cycle_on/$ sudo bash docker/installers/install_boost.sh +``` + ### cli-tool notes ``` $ python3 -m pip install build diff --git a/cli_tool/data/global_config.json b/cli_tool/data/global_config.json index ec2b75f..b1982d7 100644 --- a/cli_tool/data/global_config.json +++ b/cli_tool/data/global_config.json @@ -4,17 +4,16 @@ "port": 8181 }, "action": { - "modules": [ + "modules": [], + "simulators": [ { - "command": "touch", + "command": "/home/robo/CARLA_0.9.12/CarlaUE4.sh", "parameters": [ - "/cycleon/service", - "temp_file_to_check_child_runner.dat" + "-prefernvidia", + "-carla-rpc-port=3000", + "-quality-level=Low" ] } - ], - "simulators": [ - ] } } \ No newline at end of file diff --git a/service/CMakeLists.txt b/service/CMakeLists.txt index 61d7cb7..638c5ff 100644 --- a/service/CMakeLists.txt +++ b/service/CMakeLists.txt @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) +find_package(Threads REQUIRED) find_package(Boost REQUIRED COMPONENTS filesystem) diff --git a/service/src/runner/child.cc b/service/src/runner/child.cc index 4066d78..70f7e85 100644 --- a/service/src/runner/child.cc +++ b/service/src/runner/child.cc @@ -10,6 +10,13 @@ using namespace cycleon::runner; Child::Child(const std::vector& arguments) : arguments_(arguments) {} -void Child::Open() { child_.reset(new bp::child(bp::args(arguments_))); } +void Child::Open() { + child_.reset(new bp::child(bp::args(arguments_), group_)); + // std::cout << "Child: id " << child_->id() << std::endl; + } -void Child::Close() { child_->terminate(); } +void Child::Close() { + group_.terminate(); + child_->wait(); + // std::cout << "Child: exit_code " << child_->exit_code() << std::endl; + } diff --git a/service/src/runner/child.hpp b/service/src/runner/child.hpp index b9b1f81..1709d54 100644 --- a/service/src/runner/child.hpp +++ b/service/src/runner/child.hpp @@ -2,6 +2,7 @@ #define RUNNER_CHILD_H_ #include +#include #include #include "runner/module.hpp" @@ -20,6 +21,7 @@ class Child final : public ModuleBase { private: childPtr child_; + bp::group group_; std::vector arguments_; }; diff --git a/service/src/server/CMakeLists.txt b/service/src/server/CMakeLists.txt index 4ac9964..7e01e07 100644 --- a/service/src/server/CMakeLists.txt +++ b/service/src/server/CMakeLists.txt @@ -6,6 +6,7 @@ target_link_libraries( tcp_server handler nlohmann_json::nlohmann_json + Threads::Threads ) target_include_directories( From 7a66ecfc54c8ce95b7c2ec00da029b715932dde3 Mon Sep 17 00:00:00 2001 From: Kirill Mitkovskii Date: Sat, 23 Sep 2023 20:09:37 +0200 Subject: [PATCH 3/3] [service]: fix ros2 launch commands with the bridge and demo --- cli_tool/data/global_config.json | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cli_tool/data/global_config.json b/cli_tool/data/global_config.json index b1982d7..d34c54e 100644 --- a/cli_tool/data/global_config.json +++ b/cli_tool/data/global_config.json @@ -4,7 +4,29 @@ "port": 8181 }, "action": { - "modules": [], + "modules": [ + { + "command": "ros2", + "parameters": [ + "launch", + "carla_autoware_bridge", + "carla_autoware_demo.launch.py", + "port:=3000", + "timeout:=5" + ] + }, + { + "command": "ros2", + "parameters": [ + "launch", + "carla_launch", + "e2e_simulator.launch.xml", + "map_path:=/home/robo/autoware_map/carla-town-1", + "vehicle_model:=carla_tesla_model3", + "sensor_model:=sample_sensor_kit" + ] + } + ], "simulators": [ { "command": "/home/robo/CARLA_0.9.12/CarlaUE4.sh",