2023-02-03 07:04:12 +00:00
|
|
|
#include "rbs_skill_interfaces/action/moveit_send_pose.hpp"
|
2022-03-29 02:23:01 +08:00
|
|
|
|
2022-01-31 21:28:39 +04:00
|
|
|
#include "behaviortree_cpp_v3/bt_factory.h"
|
|
|
|
#include "behavior_tree/BtAction.hpp"
|
2022-02-07 18:34:33 +04:00
|
|
|
#include "geometry_msgs/msg/pose_stamped.hpp"
|
2022-02-10 23:15:37 +04:00
|
|
|
#include "moveit_msgs/action/move_group.h"
|
2022-03-29 02:23:01 +08:00
|
|
|
// #include "Eigen/Geometry"
|
2022-03-12 13:29:26 +04:00
|
|
|
#include "rclcpp/parameter.hpp"
|
2022-01-31 21:28:39 +04:00
|
|
|
|
|
|
|
using namespace BT;
|
2023-02-03 07:04:12 +00:00
|
|
|
using MoveToPoseAction = rbs_skill_interfaces::action::MoveitSendPose;
|
2022-03-16 00:50:12 +04:00
|
|
|
static const rclcpp::Logger LOGGER = rclcpp::get_logger("MoveToPoseActionClient");
|
2022-01-31 21:28:39 +04:00
|
|
|
|
|
|
|
class MoveToPose : public BtAction<MoveToPoseAction>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MoveToPose(const std::string & name, const BT::NodeConfiguration & config)
|
2022-04-01 01:36:48 +08:00
|
|
|
: BtAction<MoveToPoseAction>(name, config)
|
|
|
|
{
|
2023-02-03 07:04:12 +00:00
|
|
|
RCLCPP_INFO(_node->get_logger(), "Start the node");
|
2022-01-31 21:28:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MoveToPoseAction::Goal populate_goal() override
|
|
|
|
{
|
2022-04-01 01:36:48 +08:00
|
|
|
getInput<std::string>("robot_name", robot_name_);
|
2023-03-31 20:24:56 +00:00
|
|
|
getInput<std::vector<double>>("pose", pose_);
|
|
|
|
|
|
|
|
pose_des.position.x = pose_[0];
|
|
|
|
pose_des.position.y = pose_[1];
|
|
|
|
pose_des.position.z = pose_[2];
|
|
|
|
pose_des.orientation.x = pose_[3];
|
|
|
|
pose_des.orientation.y = pose_[4];
|
|
|
|
pose_des.orientation.z = pose_[5];
|
|
|
|
pose_des.orientation.w = pose_[6];
|
2023-02-05 17:04:54 +03:00
|
|
|
|
2022-03-29 02:23:01 +08:00
|
|
|
|
2023-02-05 17:04:54 +03:00
|
|
|
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",
|
2023-02-03 07:04:12 +00:00
|
|
|
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-04-01 01:36:48 +08:00
|
|
|
|
2022-02-07 18:34:33 +04:00
|
|
|
auto goal = MoveToPoseAction::Goal();
|
2022-04-01 01:36:48 +08:00
|
|
|
RCLCPP_INFO(_node->get_logger(), "Send goal to robot [%s]", robot_name_.c_str());
|
|
|
|
|
2022-02-02 21:47:26 +04:00
|
|
|
goal.robot_name = robot_name_;
|
2023-02-03 07:04:12 +00:00
|
|
|
goal.target_pose = pose_des;
|
2023-03-31 20:24:56 +00:00
|
|
|
goal.end_effector_acceleration = 0.5;
|
|
|
|
goal.end_effector_velocity = 0.5;
|
2022-04-01 01:36:48 +08:00
|
|
|
|
2022-02-07 18:34:33 +04:00
|
|
|
RCLCPP_INFO(_node->get_logger(), "Goal populated");
|
2022-01-31 21:28:39 +04:00
|
|
|
|
|
|
|
return goal;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PortsList providedPorts()
|
|
|
|
{
|
|
|
|
return providedBasicPorts({
|
2022-04-01 01:36:48 +08:00
|
|
|
InputPort<std::string>("robot_name"),
|
2023-03-31 20:24:56 +00:00
|
|
|
InputPort<std::vector<double>>("pose")
|
2022-04-01 01:36:48 +08:00
|
|
|
});
|
2022-01-31 21:28:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-02-02 21:47:26 +04:00
|
|
|
std::string robot_name_;
|
2023-03-31 20:24:56 +00:00
|
|
|
std::vector<double> pose_;
|
2023-02-03 07:04:12 +00:00
|
|
|
geometry_msgs::msg::Pose pose_des;
|
|
|
|
std::map<std::string, geometry_msgs::msg::Pose> Poses;
|
|
|
|
|
2023-02-05 17:04:54 +03:00
|
|
|
// geometry_msgs::msg::Pose array_to_pose(std::vector<double> pose_array){
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
2022-01-31 21:28:39 +04:00
|
|
|
|
|
|
|
}; // class MoveToPose
|
|
|
|
|
|
|
|
BT_REGISTER_NODES(factory)
|
|
|
|
{
|
|
|
|
factory.registerNodeType<MoveToPose>("MoveToPose");
|
|
|
|
}
|