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 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
## 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
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment