-
Notifications
You must be signed in to change notification settings - Fork 0
Added target to isObjectPerceived #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MFernandezCarmona
wants to merge
4
commits into
main
Choose a base branch
from
target_patch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
gb_world_model/include/gb_world_model/behavior_tree_nodes/GetSearchObject.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
gb_world_model/src/behavior_tree_nodes/GetSearchObject.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_ == "") | ||
| { | ||
| return BT::NodeStatus::RUNNING; | ||
| } | ||
| else | ||
| { | ||
| setOutput("object_id", received_msg_); | ||
| return BT::NodeStatus::SUCCESS; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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