修复了rosbag录制服务崩溃的bug
This commit is contained in:
+10
-10
@@ -66,19 +66,19 @@ start_bag_recorder() {
|
|||||||
echo "Rosbag log: ${BAG_LOG_FILE}"
|
echo "Rosbag log: ${BAG_LOG_FILE}"
|
||||||
|
|
||||||
: > "${BAG_LOG_FILE}"
|
: > "${BAG_LOG_FILE}"
|
||||||
setsid bash -lc "
|
setsid env WS_DIR="${WS_DIR}" bash -lc '
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
set +u
|
set +u
|
||||||
source '${WS_DIR}/install/setup.bash'
|
source "${WS_DIR}/install/setup.bash"
|
||||||
set -u
|
set -u
|
||||||
while true; do
|
while true; do
|
||||||
start_time=\\\$(date +%Y%m%d_%H%M%S)
|
start_time=$(date +%Y%m%d_%H%M%S)
|
||||||
output=/tmp/lbot_arm_\\${start_time}.mcap
|
output=/tmp/lbot_arm_${start_time}.mcap
|
||||||
echo \"Starting rosbag: \\${output}\"
|
echo "Starting rosbag: ${output}"
|
||||||
set +e
|
set +e
|
||||||
timeout 3600 ros2 bag record \
|
timeout 3600 ros2 bag record \
|
||||||
--storage mcap \
|
--storage mcap \
|
||||||
--output \"\\${output}\" \
|
--output "${output}" \
|
||||||
--polling-interval 2 \
|
--polling-interval 2 \
|
||||||
--include-unpublished-topics \
|
--include-unpublished-topics \
|
||||||
--disable-keyboard-controls \
|
--disable-keyboard-controls \
|
||||||
@@ -92,13 +92,13 @@ start_bag_recorder() {
|
|||||||
--services \
|
--services \
|
||||||
/robot1/left_arm/move_joint \
|
/robot1/left_arm/move_joint \
|
||||||
/robot1/right_arm/move_joint
|
/robot1/right_arm/move_joint
|
||||||
rc=\\$?
|
rc=$?
|
||||||
set -e
|
set -e
|
||||||
if [[ \\${rc} -ne 124 ]]; then
|
if [[ ${rc} -ne 124 ]]; then
|
||||||
exit \\${rc}
|
exit ${rc}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
" >> "${BAG_LOG_FILE}" 2>&1 &
|
' >> "${BAG_LOG_FILE}" 2>&1 &
|
||||||
|
|
||||||
local pid=$!
|
local pid=$!
|
||||||
local pgid
|
local pgid
|
||||||
|
|||||||
@@ -144,7 +144,8 @@ bool LBot::connect_robot() {
|
|||||||
g_conn_state.store(GlobalConnState::CONNECTING); // 更新全局状态
|
g_conn_state.store(GlobalConnState::CONNECTING); // 更新全局状态
|
||||||
|
|
||||||
lbot_handle = lbot_api.lbot_init(arm_ip_.c_str());
|
lbot_handle = lbot_api.lbot_init(arm_ip_.c_str());
|
||||||
if (lbot_handle->id > 0) {
|
bool success = lbot_handle != nullptr && lbot_handle->id > 0;
|
||||||
|
if (success) {
|
||||||
RCLCPP_INFO(this->get_logger(), "Connected to LBot at %s", arm_ip_.c_str());
|
RCLCPP_INFO(this->get_logger(), "Connected to LBot at %s", arm_ip_.c_str());
|
||||||
|
|
||||||
// 获取机械臂信息
|
// 获取机械臂信息
|
||||||
@@ -169,11 +170,10 @@ bool LBot::connect_robot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
RCLCPP_ERROR(this->get_logger(), "Failed to connect to LBot");
|
RCLCPP_ERROR(this->get_logger(), "Failed to connect to LBot, UDP reconnecting");
|
||||||
publish_system_error(-1, "Failed to connect to LBot");
|
publish_system_error(-1, "UDP Reconnecting");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = lbot_handle->id > 0;
|
|
||||||
conn_state_ = success ? GlobalConnState::CONNECTED : GlobalConnState::DISCONNECTED;
|
conn_state_ = success ? GlobalConnState::CONNECTED : GlobalConnState::DISCONNECTED;
|
||||||
g_conn_state.store(conn_state_); // 更新全局状态
|
g_conn_state.store(conn_state_); // 更新全局状态
|
||||||
|
|
||||||
@@ -391,6 +391,10 @@ void LBot::reconnect_timer_callback()
|
|||||||
if (reconnect_thread_running_)
|
if (reconnect_thread_running_)
|
||||||
return; // 线程正在运行,不重复启动
|
return; // 线程正在运行,不重复启动
|
||||||
|
|
||||||
|
if (reconnect_thread_.joinable()) {
|
||||||
|
reconnect_thread_.join();
|
||||||
|
}
|
||||||
|
|
||||||
reconnect_thread_running_ = true;
|
reconnect_thread_running_ = true;
|
||||||
|
|
||||||
reconnect_thread_ = std::thread([this]() {
|
reconnect_thread_ = std::thread([this]() {
|
||||||
|
|||||||
Reference in New Issue
Block a user