Skip to content

Commit 968f613

Browse files
committed
add remove_guest
1 parent 33bebaf commit 968f613

File tree

7 files changed

+148
-14
lines changed

7 files changed

+148
-14
lines changed

bt_nodes/hri/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ list(APPEND plugin_libs get_attended_guest_bt_node)
8888
add_library(get_guest_info_bt_node SHARED src/hri/dialog/get_guest_info.cpp)
8989
list(APPEND plugin_libs get_guest_info_bt_node)
9090

91+
add_library(remove_guest_attended_bt_node SHARED src/hri/dialog/remove_guest_attended.cpp)
92+
list(APPEND plugin_libs remove_guest_attended_bt_node)
93+
9194
foreach(bt_plugin ${plugin_libs})
9295
ament_target_dependencies(${bt_plugin} ${dependencies})
9396
target_compile_definitions(${bt_plugin} PRIVATE BT_PLUGIN_EXPORT)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2024 Intelligent Robotics Lab - Gentlebots
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions andGO2OBJECT
13+
// limitations under the License.
14+
15+
#ifndef HRI__REMOVE_GUEST_ATTENDED_HPP_
16+
#define HRI__REMOVE_GUEST_ATTENDED_HPP_
17+
18+
#include <chrono>
19+
#include <functional>
20+
21+
#include "behaviortree_cpp_v3/behavior_tree.h"
22+
#include "behaviortree_cpp_v3/bt_factory.h"
23+
#include "std_msgs/msg/string.hpp"
24+
#include "kb_msgs/srv/query.hpp"
25+
#include "rclcpp/rclcpp.hpp"
26+
#include "rclcpp_cascade_lifecycle/rclcpp_cascade_lifecycle.hpp"
27+
#include "hri/bt_service_node.hpp"
28+
29+
namespace dialog
30+
{
31+
32+
class RemoveGuestAttended : public BT::ActionNodeBase
33+
{
34+
public:
35+
explicit RemoveGuestAttended(const std::string & xml_tag_name, const BT::NodeConfiguration & conf);
36+
37+
void halt();
38+
BT::NodeStatus tick();
39+
40+
static BT::PortsList providedPorts()
41+
{
42+
return BT::PortsList(
43+
{
44+
BT::InputPort<std::string>("guest_attended")
45+
}
46+
);
47+
}
48+
49+
private:
50+
std::shared_ptr<rclcpp_cascade_lifecycle::CascadeLifecycleNode> node_;
51+
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr kb_publisher_;
52+
std::string guest_attending_id_;
53+
};
54+
55+
} // namespace dialog
56+
57+
#endif // HRI__REMOVE_GUEST_ATTENDED_HPP_

bt_nodes/hri/src/hri/dialog/get_attended_guest.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,18 @@ void GetAttendedGuest::on_result()
6363
guest_id_ = match[1];
6464
}
6565

66-
setOutput("guest_attended", guest_id_);
66+
if (guest_id_.empty()) {
67+
RCLCPP_ERROR(node_->get_logger(), "[GetAttendedGuest] No attended guest found in the result");
68+
setStatus(BT::NodeStatus::FAILURE);
69+
}else{
6770

68-
RCLCPP_INFO(
69-
node_->get_logger(), "[GetAttendedGuest] Guest attended: %s", guest_id_.c_str());
71+
setOutput("guest_attended", guest_id_);
7072

71-
std_msgs::msg::String fact_msg;
73+
RCLCPP_INFO(
74+
node_->get_logger(), "[GetAttendedGuest] Guest attended: %s", guest_id_.c_str());
7275

73-
setStatus(BT::NodeStatus::SUCCESS);
76+
setStatus(BT::NodeStatus::SUCCESS);
77+
}
7478
}
7579

7680

bt_nodes/hri/src/hri/dialog/get_guest_info.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ void GetGuestInfo::on_result()
109109
node_->get_logger(), "[GetGuestInfo] Guest info retrieved: Name: %s, Drink: %s, Description: %s",
110110
guest_name_.c_str(), guest_drink_.c_str(), guest_description_.c_str());
111111

112-
std_msgs::msg::String fact_msg;
113-
114-
// Delete attending fact
115-
if (!guest_attending_id_.empty()) {
116-
fact_msg.data = "robot1 oro:attends " + guest_attending_id_;
117-
kb_publisher_->publish(fact_msg);
118-
RCLCPP_INFO(node_->get_logger(), "[GetGuestInfo] Removing fact: robot1 oro:attends %s", guest_id_.c_str());
119-
}
120112

121113
setStatus(BT::NodeStatus::SUCCESS);
122114
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2024 Intelligent Robotics Lab - Gentlebots
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "hri/dialog/remove_guest_attended.hpp"
16+
#include <regex>
17+
18+
using std::placeholders::_1;
19+
using namespace std::chrono_literals;
20+
21+
22+
namespace dialog
23+
{
24+
25+
RemoveGuestAttended::RemoveGuestAttended(
26+
const std::string & xml_tag_name, const BT::NodeConfiguration & conf)
27+
: BT::ActionNodeBase(xml_tag_name, conf)
28+
{
29+
config().blackboard->get("node", node_);
30+
this->kb_publisher_= node_->create_publisher<std_msgs::msg::String>("/kb/remove_fact", 10);
31+
}
32+
33+
BT::NodeStatus RemoveGuestAttended::tick()
34+
{
35+
RCLCPP_DEBUG(node_->get_logger(), "[RemoveGuestAttended] ticked");
36+
37+
getInput("guest_attended", guest_attending_id_);
38+
39+
std_msgs::msg::String fact_msg;
40+
41+
if (!guest_attending_id_.empty()) {
42+
fact_msg.data = "robot1 oro:attends " + guest_attending_id_;
43+
kb_publisher_->publish(fact_msg);
44+
RCLCPP_INFO(node_->get_logger(), "[RemoveGuestAttended] Removing fact: robot1 oro:attends %s", guest_attending_id_.c_str());
45+
}else{
46+
return BT::NodeStatus::FAILURE;
47+
}
48+
49+
return BT::NodeStatus::SUCCESS;
50+
51+
}
52+
53+
void RemoveGuestAttended::halt() {}
54+
55+
56+
} // namespace hri
57+
58+
#include "behaviortree_cpp_v3/bt_factory.h"
59+
BT_REGISTER_NODES(factory)
60+
{
61+
62+
factory.registerNodeType<dialog::RemoveGuestAttended>("RemoveGuestAttended");
63+
}

bt_nodes/hri/src/hri/dialog/store_guest_info.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ std::string obtain_guest_id(const std::string & json)
7575
return "guest" + std::to_string(max_id + 1);
7676
}
7777

78+
static std::string unescape_latex_like(std::string s)
79+
{
80+
static const std::regex rx(R"(\\([,.;:!?()\[\]{}\-_%&#$]))");
81+
return std::regex_replace(s, rx, "$1");
82+
}
83+
7884
static std::string escape_turtle_literal(std::string s)
7985
{
8086
// 1) Escape backslashes
@@ -92,6 +98,10 @@ static std::string escape_turtle_literal(std::string s)
9298
s.replace(pos, 1, "\\n");
9399
}
94100

101+
for (size_t pos = 0; (pos = s.find('\r', pos)) != std::string::npos; pos += 2) {
102+
s.replace(pos, 1, "\\r");
103+
}
104+
95105
return s;
96106
}
97107

@@ -121,6 +131,11 @@ void StoreGuestInfo::on_result()
121131
kb_publisher_->publish(fact_msg);
122132

123133
if (!guest_description_.empty()) {
134+
if (guest_description_.find('\\') != std::string::npos) {
135+
RCLCPP_WARN(node_->get_logger(), "guest_description (pre-fix): '%s'",
136+
guest_description_.c_str());
137+
}
138+
guest_description_ = unescape_latex_like(guest_description_);
124139
guest_description_ = escape_turtle_literal(guest_description_);
125140
fact_msg.data = guest_id + " oro:description \"" + guest_description_ + "\"";
126141
kb_publisher_->publish(fact_msg);

robocup_bringup/launch/dialog.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def generate_launch_description():
130130
ld.add_action(llava_cmd)
131131
ld.add_action(audio_common_tts_node)
132132
ld.add_action(audio_common_player_node)
133-
ld.add_action(kb_cmd)
133+
# ld.add_action(kb_cmd)
134134

135135
#ld.add_action(music_player_node)
136136

0 commit comments

Comments
 (0)