Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ include_directories(${PROJECT_SOURCE_DIR}/src)

ament_auto_add_library(rmcs_rl_bridge SHARED
src/rl_bridge.cpp
src/rl_bridge/utility.cpp
src/rl_bridge/parameters.cpp
src/rl_bridge/joint_config.cpp
src/rl_bridge/term_parser.cpp
src/rl_bridge/interface_binding.cpp
src/rl_bridge/observation.cpp
src/rl_bridge/action_channel.cpp
src/policy_server_launcher.cpp
)
target_link_libraries(rmcs_rl_bridge ${cpp_typesupport_target})
Expand Down
9 changes: 3 additions & 6 deletions config/executor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ rmcs_executor:
wheel_leg_infantry_rl:
ros__parameters:
board_serial: ""
hip_kp: 200.0
hip_kd: 4.0
knee_kp: 200.0
knee_kd: 4.0

wheel_leg_chassis_controller:
ros__parameters:
Expand All @@ -29,9 +25,10 @@ wheel_leg_chassis_controller:

rl_bridge:
ros__parameters:
history_length: 1
rl_base: "/wheel_leg/rl"
policy_rate: 50.0
max_action_age: 0.04 # 缺省 = 2 / policy_rate;超时 → valid=0(绝不保持旧动作)
policy_rate: 100.0
max_action_age: 0.02 # 缺省 = 2 / policy_rate;超时 → valid=0(绝不保持旧动作)

rl_obs_size: 28
rl_action_size: 6
Expand Down
16 changes: 7 additions & 9 deletions src/policy_server_launcher.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <cerrno>
#include <chrono>
#include <csignal>
Expand All @@ -21,15 +20,15 @@

namespace rmcs_rl {

// 随 executor 生命周期拉起独立的 policy_server 子进程:
// - 组件只存在于需要 RL 的配置里,非 RL 车不受影响;
// - 子进程设置 PR_SET_PDEATHSIG,executor 结束/崩溃时自动被内核回收,不会留孤儿;
// - update() 低频 waitpid(WNOHANG) 监管,可选退避重启。
// Spawns and supervises an independent policy_server child process for the executor lifetime:
// - the component only exists in RL configs; non-RL robots are unaffected;
// - the child sets PR_SET_PDEATHSIG so the kernel reaps it when executor exits/crashes;
// - update() does a low-frequency waitpid(WNOHANG) poll with optional backoff restart.
class PolicyServerLauncher
: public rmcs_executor::Component
, public rclcpp::Node {
public:
PolicyServerLauncher()
explicit PolicyServerLauncher()
: Node(
get_component_name(),
rclcpp::NodeOptions{}.automatically_declare_parameters_from_overrides(true)) {
Expand Down Expand Up @@ -168,7 +167,7 @@ class PolicyServerLauncher
}

if (pid == 0) {
// 子进程内只调用 async-signal-safe 的接口。
// Only async-signal-safe calls are allowed inside the child.
::prctl(PR_SET_PDEATHSIG, SIGTERM);
if (::getppid() != parent_pid)
::_exit(EXIT_FAILURE);
Expand Down Expand Up @@ -230,8 +229,7 @@ class PolicyServerLauncher

::kill(pid, SIGKILL);
::waitpid(pid, nullptr, 0);
RCLCPP_WARN(
get_logger(), "policy_server (pid=%d) did not stop, killed", static_cast<int>(pid));
RCLCPP_WARN(get_logger(), "policy_server (pid=%d) did not stop, killed", static_cast<int>(pid));
}

bool autostart_ = true;
Expand Down
Loading
Loading