Skip to content

Commit aecccaa

Browse files
committed
restore manipulation server launch
2 parents fcc79e0 + 21d779c commit aecccaa

5 files changed

Lines changed: 116 additions & 49 deletions

File tree

bt_nodes/hri/src/hri/check_policy.cpp

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include <nlohmann/json.hpp>
1818
#include <string>
1919
#include <utility>
20+
#include <regex>
21+
#include <algorithm>
22+
#include <cctype>
2023

2124
#include "behaviortree_cpp_v3/behavior_tree.h"
2225
#include "hri/check_policy.hpp"
@@ -49,9 +52,8 @@ void CheckPolicy::on_tick()
4952
RCLCPP_DEBUG(node_->get_logger(), "CheckPolicy ticked");
5053
RCLCPP_INFO(node_->get_logger(), "CheckPolicy ticked");
5154
if (!image_) {
52-
RCLCPP_ERROR(node_->get_logger(), "No image received");
53-
RCLCPP_INFO(node_->get_logger(), "No image received, setting to IDLE");
54-
setStatus(BT::NodeStatus::IDLE);
55+
RCLCPP_ERROR(node_->get_logger(), "No image received yet");
56+
goal_.prompt.clear();
5557
return;
5658
}
5759
RCLCPP_INFO(node_->get_logger(), "Image received, proceeding with CheckPolicy");
@@ -61,6 +63,7 @@ void CheckPolicy::on_tick()
6163

6264
std::string prompt_ = text_;
6365
goal_.prompt = prompt_;
66+
goal_.images.clear();
6467
goal_.images.push_back(*image_);
6568
goal_.reset = true;
6669
goal_.sampling_config.temp = 0.0;
@@ -99,6 +102,61 @@ void CheckPolicy::image_callback(
99102
RCLCPP_INFO_ONCE(node_->get_logger(), "Image received in CheckPolicy");
100103
}
101104

105+
std::string trim_copy(const std::string & s)
106+
{
107+
auto start = std::find_if_not(s.begin(), s.end(),
108+
[](unsigned char c) { return std::isspace(c); });
109+
auto end = std::find_if_not(s.rbegin(), s.rend(),
110+
[](unsigned char c) { return std::isspace(c); }).base();
111+
112+
if (start >= end) {
113+
return "";
114+
}
115+
return std::string(start, end);
116+
}
117+
118+
std::string sanitize_llm_output(std::string text)
119+
{
120+
// 1) quitar bloques <think>...</think>
121+
text = std::regex_replace(text, std::regex(R"(<think>.*?</think>)"), "");
122+
123+
// 2) quitar tags sueltos <think>, </think> y cualquier otro <...>
124+
text = std::regex_replace(text, std::regex(R"(</?think>)"), "");
125+
text = std::regex_replace(text, std::regex(R"(<[^>]+>)"), "");
126+
127+
// 3) si existe 'the guest is', quedarse desde ahí
128+
// std::string anchor = "the guest is";
129+
// auto pos = text.find(anchor);
130+
// if (pos != std::string::npos) {
131+
// text = text.substr(pos);
132+
// }
133+
134+
// 4) quitar saltos de línea
135+
text = std::regex_replace(text, std::regex(R"([\r\n\t]+)"), " ");
136+
137+
// 5) quitar comillas y paréntesis
138+
text = std::regex_replace(text, std::regex(R"(["])"), "");
139+
text = std::regex_replace(text, std::regex(R"([()])"), "");
140+
text = std::regex_replace(text, std::regex(R"([!])"), "");
141+
142+
// 6) cambiar guiones por espacio
143+
text = std::regex_replace(text, std::regex(R"(-)"), " ");
144+
145+
// 7) colapsar espacios múltiples
146+
text = std::regex_replace(text, std::regex(R"(\s{2,})"), " ");
147+
148+
// 8) trim
149+
text = trim_copy(text);
150+
151+
// 9) quedarnos con una sola frase si hay varias
152+
// auto dot_pos = text.find('.');
153+
// if (dot_pos != std::string::npos) {
154+
// text = text.substr(0, dot_pos + 1);
155+
// }
156+
157+
return text;
158+
}
159+
102160
BT::NodeStatus CheckPolicy::on_success()
103161
{
104162
fprintf(stderr, "%s\n", result_.result->response.text.c_str());
@@ -110,24 +168,18 @@ BT::NodeStatus CheckPolicy::on_success()
110168
if (result_.result->response.text.empty() || result_.result->response.text == "{}") {
111169
return BT::NodeStatus::FAILURE;
112170
}
113-
std::string answer = result_.result->response.text;
114-
setOutput("output_text", answer);
171+
172+
std::string answer = sanitize_llm_output(result_.result->response.text);
173+
115174
RCLCPP_INFO(
116175
node_->get_logger(), "CheckPolicy extracted answer: %s",
117176
answer.c_str());
118177

119-
answer.erase(
120-
std::remove_if(
121-
answer.begin(), answer.end(),
122-
[](unsigned char c) {return !std::isalnum(c);}), answer.end());
123-
std::transform(
124-
answer.begin(), answer.end(), answer.begin(),
125-
[](unsigned char c) {return std::tolower(c);});
126-
127178
if (answer.empty()) {
128179
return BT::NodeStatus::FAILURE;
129180
}
130181

182+
setOutput("output_text", answer);
131183
return BT::NodeStatus::SUCCESS;
132184
}
133185

bt_nodes/perception/src/perception/set_persistent_id.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ void SetPersistentId::on_tick()
3838
int id;
3939
if (!getInput("id", id)) {
4040
RCLCPP_ERROR(node_->get_logger(), "Missing ID in SetPersistentId");
41+
setStatus(BT::NodeStatus::FAILURE);
42+
}else{
43+
request_->id = id;
4144
}
42-
43-
request_->id = id;
4445
}
4546

4647
void SetPersistentId::on_result()

robocup_bringup/config/gpsr/gpsr.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ behaviors_main:
22
ros__parameters:
33
use_sim_time: False
44
cam_frame: "head_front_camera_color_optical_frame"
5-
home_position: [54.701, 1.360, 0.001]
5+
home_position: [0.0, 0.0, 0.0]
66
home_pose: "home"
77
offer_pose: "offer"
88
person_id: 001122334455
@@ -29,12 +29,13 @@ behaviors_main:
2929
"kitchen",
3030
"office",
3131
"living_room",
32-
"instruction_point"
32+
"instruction_point",
33+
"bedroom"
3334
]
3435
waypoints:
3536
#ARENA B
36-
tv_table: [-14.936, -0.490, 1.543]
37-
hallway: [-12.272, 0.691, 2.076]
37+
tv_table: [1.42, 3.89, 1.543]
38+
hallway: [1.01, 9.05, 2.076]
3839
hallway_cabinet: [-14.214, 2.942, 1.258]
3940
desk: [-9.134, 2.014, 2.901]
4041
shelf: [-8.354, 0.573, 1.306]
@@ -47,13 +48,14 @@ behaviors_main:
4748
dinner_table: [-9.216, -1.555, -1.775]
4849
kitchen_counter: [-9.312, -4.550, -1.747]
4950
dishwasher: [-10.371, -4.185, -1.762]
50-
entrance: [-11.886, 2.915, 1.952]
51+
entrance: [1.16, 6.19, 1.952]
5152
coffee_table: [-14.142, -2.027, -2.056]
5253
exit: [-8.242, -0.344, -0.441]
53-
kitchen: [-11.626, -0.85, -0.689]
54+
kitchen: [3.79, 6.57, -0.689]
5455
office: [-8.551, 0.033, 2.090]
55-
living_room: [-13.452, -1.870, -2.397]
56-
instruction_point: [-12.933, -0.495, -2.132]
56+
living_room: [1.27, 4.56, -2.397]
57+
instruction_point: [1.16, 6.19, -2.132]
58+
bedroom: [6.31, 1.54, 1.258]
5759
plugins:
5860
- dialogConfirmation_bt_node
5961
- listen_bt_node

robocup_bringup/config/llm.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**:
2+
ros__parameters:
3+
# Model parameters
4+
model:
5+
repo: bartowski/Qwen_Qwen3.5-4B-GGUF
6+
filename: Qwen_Qwen3.5-4B-Q4_K_M.gguf
7+
8+
mmproj:
9+
repo: bartowski/Qwen_Qwen3.5-4B-GGUF
10+
filename: mmproj-Qwen_Qwen3.5-4B-f16.gguf
11+
12+
# Context / inference parameters
13+
context:
14+
n_ctx: 16384
15+
n_batch: 1024
16+
n_predict: 2000
17+
18+
# GPU / backend parameters
19+
gpu:
20+
n_gpu_layers: -1
21+
22+
# CPU parameters
23+
cpu:
24+
n_threads: -1

robocup_bringup/launch/dialog.launch.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from launch.launch_description_sources import PythonLaunchDescriptionSource
2121
from launch.substitutions import LaunchConfiguration
2222
from launch_ros.actions import Node
23-
# from llama_bringup.utils import create_llama_launch
2423

2524

2625
def generate_launch_description():
@@ -66,29 +65,18 @@ def generate_launch_description():
6665
# )
6766

6867
llava_cmd = Node(
69-
package="llama_ros",
70-
executable="llava_node",
71-
name="llava_node",
72-
namespace="llama",
73-
parameters=[{
74-
"context.n_ctx": 2048,
75-
"context.n_batch": 256,
76-
"gpu.n_gpu_layers": 23,
77-
"cpu.n_threads": 4,
78-
"context.n_predict": -1,
79-
80-
# uncomment this for GPSR:
81-
# "model.repo": "cstr/Spaetzle-v60-7b-Q4_0-GGUF",
82-
# "model.filename": "Spaetzle-v60-7b_Q4_0.gguf",
83-
84-
# comment this for GPSR:
85-
"model.repo": 'bartowski/Qwen2-VL-2B-Instruct-GGUF',
86-
"model.filename": 'Qwen2-VL-2B-Instruct-Q4_K_M.gguf',
87-
"mmproj.repo": "bartowski/Qwen2-VL-2B-Instruct-GGUF",
88-
"mmproj.filename": "mmproj-Qwen2-VL-2B-Instruct-f16.gguf",
89-
"prompt.system_prompt_type": "ChatML"
90-
}]
91-
)
68+
package="llama_ros",
69+
executable="llava_node",
70+
name="llava_node",
71+
namespace="llama",
72+
parameters=[
73+
os.path.join(
74+
get_package_share_directory("robocup_bringup"),
75+
"config",
76+
"llm.yaml",
77+
)
78+
],
79+
)
9280

9381
whisper_cmd = IncludeLaunchDescription(
9482
PythonLaunchDescriptionSource(
@@ -134,8 +122,8 @@ def generate_launch_description():
134122
ld.add_action(llava_cmd)
135123
ld.add_action(audio_common_tts_node)
136124
ld.add_action(audio_common_player_node)
137-
ld.add_action(kb_cmd)
125+
# ld.add_action(kb_cmd)
138126

139-
#ld.add_action(music_player_node)
127+
ld.add_action(music_player_node)
140128

141129
return ld

0 commit comments

Comments
 (0)