-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add temporal obstacle layer * add remove obstacles * add bt nodes
- Loading branch information
1 parent
f52f483
commit e48b84b
Showing
13 changed files
with
405 additions
and
16 deletions.
There are no files selected for viewing
18 changes: 9 additions & 9 deletions
18
mep3_behavior_tree/assets/strategies/big/purple_strategy.xml
This file contains 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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<root main_tree_to_execute="BehaviorTree"> | ||
<!-- ////////// --> | ||
<BehaviorTree ID="BehaviorTree"> | ||
<Sequence> | ||
<DefaultTeamColor color="purple" /> | ||
<WaitMatchStart state="1" /> | ||
<!-- Robot setup (pre-match state) --> | ||
<WaitMatchStart state="2" /> | ||
<!-- Robot strategy (match state) --> | ||
<Wait duration="10000000.0" name="Wait forever as big robot" /> | ||
</Sequence> | ||
<SequenceStar> | ||
<AddObstacle label="initial" polygon="0.0;0.0|0.2;0.0|0.0;0.2" /> | ||
<AddObstacle label="initial" polygon="0.0;0.0|-0.2;0.0|0.0;-0.2" /> | ||
<Navigate goal="-0.8;0.0;0" /> | ||
<RemoveObstacle label="initial" /> | ||
|
||
<Wait duration="100000.0" name="Wait one big purple main strategy" /> | ||
</SequenceStar> | ||
</BehaviorTree> | ||
<!-- ////////// --> | ||
</root> | ||
</root> |
78 changes: 78 additions & 0 deletions
78
mep3_behavior_tree/include/mep3_behavior_tree/add_obstacle_action.hpp
This file contains 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,78 @@ | ||
// Copyright 2022 Memristor Robotics | ||
// | ||
// 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 MEP3_BEHAVIOR_TREE__ADD_OBSTACLE_ACTION_HPP_ | ||
#define MEP3_BEHAVIOR_TREE__ADD_OBSTACLE_ACTION_HPP_ | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
#include "mep3_behavior_tree/pose_2d.hpp" | ||
#include "mep3_msgs/msg/temporal_obstacle.hpp" | ||
|
||
#include "behaviortree_cpp_v3/behavior_tree.h" | ||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
#include "behaviortree_cpp_v3/action_node.h" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "geometry_msgs/msg/point.hpp" | ||
|
||
namespace mep3_behavior_tree | ||
{ | ||
class AddObstacleAction : public BT::AsyncActionNode | ||
{ | ||
public: | ||
AddObstacleAction(const std::string &name, const BT::NodeConfiguration &config_) | ||
: BT::AsyncActionNode(name, config_) | ||
{ | ||
node_ = config().blackboard->get<rclcpp::Node::SharedPtr>("node"); | ||
publisher_ = node_->create_publisher<mep3_msgs::msg::TemporalObstacle>( | ||
"add_obstacle", rclcpp::QoS(1).reliable()); | ||
} | ||
|
||
AddObstacleAction() = delete; | ||
|
||
BT::NodeStatus tick() override; | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return { | ||
BT::InputPort<std::string>("label"), | ||
BT::InputPort<std::vector<geometry_msgs::msg::Point>>("polygon") | ||
}; | ||
} | ||
|
||
private: | ||
rclcpp::Node::SharedPtr node_; | ||
rclcpp::Publisher<mep3_msgs::msg::TemporalObstacle>::SharedPtr publisher_; | ||
}; | ||
|
||
BT::NodeStatus AddObstacleAction::tick() | ||
{ | ||
std::string label; | ||
std::vector<geometry_msgs::msg::Point> polygon; | ||
getInput("label", label); | ||
getInput<std::vector<geometry_msgs::msg::Point>>("polygon", polygon); | ||
|
||
mep3_msgs::msg::TemporalObstacle msg; | ||
msg.label = label; | ||
msg.polygon = polygon; | ||
|
||
publisher_->publish(msg); | ||
|
||
return BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
} // namespace mep3_behavior_tree | ||
|
||
#endif // MEP3_BEHAVIOR_TREE__ADD_OBSTACLE_ACTION_HPP_ |
This file contains 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
71 changes: 71 additions & 0 deletions
71
mep3_behavior_tree/include/mep3_behavior_tree/remove_obstacle_action.hpp
This file contains 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,71 @@ | ||
// Copyright 2022 Memristor Robotics | ||
// | ||
// 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 MEP3_BEHAVIOR_TREE__REMOVE_OBSTACLE_ACTION_HPP_ | ||
#define MEP3_BEHAVIOR_TREE__REMOVE_OBSTACLE_ACTION_HPP_ | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
#include "behaviortree_cpp_v3/behavior_tree.h" | ||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
#include "behaviortree_cpp_v3/action_node.h" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "std_msgs/msg/string.hpp" | ||
|
||
namespace mep3_behavior_tree | ||
{ | ||
class RemoveObstacleAction : public BT::AsyncActionNode | ||
{ | ||
public: | ||
RemoveObstacleAction(const std::string &name, const BT::NodeConfiguration &config_) | ||
: BT::AsyncActionNode(name, config_) | ||
{ | ||
node_ = config().blackboard->get<rclcpp::Node::SharedPtr>("node"); | ||
publisher_ = node_->create_publisher<std_msgs::msg::String>( | ||
"remove_obstacle", rclcpp::QoS(1).reliable()); | ||
} | ||
|
||
RemoveObstacleAction() = delete; | ||
|
||
BT::NodeStatus tick() override; | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return { | ||
BT::InputPort<std::string>("label"), | ||
}; | ||
} | ||
|
||
private: | ||
rclcpp::Node::SharedPtr node_; | ||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_; | ||
}; | ||
|
||
BT::NodeStatus RemoveObstacleAction::tick() | ||
{ | ||
std::string label; | ||
getInput("label", label); | ||
|
||
std_msgs::msg::String msg; | ||
msg.data = label; | ||
|
||
publisher_->publish(msg); | ||
|
||
return BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
} // namespace mep3_behavior_tree | ||
|
||
#endif // MEP3_BEHAVIOR_TREE__REMOVE_OBSTACLE_ACTION_HPP_ |
This file contains 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 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
File renamed without changes.
This file contains 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,2 @@ | ||
string label | ||
geometry_msgs/Point[] polygon |
This file contains 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
65 changes: 65 additions & 0 deletions
65
mep3_navigation/include/mep3_navigation/temporal_obstacle_layer/temporal_obstacle_layer.hpp
This file contains 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,65 @@ | ||
// Copyright (c) 2020 Shrijit Singh | ||
// Copyright (c) 2020 Samsung Research America | ||
// | ||
// 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 MEP3_NAVIGATION__TEMPORAL_OBSTACLE_LAYER_HPP_ | ||
#define MEP3_NAVIGATION__TEMPORAL_OBSTACLE_LAYER_HPP_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "nav2_costmap_2d/layer.hpp" | ||
#include "nav2_costmap_2d/layered_costmap.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "std_msgs/msg/string.hpp" | ||
|
||
#include "mep3_msgs/msg/temporal_obstacle.hpp" | ||
|
||
namespace mep3_navigation { | ||
class TemporalObstacleLayer : public nav2_costmap_2d::Layer { | ||
public: | ||
TemporalObstacleLayer(); | ||
|
||
virtual void onInitialize(); | ||
virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, | ||
double *min_x, double *min_y, double *max_x, | ||
double *max_y); | ||
virtual void updateCosts(nav2_costmap_2d::Costmap2D &master_grid, int min_i, | ||
int min_j, int max_i, int max_j); | ||
|
||
virtual void reset() { return; } | ||
|
||
virtual void onFootprintChanged(); | ||
|
||
virtual bool isClearable() { return false; } | ||
|
||
private: | ||
rclcpp::Subscription<mep3_msgs::msg::TemporalObstacle>::SharedPtr | ||
add_obstacle_subscriber_; | ||
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr | ||
remove_obstacle_subscriber_; | ||
|
||
void on_new_obstacle(const mep3_msgs::msg::TemporalObstacle::SharedPtr msg); | ||
void on_remove_obstacle(const std_msgs::msg::String::SharedPtr msg); | ||
|
||
std::string add_obstacle_topic_; | ||
std::string remove_obstacle_topic_; | ||
|
||
bool need_update_; | ||
std::vector<mep3_msgs::msg::TemporalObstacle::SharedPtr> obstacles_; | ||
}; | ||
|
||
} // namespace mep3_navigation | ||
|
||
#endif // MEP3_NAVIGATION__TEMPORAL_OBSTACLE_LAYER_HPP_ |
This file contains 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
Oops, something went wrong.