Skip to content
Snippets Groups Projects
Commit b8f4c2fa authored by Johannes Mey's avatar Johannes Mey
Browse files

add settings and ros message interface to dummy selection provider

parent ab88f031
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "ros/ros.h" #include "ros/ros.h"
#include "std_msgs/String.h" #include "std_msgs/String.h"
#include "ccf/util/NodeUtil.h"
#include <nng/nng.h> #include <nng/nng.h>
#include <nng/protocol/pair1/pair.h> #include <nng/protocol/pair1/pair.h>
...@@ -51,6 +53,9 @@ int main(int argc, char **argv) { ...@@ -51,6 +53,9 @@ int main(int argc, char **argv) {
ros::NodeHandle n("ccf"); ros::NodeHandle n("ccf");
auto autoselect = CetiRosToolbox::getPrivateParameter<bool>("autoselect", "false");
auto prefix = CetiRosToolbox::getPrivateParameter<std::string>("prefix", "sub_select");
if ((rv = nng_pair1_open(&sock)) != 0) { if ((rv = nng_pair1_open(&sock)) != 0) {
ROS_ERROR_STREAM("nng_pair1_open returned: " << nng_strerror(rv)); ROS_ERROR_STREAM("nng_pair1_open returned: " << nng_strerror(rv));
} }
...@@ -70,6 +75,11 @@ int main(int argc, char **argv) { ...@@ -70,6 +75,11 @@ int main(int argc, char **argv) {
std::random_device rd; std::random_device rd;
std::mt19937 rng(rd()); std::mt19937 rng(rd());
ros::Subscriber sub_select =
n.subscribe<std_msgs::String>(prefix + "/select", 1000, [&](auto &m) { sendSelection(m->data); });
ros::Publisher pub_objects = n.advertise<std_msgs::String>(prefix + "/objects", 1);
ros::Publisher pub_bins = n.advertise<std_msgs::String>(prefix + "/bins", 1);
while (ros::ok()) { while (ros::ok()) {
char *buf = nullptr; char *buf = nullptr;
...@@ -104,6 +114,25 @@ int main(int argc, char **argv) { ...@@ -104,6 +114,25 @@ int main(int argc, char **argv) {
} }
} }
std_msgs::String objects_msg;
objects_msg.data = objects.empty() ? "" :
std::accumulate(
++objects.begin(), objects.end(),
*objects.begin(),
[](auto &a, auto &b) { return a + "," + b; });
pub_objects.publish(objects_msg);
std_msgs::String bins_msg;
bins_msg.data = bins.empty() ? "" :
std::accumulate(
++bins.begin(), bins.end(),
*bins.begin(),
[](auto &a, auto &b) { return a + "," + b; });
pub_bins.publish(bins_msg);
if (autoselect) {
if (objects.empty()) { if (objects.empty()) {
ROS_INFO("No objects to select in a scene without boxes!"); ROS_INFO("No objects to select in a scene without boxes!");
} else if (bins.empty()) { } else if (bins.empty()) {
...@@ -130,7 +159,7 @@ int main(int argc, char **argv) { ...@@ -130,7 +159,7 @@ int main(int argc, char **argv) {
ROS_INFO_STREAM("Selecting random bin: " << bin); ROS_INFO_STREAM("Selecting random bin: " << bin);
sendSelection(bin); sendSelection(bin);
} }
}
} else if (rv == NNG_EAGAIN) { } else if (rv == NNG_EAGAIN) {
// no message received in current spin // no message received in current spin
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment