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,33 +114,52 @@ int main(int argc, char **argv) { ...@@ -104,33 +114,52 @@ int main(int argc, char **argv) {
} }
} }
if (objects.empty()) { std_msgs::String objects_msg;
ROS_INFO("No objects to select in a scene without boxes!"); objects_msg.data = objects.empty() ? "" :
} else if (bins.empty()) { std::accumulate(
ROS_INFO("No bin to put the object in available!"); ++objects.begin(), objects.end(),
} else { *objects.begin(),
// select a random object [](auto &a, auto &b) { return a + "," + b; });
std::uniform_int_distribution<u_long> distribution{0, objects.size() - 1};
pub_objects.publish(objects_msg);
// wait some time, then send a selected object
pause_rate.sleep(); std_msgs::String bins_msg;
std::string object{objects[distribution(rng)]}; bins_msg.data = bins.empty() ? "" :
std::accumulate(
ROS_INFO_STREAM("Selecting random object: " << object); ++bins.begin(), bins.end(),
sendSelection(object); *bins.begin(),
[](auto &a, auto &b) { return a + "," + b; });
// wait again, then send the bin object
pause_rate.sleep(); pub_bins.publish(bins_msg);
// we expect an object named "bin" to be there if (autoselect) {
// select a random object if (objects.empty()) {
std::uniform_int_distribution<u_long> binDistribution{0, bins.size() - 1}; ROS_INFO("No objects to select in a scene without boxes!");
} else if (bins.empty()) {
std::string bin{bins[binDistribution(rng)]}; ROS_INFO("No bin to put the object in available!");
ROS_INFO_STREAM("Selecting random bin: " << bin); } else {
sendSelection(bin); // select a random object
std::uniform_int_distribution<u_long> distribution{0, objects.size() - 1};
// wait some time, then send a selected object
pause_rate.sleep();
std::string object{objects[distribution(rng)]};
ROS_INFO_STREAM("Selecting random object: " << object);
sendSelection(object);
// wait again, then send the bin object
pause_rate.sleep();
// we expect an object named "bin" to be there
// select a random object
std::uniform_int_distribution<u_long> binDistribution{0, bins.size() - 1};
std::string bin{bins[binDistribution(rng)]};
ROS_INFO_STREAM("Selecting random bin: " << 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