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

fix execution bug, simplyfy parameter handling

parent b1c3c740
Branches
No related tags found
No related merge requests found
...@@ -19,12 +19,15 @@ ...@@ -19,12 +19,15 @@
#include "ccf/controller/DummyRobotArmController.h" #include "ccf/controller/DummyRobotArmController.h"
#include "ccf/connection/NngConnection.h" #include "ccf/connection/NngConnection.h"
#include "ccf/util/NodeUtil.h"
#include <google/protobuf/text_format.h> #include <google/protobuf/text_format.h>
#include <google/protobuf/util/json_util.h> #include <google/protobuf/util/json_util.h>
const std::string NODE_NAME = "ros2cgv_dummy"; const std::string NODE_NAME = "ros2cgv_dummy";
using CetiRosToolbox::getParameter;
void loadScene(DummyRobotArmController &connector) { void loadScene(DummyRobotArmController &connector) {
// read file into string: https://stackoverflow.com/questions/2602013/read-whole-ascii-file-into-c-stdstring // read file into string: https://stackoverflow.com/questions/2602013/read-whole-ascii-file-into-c-stdstring
std::string path = ros::package::getPath("ccf") + "/config/config_scene.yaml"; std::string path = ros::package::getPath("ccf") + "/config/config_scene.yaml";
...@@ -74,22 +77,12 @@ int main(int argc, char **argv) { ...@@ -74,22 +77,12 @@ int main(int argc, char **argv) {
<< "/cgv_address from param server, using default " << cgv_address); << "/cgv_address from param server, using default " << cgv_address);
} }
DummyRobotArmController connector{n, "place-a"}; DummyRobotArmController connector{n, NODE_NAME};
// add an NNG connection // add an NNG connection
std::unique_ptr<NngConnection> connection = std::make_unique<NngConnection>(cgv_address); std::unique_ptr<NngConnection> connection = std::make_unique<NngConnection>(cgv_address);
std::string selectionTopic = "selection"; connection->setReceiveTopic(getParameter(n, "topics/selection", "selection"));
if (!n.getParam("topics/selection", selectionTopic)) { connection->setSendTopic(getParameter(n, "topics/scene", NODE_NAME + "/scene/update"));
ROS_WARN_STREAM("[" << NODE_NAME << "] Could not get string value for " << n.getNamespace()
<< "/topics/selection from param server, using default " << selectionTopic);
}
connection->setReceiveTopic(selectionTopic);
std::string sceneTopic = "scene";
if (!n.getParam("topics/scene", sceneTopic)) {
ROS_WARN_STREAM("[" << NODE_NAME << "] Could not get string value for " << n.getNamespace()
<< "/topics/scene from param server, using default " << sceneTopic);
}
connection->setSendTopic(sceneTopic);
connector.addConnection(std::move(connection)); connector.addConnection(std::move(connection));
loadScene(connector); loadScene(connector);
...@@ -126,7 +119,7 @@ int main(int argc, char **argv) { ...@@ -126,7 +119,7 @@ int main(int argc, char **argv) {
if (selectedBin && selectedBox) { if (selectedBin && selectedBox) {
auto boxId = selectedBox->id(); auto boxId = selectedBox->id();
ROS_INFO_STREAM("[" << NODE_NAME << "] Got task: Put " << boxId << " into " << selectedBin->id()); ROS_INFO_STREAM("[" << NODE_NAME << "] Got task: Put " << boxId << " into " << selectedBin->id());
if (!connector.RobotArmController::pickAndDrop(*robot, *selectedBox, *selectedBin, false)) { if (!connector.pickAndDrop(*robot, *selectedBox, *selectedBin, false)) {
ROS_WARN_STREAM("[" << NODE_NAME << "] Unable to remove box '" << boxId << "'!"); ROS_WARN_STREAM("[" << NODE_NAME << "] Unable to remove box '" << boxId << "'!");
selectedBox = nullptr; selectedBox = nullptr;
selectedBin = nullptr; selectedBin = nullptr;
......
...@@ -20,9 +20,12 @@ ...@@ -20,9 +20,12 @@
#include "ccf/controller/MoveItRobotArmController.h" #include "ccf/controller/MoveItRobotArmController.h"
#include "ccf/connection/NngConnection.h" #include "ccf/connection/NngConnection.h"
#include "ccf/util/NodeUtil.h"
const std::string NODE_NAME = "ros2cgv_moveit"; const std::string NODE_NAME = "ros2cgv_moveit";
using CetiRosToolbox::getParameter;
int main(int argc, char **argv) { int main(int argc, char **argv) {
GOOGLE_PROTOBUF_VERIFY_VERSION; GOOGLE_PROTOBUF_VERIFY_VERSION;
...@@ -37,25 +40,17 @@ int main(int argc, char **argv) { ...@@ -37,25 +40,17 @@ int main(int argc, char **argv) {
<< "/cgv_address from param server, using default " << cgv_address); << "/cgv_address from param server, using default " << cgv_address);
} }
MoveItRobotArmController connector{n, "place-a"}; MoveItRobotArmController connector{n, NODE_NAME};
// add an NNG connection // add an NNG connection
std::unique_ptr<NngConnection> connection = std::make_unique<NngConnection>(cgv_address); std::unique_ptr<NngConnection> connection = std::make_unique<NngConnection>(cgv_address);
std::string selectionTopic = "selection"; connection->setReceiveTopic(getParameter(n, "topics/selection", "selection"));
if (!n.getParam("topics/selection", selectionTopic)) { connection->setSendTopic(getParameter(n, "topics/scene", NODE_NAME + "/scene/update"));
ROS_WARN_STREAM("[" << NODE_NAME << "] Could not get string value for " << n.getNamespace()
<< "/topics/selection from param server, using default " << selectionTopic);
}
connection->setReceiveTopic(selectionTopic);
std::string sceneTopic = "scene";
if (!n.getParam("topics/scene", sceneTopic)) {
ROS_WARN_STREAM("[" << NODE_NAME << "] Could not get string value for " << n.getNamespace()
<< "/topics/scene from param server, using default " << sceneTopic);
}
connection->setSendTopic(sceneTopic);
connector.addConnection(std::move(connection)); connector.addConnection(std::move(connection));
std::shared_ptr<Object> robot{}; // scene loading is not required, the scene is updated by moveit
Object* robot = nullptr;
Object* selectedBox = nullptr; Object* selectedBox = nullptr;
Object* selectedBin = nullptr; Object* selectedBin = nullptr;
std::optional<std::string> currentlyPickedBox{}; std::optional<std::string> currentlyPickedBox{};
...@@ -87,14 +82,16 @@ int main(int argc, char **argv) { ...@@ -87,14 +82,16 @@ int main(int argc, char **argv) {
if (selectedBin && selectedBox) { if (selectedBin && selectedBox) {
auto boxId = selectedBox->id(); auto boxId = selectedBox->id();
ROS_INFO_STREAM("[" << NODE_NAME << "] Got task: Put " << boxId << " into " << selectedBin->id()); ROS_INFO_STREAM("[" << NODE_NAME << "] Got task: Put " << boxId << " into " << selectedBin->id());
if (!connector.RobotArmController::pickAndDrop(*robot, *selectedBox, *selectedBin, false)) { if (!connector.pickAndDrop(*robot, *selectedBox, *selectedBin, false)) {
ROS_WARN_STREAM("[" << NODE_NAME << "] Unable to remove box '" << boxId << "'!"); ROS_WARN_STREAM("[" << NODE_NAME << "] Unable to remove box '" << boxId << "'!");
selectedBox = nullptr;
selectedBin = nullptr;
} else { } else {
ROS_INFO_STREAM("[" << NODE_NAME << "] Job is done! '" << boxId << "' is no more."); ROS_INFO_STREAM("[" << NODE_NAME << "] Job is done! '" << boxId << "' is no more.");
connector.sendScene();
}
selectedBox = nullptr; selectedBox = nullptr;
selectedBin = nullptr; selectedBin = nullptr;
connector.sendScene();
}
} }
}; };
...@@ -102,7 +99,7 @@ int main(int argc, char **argv) { ...@@ -102,7 +99,7 @@ int main(int argc, char **argv) {
ros::ServiceClient bin_check_client = n.serviceClient<ccf::BinCheck>("/check_bin_service"); ros::ServiceClient bin_check_client = n.serviceClient<ccf::BinCheck>("/check_bin_service");
ros::ServiceServer get_scene_service = n.advertiseService<ccf::SceneUpdateRequest, ccf::SceneUpdateResponse>( ros::ServiceServer get_scene_service = n.advertiseService<ccf::SceneUpdateRequest, ccf::SceneUpdateResponse>(
"/connector_node_ros_cgv/updateCgvScene", "updateCgvScene",
[&currentlyPickedBox, &connector, &bin_check_client](auto &req, auto &res) { [&currentlyPickedBox, &connector, &bin_check_client](auto &req, auto &res) {
ROS_INFO_STREAM("[" << NODE_NAME << "] Received a scene update from the controller."); ROS_INFO_STREAM("[" << NODE_NAME << "] Received a scene update from the controller.");
connector.updateScene(req, bin_check_client); connector.updateScene(req, bin_check_client);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment