停障服务接口
功能 | C++ | ROS |
---|---|---|
设置停障参数 | ✔ | ✔ |
开关停障 | ✔ |
设置停障参数
C++ 接口
rcClientInterfaceSetGuardian
简介
cpp
/**
* @brief 设置Guardian参数。
*
* 该函数用于设置Guardian的速度衰减比率和触发源。
*
* @param from 指定操作模式(导航或操纵杆)。
* @param velocity_decay_ratio 指定速度衰减比率。
* @param trigger_source 指定触发源。
* @return bool 返回 `true` 表示设置成功,返回 `false` 表示设置失败。
*/
bool rcClientInterfaceSetGuardian(
common::NAV_OR_JOY_MODE from,
float velocity_decay_ratio,
std::string trigger_source);
使用案例
cpp
robot_control::common::NAV_OR_JOY_MODE mode = robot_control::common::NAV_OR_JOY_MODE::joy_control;
float decay_ratio = 0.5; // 示例值,表示速度衰减比率
std::string source = "SOURCE_A"; // 示例触发源
bool success = rcClientInterfaceSetGuardian(mode, decay_ratio, source);
if (success) {
std::cout << "Guardian Parameters Set Successfully." << std::endl;
} else {
std::cout << "Failed to Set Guardian Parameters." << std::endl;
}
注意事项
- 确保传入的速度衰减比率和触发源是有效的。
ROS2 接口
该接口用于订阅停障指令的guardian
topic。该topic使用daystar_navigation_msgs::msg::Guardian
消息类型,包含停障相关的信息。获得信息后设置停障参数。
Topic 名称 | Topic类型 | 角色 |
---|---|---|
/guardian | daystar_navigation_msgs::msg::Guardian | 订阅方 |
消息结构
daystar_navigation_msgs::msg::Guardian
消息类型根据具体定义,通常包含停障相关的参数。
示例消息
cpp
daystar_navigation_msgs::msg::Guardian guardian_msg;
// 根据daystar_navigation_msgs::msg::Guardian的定义填充消息内容
测试方法
- 发布一次性消息:
bash
ros2 topic pub --once /guardian daystar_navigation_msgs/msg/Guardian "{...}"
- 持续发布消息:
bash
ros2 topic pub --rate 10 /guardian daystar_navigation_msgs/msg/Guardian "{...}"
注意事项
- 确保ROS2节点已启动并正在订阅
guardian
topic。 - 发布的消息格式必须严格符合
daystar_navigation_msgs::msg::Guardian
消息类型的定义。 - 持续发布消息时,注意控制发布频率,避免网络拥塞。
开关停障
C++ 接口
rcClientInterfaceSetGuardianSwitch
简介
cpp
/**
* @brief 开启或关闭Guardian。
*
* 该函数用于开启或关闭Guardian功能。
*
* @param from 指定操作模式(导航或操纵杆)。
* @param enable 指定是否开启Guardian(true表示开启,false表示关闭)。
* @return bool 返回 `true` 表示设置成功,返回 `false` 表示设置失败。
*/
bool rcClientInterfaceSetGuardianSwitch(
robot_control::common::NAV_OR_JOY_MODE from,
bool enable);
使用案例
cpp
robot_control::common::NAV_OR_JOY_MODE mode = robot_control::common::NAV_OR_JOY_MODE::joy_control;
bool enable_guardian = true; // 示例值,表示开启Guardian
bool success = rcClientInterfaceSetGuardianSwitch(mode, enable_guardian);
if (success) {
std::cout << "Guardian Switch Set Successfully." << std::endl;
} else {
std::cout << "Failed to Set Guardian Switch." << std::endl;
}
注意事项
- 确保传入的使能状态是有效的。