Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gb_world_model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ list(APPEND plugin_libs gb_get_placing_pose_bt_node)
add_library(gb_select_pick_bt_node SHARED src/behavior_tree_nodes/SelectPick.cpp)
list(APPEND plugin_libs gb_select_pick_bt_node)

add_library(gb_search_object_bt_node SHARED src/behavior_tree_nodes/GetSearchObject.cpp)
list(APPEND plugin_libs gb_search_object_bt_node)

add_library(gb_is_object_perceived_bt_node SHARED src/behavior_tree_nodes/isObjectPerceived.cpp)
list(APPEND plugin_libs gb_is_object_perceived_bt_node)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2019 Intelligent Robotics Lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef GB_BEHAVIOR_TREE__BEHAVIOR_TREE_NODES__GETSEARCHOBJECT_HPP_
#define GB_BEHAVIOR_TREE__BEHAVIOR_TREE_NODES__GETSEARCHOBJECT_HPP_

#include <string>
#include "std_msgs/msg/string.hpp"
#include "rclcpp/rclcpp.hpp"

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp_v3/bt_factory.h"

namespace gb_world_model
{

class GetSearchObject : public BT::ActionNodeBase
{
public:
explicit GetSearchObject(
const std::string & xml_tag_name,
const BT::NodeConfiguration & conf);

void halt();
BT::NodeStatus tick();

static BT::PortsList providedPorts()
{
return BT::PortsList(
{
BT::OutputPort<std::string>("object_id")
});
}

void messageCB(const std_msgs::msg::String::SharedPtr msg);

private:
rclcpp::Node::SharedPtr node_;
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr message_sub_;

};

} // namespace namespace gb_world_model

#endif // GB_BEHAVIOR_TREE__BEHAVIOR_TREE_NODES__GETSEARCHOBJECT_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class SelectPick : public BT::ActionNodeBase

static BT::PortsList providedPorts()
{
return BT::PortsList({});
return {
BT::InputPort<std::string>("target")
};
}

private:
Expand Down
73 changes: 73 additions & 0 deletions gb_world_model/src/behavior_tree_nodes/GetSearchObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2019 Intelligent Robotics Lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <string>

#include "ros2_knowledge_graph/GraphNode.hpp"
#include "gb_world_model/behavior_tree_nodes/GetSearchObject.hpp"
#include "ros2_knowledge_graph/graph_utils.hpp"

#include "behaviortree_cpp_v3/behavior_tree.h"

namespace gb_world_model
{

GetSearchObject::GetSearchObject(
const std::string & xml_tag_name,
const BT::NodeConfiguration & conf)
: BT::ActionNodeBase(xml_tag_name, conf)
{
node_ = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
message_sub_ = node_->create_subscription<std_msgs::msg::String>(
"/message", 1, std::bind(&GetSearchObject::messageCB, this, _1));
}

void
GetSearchObject::halt()
{
}


void
GetSearchObject::messageCB(const std_msgs::msg::String::SharedPtr msg)
{
received_msg_ = (msg->data);
}


BT::NodeStatus
GetSearchObject::tick()
{


if (received_msg_ == "")
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do a colcon test, the linter would make the isolated { in one line

return BT::NodeStatus::RUNNING;
}
else
{
setOutput("object_id", received_msg_);
return BT::NodeStatus::SUCCESS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated line

return BT::NodeStatus::SUCCESS;
}

}

} // namespace gb_world_model

#include "behaviortree_cpp_v3/bt_factory.h"
BT_REGISTER_NODES(factory)
{
factory.registerNodeType<gb_world_model::GetSearchObject>("GetSearchObject");
}
33 changes: 24 additions & 9 deletions gb_world_model/src/behavior_tree_nodes/SelectPick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,40 @@ SelectPick::tick()
std::string object_id;
auto edges_by_data = graph_->get_edges_from_node_by_data(robot_, "perceived");


std::string target;
getInput<std::string>("target", target);

if (edges_by_data.size() == 0)
{
std::cerr << " [SelectPick] Error: I found [" << edges_by_data.size() << "] perceived edges from jarvis node. Retrying..." << std::endl;
for (auto edge : edges_by_data)
{
std::cerr << " [" << ros2_knowledge_graph::to_string(edge) << "] " << std::endl;
}
return BT::NodeStatus::RUNNING;
}

if (target=="any")
{
object_id = edges_by_data[0].target_node_id;
}
else
{
object_id = target;
}

for (auto edge : edges_by_data)
{
object_id = edge.target_node_id;
if (target == edge.target_node_id)
{
auto edge_pick_obj = ros2_knowledge_graph::new_edge<std::string>(
robot_, object_id, "pick");
graph_->update_edge(edge_pick_obj);
return BT::NodeStatus::SUCCESS;
}

}

auto edge_pick_obj = ros2_knowledge_graph::new_edge<std::string>(
robot_, object_id, "pick");
graph_->update_edge(edge_pick_obj);
return BT::NodeStatus::SUCCESS;
std::cerr << " [SelectPick] Error: Requested Object [" << target << "] wasn't among detections..." << std::endl;
return BT::NodeStatus::RUNNING;

}

} // namespace gb_world_model
Expand Down
22 changes: 20 additions & 2 deletions gb_world_model/src/behavior_tree_nodes/isObjectPerceived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,37 @@ isObjectPerceived::tick()
{
rclcpp::spin_some(node_);
std::string object_id;
std::string target;
getInput<std::string>("target", target);

auto edges_by_data = graph_->get_edges_from_node_by_data(robot_, "perceived");

if (edges_by_data.size() == 0)
{
RCLCPP_INFO(node_->get_logger(), "isObjectPerceived returns false, scanning...");
return BT::NodeStatus::RUNNING;
}
else

if (target=="any")
{
RCLCPP_INFO(node_->get_logger(), "isObjectPerceived returns TRUE");
return BT::NodeStatus::SUCCESS;
}
}

//TODO:: make sure that string comparison is right!!!!!!
for (auto edge : edges_by_data)
{
if (target == edge.target_node_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint

{
RCLCPP_INFO(node_->get_logger(), "isObjectPerceived returns TRUE");
return BT::NodeStatus::SUCCESS;
}
}

// edges do not match target ...
return BT::NodeStatus::RUNNING;

}

} // namespace gb_world_model

Expand Down