Skip to content
Snippets Groups Projects
Commit 4667e148 authored by Sebastian Ebert's avatar Sebastian Ebert
Browse files

completed ros connection example

parent b0f4a0c8
No related branches found
No related tags found
1 merge request!1Example for -> feature/ros connection
...@@ -143,7 +143,7 @@ add_executable(${PROJECT_NAME}_ros_demo src/ros_demo.cpp ${PROTO_SRCS} ${PROTO_H ...@@ -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 ## 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" ## 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}_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 ## Add cmake target dependencies of the executable
## same as for the library above ## same as for the library above
......
...@@ -8,10 +8,13 @@ ...@@ -8,10 +8,13 @@
#include "ccf/controller/Controller.h" #include "ccf/controller/Controller.h"
#include "ccf/connection/RosConnection.h" #include "ccf/connection/RosConnection.h"
#include "ccf/util/NodeUtil.h"
void receiverCallback(const std::string& msg){ void receiverCallbackA(const std::string& msg){
std::cout << "RECEIVED: " << msg << std::endl; 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) { int main(int argc, char **argv) {
...@@ -24,11 +27,21 @@ int main(int argc, char **argv) { ...@@ -24,11 +27,21 @@ int main(int argc, char **argv) {
Controller controller{n}; Controller controller{n};
std::unique_ptr<RosConnection> connection = std::make_unique<RosConnection>("demo", n); std::unique_ptr<RosConnection> connection = std::make_unique<RosConnection>(n, 3000, 3000);
connection->setTopic("demo"); connection->listen("topicA");
// connection->setHandle(n); connection->listen("topicB");
connection->addPublisher("topicA");
controller.addConnection(std::move(connection)); 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(); ros::spin();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment