diff --git a/CMakeLists.txt b/CMakeLists.txt index adde18720f79d2af566d8410d8bb7e6425bdfac7..b112f96f81631fbbefb2334e253b1c457b33ba92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,7 +143,7 @@ add_executable(${PROJECT_NAME}_ros_demo src/ros_demo.cpp ${PROTO_SRCS} ${PROTO_H ## target back to the shorter version for ease of user use ## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" set_target_properties(${PROJECT_NAME}_demo PROPERTIES OUTPUT_NAME demo PREFIX "") -set_target_properties(${PROJECT_NAME}_ros_demo PROPERTIES OUTPUT_NAME ros_nnnnndemo PREFIX "") +set_target_properties(${PROJECT_NAME}_ros_demo PROPERTIES OUTPUT_NAME ros_demo PREFIX "") ## Add cmake target dependencies of the executable ## same as for the library above diff --git a/src/ros_demo.cpp b/src/ros_demo.cpp index 6f6b804c71cbbe5cf1993ec251a61d0273f0b560..654e97b2771cd469cab86d9a6b35c6926bd9894f 100644 --- a/src/ros_demo.cpp +++ b/src/ros_demo.cpp @@ -8,10 +8,13 @@ #include "ccf/controller/Controller.h" #include "ccf/connection/RosConnection.h" -#include "ccf/util/NodeUtil.h" -void receiverCallback(const std::string& msg){ - std::cout << "RECEIVED: " << msg << std::endl; +void receiverCallbackA(const std::string& msg){ + std::cout << "RECEIVED on A: " << msg << std::endl; +} + +void receiverCallbackB(const std::string& msg){ + std::cout << "RECEIVED on B: " << msg << std::endl; } int main(int argc, char **argv) { @@ -24,11 +27,21 @@ int main(int argc, char **argv) { Controller controller{n}; - std::unique_ptr<RosConnection> connection = std::make_unique<RosConnection>("demo", n); - connection->setTopic("demo"); - // connection->setHandle(n); + std::unique_ptr<RosConnection> connection = std::make_unique<RosConnection>(n, 3000, 3000); + connection->listen("topicA"); + connection->listen("topicB"); + + connection->addPublisher("topicA"); + controller.addConnection(std::move(connection)); - controller.addCallback("demo",receiverCallback); + + controller.addCallback("topicA",receiverCallbackA); + controller.addCallback("topicB",receiverCallbackB); + + // make sure that the publisher got registered within the master + ros::Rate(ros::Duration(0.5)).sleep(); + + controller.sendToAll("topicA", "Hello World!"); ros::spin();