diff --git a/.vscode/settings.json b/.vscode/settings.json index 6b40311..b01d19d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,8 @@ { "python.autoComplete.extraPaths": [ "/opt/ros/foxy/lib/python3.8/site-packages" - ] + ], + "files.associations": { + "functional": "cpp" + } } \ No newline at end of file diff --git a/src/ros2aria/CMakeLists.txt b/src/ros2aria/CMakeLists.txt index 039b025..e13f990 100644 --- a/src/ros2aria/CMakeLists.txt +++ b/src/ros2aria/CMakeLists.txt @@ -19,6 +19,7 @@ endif() find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) find_package(std_srvs REQUIRED) +find_package(geometry_msgs REQUIRED) # uncomment the following section in order to fill in # further dependencies manually. # find_package( REQUIRED) @@ -27,6 +28,7 @@ find_package(std_srvs REQUIRED) add_executable(ros2aria src/ros2aria.cpp) ament_target_dependencies(ros2aria rclcpp) ament_target_dependencies(ros2aria std_srvs) +ament_target_dependencies(ros2aria geometry_msgs) target_include_directories(ros2aria PUBLIC $ $ diff --git a/src/ros2aria/package.xml b/src/ros2aria/package.xml index a940bc3..ac2ad23 100644 --- a/src/ros2aria/package.xml +++ b/src/ros2aria/package.xml @@ -14,6 +14,7 @@ rclcpp std_srvs + geometry_msgs ament_cmake diff --git a/src/ros2aria/src/ros2aria.cpp b/src/ros2aria/src/ros2aria.cpp index ebb1600..24db7a5 100644 --- a/src/ros2aria/src/ros2aria.cpp +++ b/src/ros2aria/src/ros2aria.cpp @@ -6,6 +6,8 @@ #include "rclcpp/rclcpp.hpp" #include "std_msgs/msg/string.hpp" #include "std_srvs/srv/empty.hpp" +#include "geometry_msgs/msg/twist.hpp" + using std::placeholders::_1; using std::placeholders::_2; @@ -35,20 +37,20 @@ public: this->robot->runAsync(true); this->robot->enableMotors(); - subscription_ = this->create_subscription( - "topic", 10, std::bind(&MinimalSubscriber::topic_callback, this, _1)); - service_ = this->create_service("stop", std::bind(&MinimalSubscriber::stop, this, _1, _2)); + cmd_vel_sub_ = this->create_subscription( + "cmd_vel", 10, std::bind(&MinimalSubscriber::cmd_vel_callback, this, _1)); + stop_service_ = this->create_service("stop", std::bind(&MinimalSubscriber::stop, this, _1, _2)); } private: ArRobot *robot; ArRobotConnector *robotConn; - void topic_callback(const std_msgs::msg::String::SharedPtr msg) const + void cmd_vel_callback(const geometry_msgs::msg::Twist::SharedPtr msg) const { - RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str()); + RCLCPP_INFO(this->get_logger(), "cmd_vel: %f", msg->linear.x); } - rclcpp::Subscription::SharedPtr subscription_; + rclcpp::Subscription::SharedPtr cmd_vel_sub_; void stop(const std::shared_ptr request, std::shared_ptr response) const { @@ -56,7 +58,7 @@ private: this->robotConn->disconnectAll(); rclcpp::shutdown(); } - rclcpp::Service::SharedPtr service_; + rclcpp::Service::SharedPtr stop_service_; }; int main(int argc, char **argv)