runtime/rbs_bt_executor/src/MoveToPose.cpp

54 lines
1.8 KiB
C++
Raw Normal View History

2023-12-30 23:42:10 +03:00
// Copyright [2023] bill-finger
2023-02-03 07:04:12 +00:00
#include "rbs_skill_interfaces/action/moveit_send_pose.hpp"
2022-01-31 21:28:39 +04:00
#include "behavior_tree/BtAction.hpp"
2023-11-22 14:43:30 +03:00
#include "behaviortree_cpp_v3/bt_factory.h"
// #include "Eigen/Geometry"
2022-01-31 21:28:39 +04:00
2023-02-03 07:04:12 +00:00
using MoveToPoseAction = rbs_skill_interfaces::action::MoveitSendPose;
2023-11-22 14:43:30 +03:00
class MoveToPose : public BtAction<MoveToPoseAction> {
2023-12-30 23:42:10 +03:00
public:
2023-11-22 14:43:30 +03:00
MoveToPose(const std::string &name, const BT::NodeConfiguration &config)
: BtAction<MoveToPoseAction>(name, config) {}
2022-01-31 21:28:39 +04:00
2023-11-22 14:43:30 +03:00
MoveToPoseAction::Goal populate_goal() override {
getInput<std::string>("robot_name", robot_name_);
getInput<geometry_msgs::msg::Pose>("pose", pose_des);
RCLCPP_INFO(_node->get_logger(),
"\n Send Pose: \n\t pose.x: %f \n\t pose.y: %f \n\t pose.z: %f "
"\n\n\t opientation.x: %f \n\t orientation.y: %f \n\t "
"orientation.z: %f \n\t orientation.w: %f",
pose_des.position.x, pose_des.position.y, pose_des.position.z,
pose_des.orientation.x, pose_des.orientation.y,
pose_des.orientation.z, pose_des.orientation.w);
2022-01-31 21:28:39 +04:00
2023-11-22 14:43:30 +03:00
auto goal = MoveToPoseAction::Goal();
RCLCPP_INFO(_node->get_logger(), "Send goal to robot [%s]",
robot_name_.c_str());
2022-04-01 01:36:48 +08:00
2023-11-22 14:43:30 +03:00
goal.robot_name = robot_name_;
goal.target_pose = pose_des;
2024-04-22 15:06:46 +03:00
goal.end_effector_acceleration = 1.0;
goal.end_effector_velocity = 1.0;
2022-01-31 21:28:39 +04:00
2023-11-22 14:43:30 +03:00
RCLCPP_INFO(_node->get_logger(), "Goal populated");
2022-01-31 21:28:39 +04:00
2023-11-22 14:43:30 +03:00
return goal;
}
2022-01-31 21:28:39 +04:00
2023-12-30 23:42:10 +03:00
static BT::PortsList providedPorts() {
return providedBasicPorts(
{BT::InputPort<std::string>("robot_name"),
BT::InputPort<geometry_msgs::msg::Pose>("pose")});
2023-11-22 14:43:30 +03:00
}
2023-02-03 07:04:12 +00:00
2023-11-22 14:43:30 +03:00
private:
std::string robot_name_;
geometry_msgs::msg::Pose pose_des;
2023-12-30 23:42:10 +03:00
}; // class MoveToPose
2022-01-31 21:28:39 +04:00
2023-11-22 14:43:30 +03:00
BT_REGISTER_NODES(factory) {
factory.registerNodeType<MoveToPose>("MoveToPose");
2023-12-30 23:42:10 +03:00
}