diff --git a/autorun/CMakeLists.txt b/autorun/CMakeLists.txt new file mode 100644 index 000000000..004021436 --- /dev/null +++ b/autorun/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.8) +project(autorun) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(rclcpp REQUIRED) +find_package(std_msgs REQUIRED) +# uncomment the following section in order to fill in +# further dependencies manually. +# find_package( REQUIRED) + +add_executable(autorunner src/autorunner.cpp) +ament_target_dependencies(autorunner rclcpp std_msgs) +target_include_directories(autorunner PUBLIC + $ + $) +target_compile_features(autorunner PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 + +install(TARGETS autorunner + DESTINATION lib/${PROJECT_NAME}) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + # the following line skips the linter which checks for copyrights + # comment the line when a copyright and license is added to all source files + set(ament_cmake_copyright_FOUND TRUE) + # the following line skips cpplint (only works in a git repo) + # comment the line when this package is in a git repo and when + # a copyright and license is added to all source files + set(ament_cmake_cpplint_FOUND TRUE) + ament_lint_auto_find_test_dependencies() +endif() + +ament_package() diff --git a/autorun/package.xml b/autorun/package.xml new file mode 100644 index 000000000..0487daf56 --- /dev/null +++ b/autorun/package.xml @@ -0,0 +1,20 @@ + + + + autorun + 0.0.0 + TODO: Package description + victor + TODO: License declaration + rclcpp + std_msgs + + ament_cmake + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/autorun/src/autorunner.cpp b/autorun/src/autorunner.cpp new file mode 100644 index 000000000..1de41fc13 --- /dev/null +++ b/autorun/src/autorunner.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#include "rclcpp/rclcpp.hpp" + +#include "std_msgs/msg/empty.hpp" + +class Autorunner : public rclcpp::Node +{ + public: + Autorunner() + : Node("autorunner") + { + init_pub = this->create_publisher("/atos/init", 10); + connect_pub = this->create_publisher("/atos/connect", 10); + arm_pub = this->create_publisher("/atos/arm", 10); + start_pub = this->create_publisher("/atos/start", 10); + abort_pub = this->create_publisher("/atos/abort", 10); + all_clear_pub = this->create_publisher("/atos/all_clear", 10); + run_experiment(20); + } + + private: + rclcpp::Publisher::SharedPtr init_pub; + rclcpp::Publisher::SharedPtr connect_pub; + rclcpp::Publisher::SharedPtr arm_pub; + rclcpp::Publisher::SharedPtr start_pub; + rclcpp::Publisher::SharedPtr abort_pub; + rclcpp::Publisher::SharedPtr all_clear_pub; + void run_experiment(int n) + { + RCLCPP_INFO(this->get_logger(), "Running %d experiments", n); + std_msgs::msg::Empty message; + RCLCPP_INFO(this->get_logger(), "Sending init to ATOS"); + init_pub->publish(message); + sleep(1); + init_pub->publish(message); + sleep(2); + RCLCPP_INFO(this->get_logger(), "Sending connect to ATOS"); + connect_pub->publish(message); + sleep(2); + + while (n > 0) + { + RCLCPP_INFO(this->get_logger(), "Experiment %d", n); + RCLCPP_INFO(this->get_logger(), "Sending arm to ATOS"); + arm_pub->publish(message); + sleep(2); + RCLCPP_INFO(this->get_logger(), "Sending start to ATOS"); + start_pub->publish(message); + sleep(35); + RCLCPP_INFO(this->get_logger(), "Sending abort to ATOS"); + abort_pub->publish(message); + sleep(2); + RCLCPP_INFO(this->get_logger(), "Sending all_clear to ATOS"); + all_clear_pub->publish(message); + sleep(2); + n--; + } + } +}; + + +int main(int argc, char ** argv) +{ + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +}