diff --git a/src/moveit_interface.cpp b/src/moveit_interface.cpp index 5c5b74c..dca3ca0 100644 --- a/src/moveit_interface.cpp +++ b/src/moveit_interface.cpp @@ -7,6 +7,10 @@ #include +#include +#include +#include +#include #include "moveit_msgs/msg/robot_trajectory.hpp" #include "geometry_msgs/msg/pose_array.hpp" #include "geometry_msgs/msg/pose_stamped.hpp" @@ -15,7 +19,7 @@ #include "moveit/move_group_interface/move_group_interface.h" #include "moveit_visual_tools/moveit_visual_tools.h" -#include "moveit/robot_model_loader/robot_model_loader.h" +#include "moveit/planning_scene_interface/planning_scene_interface.h" #include "tf2_ros/transform_listener.h" @@ -31,6 +35,7 @@ class MoveitInterface : public rclcpp::Node pose_publisher_ = this->create_publisher("moveit_interface/current_pose", 10); subscriber_ = this->create_subscription("moveit_interface/task_space_trajectory", 10, std::bind(&MoveitInterface::task_space_callback, this, std::placeholders::_1)); execute_sub_ = this->create_subscription("moveit_interface/execution", 10, std::bind(&MoveitInterface::execution_callback, this, std::placeholders::_1)); + box_sub_ = this->create_subscription("moveit_interface/box", 10, std::bind(&MoveitInterface::box_callback, this, std::placeholders::_1)); // Create a shared instance of the current node auto shared_this = std::shared_ptr(this); @@ -39,6 +44,8 @@ class MoveitInterface : public rclcpp::Node static const std::string PLANNING_GROUP = "panda_arm"; move_group_ = std::make_shared(std::shared_ptr(shared_this), PLANNING_GROUP); move_group_->setStartStateToCurrentState(); + planning_scene_interface_ = std::make_shared(); + // Connection to Rviz visual_tools_ = std::make_shared(std::shared_ptr(shared_this), "panda_link0", "move_group", move_group_->getRobotModel()); Eigen::Isometry3d text_pose = Eigen::Isometry3d::Identity(); @@ -49,7 +56,6 @@ class MoveitInterface : public rclcpp::Node tf2_ros::Buffer tf_buffer_{this->get_clock()}; tf2_ros::TransformListener tf_listener_{tf_buffer_}; tf2_timer_ = this->create_wall_timer(std::chrono::milliseconds(200), std::bind(&MoveitInterface::compute_endeffector_pose, this)); - } private: @@ -111,20 +117,58 @@ class MoveitInterface : public rclcpp::Node RCLCPP_WARN(logger, "Trajectroy is not set. Unable to execute."); } } + + //Just for the IML experiment + void box_callback(const std_msgs::msg::Empty::SharedPtr /*msg*/) + { + moveit_msgs::msg::CollisionObject visual_object; + visual_object.header.frame_id = move_group_->getPlanningFrame(); + + visual_object.id = "box1"; + + shape_msgs::msg::SolidPrimitive primitive; + primitive.type = primitive.BOX; + primitive.dimensions.resize(3); + primitive.dimensions[primitive.BOX_X] = 0.2; + primitive.dimensions[primitive.BOX_Y] = 0.2; + primitive.dimensions[primitive.BOX_Z] = 0.4; + + geometry_msgs::msg::Pose box_pose; + box_pose.orientation.w = 1.0; + box_pose.position.x = 0.5; + box_pose.position.y = 0.0; + box_pose.position.z = 0.2; + + visual_object.primitives.push_back(primitive); + visual_object.primitive_poses.push_back(box_pose); + visual_object.operation = visual_object.ADD; + + std::vector visual_objects; + visual_objects.push_back(visual_object); + + planning_scene_interface_->addCollisionObjects(visual_objects); + + } + rclcpp::Publisher::SharedPtr publisher_; rclcpp::Publisher::SharedPtr pose_publisher_; rclcpp::Subscription::SharedPtr subscriber_; rclcpp::Subscription::SharedPtr execute_sub_; + rclcpp::Subscription::SharedPtr box_sub_; std::shared_ptr move_group_; std::shared_ptr visual_tools_; + std::shared_ptr planning_scene_interface_; tf2_ros::Buffer tf_buffer_; tf2_ros::TransformListener tf_listener_; rclcpp::TimerBase::SharedPtr tf2_timer_; + Eigen::Isometry3d text_pose; moveit_msgs::msg::RobotTrajectory trajectory; rclcpp::Logger logger = this->get_logger(); bool trajectory_set; + + }; int main(int argc, char * argv[]) diff --git a/src/scene_interface.cpp b/src/scene_interface.cpp deleted file mode 100644 index e69de29..0000000