metablock.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 SoftBank Robotics Europe
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015 */
00016 
00017 #include <Eigen/Eigen>
00018 #include <stdlib.h>
00019 
00020 #include "romeo_moveit_actions/metablock.hpp"
00021 #include "romeo_moveit_actions/toolsForObject.hpp"
00022 
00023 namespace moveit_simple_actions
00024 {
00025 
00026 MetaBlock::MetaBlock(const std::string name,
00027                      const geometry_msgs::Pose pose,
00028                      const uint &shapeType,
00029                      const float &size_x,
00030                      const float &size_y,
00031                      const float &size_z,
00032                      ros::Time timestamp,
00033                      std::string base_frame):
00034     name_(name),
00035     pose_(pose),
00036     size_x_(size_x),
00037     size_y_(size_y),
00038     size_z_(size_z),
00039     timestamp_(timestamp),
00040     base_frame_(base_frame)
00041 {
00042   if (pose_.position.y < 0)
00043     pose_.orientation.y *= -1;
00044 
00045   goal_pose_ = pose_;
00046   if (pose_.position.y < 0)
00047     goal_pose_.position.y -= 0.2;
00048   else
00049     goal_pose_.position.y += 0.2;
00050 
00051   //setshape
00052   sprimitive solidPrimitive;
00053   if (shapeType == sprimitive::CYLINDER)
00054   {
00055     solidPrimitive.type = sprimitive::CYLINDER;
00056     solidPrimitive.dimensions.resize(geometric_shapes::SolidPrimitiveDimCount<sprimitive::CYLINDER>::value);
00057     solidPrimitive.dimensions[sprimitive::CYLINDER_HEIGHT] = size_y;
00058     solidPrimitive.dimensions[sprimitive::CYLINDER_RADIUS] = size_x;
00059   }
00060   else
00061   {
00062     solidPrimitive.type = sprimitive::BOX;
00063     solidPrimitive.dimensions.resize(geometric_shapes::SolidPrimitiveDimCount<sprimitive::BOX>::value);
00064     solidPrimitive.dimensions[sprimitive::BOX_X] = size_x;
00065     solidPrimitive.dimensions[sprimitive::BOX_Y] = size_y;
00066     solidPrimitive.dimensions[sprimitive::BOX_Z] = size_z;
00067   }
00068   shape_ = solidPrimitive;
00069 
00070   //create collision object
00071   collObj_.header.stamp = ros::Time::now();
00072   collObj_.header.frame_id = base_frame_;
00073   collObj_.id = name_;
00074   collObj_.operation = mcollobj::ADD;
00075   collObj_.primitives.resize(1);
00076   if (shape_.dimensions.size() > 0)
00077     collObj_.primitives[0] = shape_;
00078   collObj_.primitive_poses.resize(1);
00079   collObj_.primitive_poses[0] = pose_;
00080 }
00081 
00082 MetaBlock::MetaBlock(const std::string name,
00083                      const geometry_msgs::Pose pose,
00084                      const shape_msgs::Mesh mesh,
00085                      const object_recognition_msgs::ObjectType type,
00086                      ros::Time timestamp,
00087                      std::string base_frame):
00088     name_(name),
00089     pose_(pose),
00090     size_x_(0.03),
00091     size_y_(0.115),
00092     size_z_(0.01),
00093     timestamp_(timestamp),
00094     base_frame_(base_frame)
00095 {
00096   pose_.orientation.x = -1.0;
00097   pose_.orientation.y = 0.0;
00098   pose_.orientation.z = 0.0;
00099   pose_.orientation.w = 0.0;
00100 
00101   goal_pose_ = pose_;
00102   goal_pose_.position.x = 0.4;
00103   goal_pose_.position.y = 0.3;
00104   goal_pose_.position.z = -0.05;
00105   if (pose_.position.y < 0)
00106     goal_pose_.position.y *= -1;
00107 
00108   mesh_ = mesh;
00109   type_ = type;
00110 
00111   //create collision object
00112   collObj_.header.stamp = ros::Time::now();
00113   collObj_.header.frame_id = base_frame_;
00114   collObj_.id = name_;
00115   collObj_.operation = mcollobj::ADD;
00116   collObj_.meshes.resize(1);
00117   collObj_.meshes[0] = mesh;
00118   collObj_.mesh_poses.resize(1);
00119   collObj_.mesh_poses[0] = pose_;
00120 }
00121 
00122 void MetaBlock::updatePose(const geometry_msgs::Pose &pose)
00123 {
00124   pose_ = pose;
00125   if (collObj_.primitive_poses.size() > 0)
00126     collObj_.primitive_poses[0] = pose;
00127 }
00128 
00129 void MetaBlock::updatePoseVis(const geometry_msgs::Pose &pose)
00130 {
00131   if (collObj_.primitive_poses.size() > 0)
00132     collObj_.primitive_poses[0] = pose;
00133 }
00134 
00135 void MetaBlock::removeBlock(mscene *current_scene)
00136 {
00137   // Remove/Add collision object
00138   std::vector<std::string> objects_id;
00139   objects_id.resize(1);
00140   objects_id[0] = name_;
00141   current_scene->removeCollisionObjects(objects_id);
00142 }
00143 
00144 void MetaBlock::publishBlock(mscene *current_scene)
00145 {
00146   std::vector<moveit_msgs::CollisionObject> coll_objects;
00147   coll_objects.push_back(collObj_);
00148   current_scene->addCollisionObjects(coll_objects);
00149   sleep(0.6);
00150 }
00151 
00152 void MetaBlock::updatePose(mscene *current_scene,
00153                            const geometry_msgs::Pose &pose)
00154 {
00155   updatePose(pose);
00156 
00157   //pub_obj_moveit->publish(collObj_);
00158   std::vector<moveit_msgs::CollisionObject> coll_objects;
00159   coll_objects.push_back(collObj_);
00160   current_scene->addCollisionObjects(coll_objects);
00161   sleep(0.5);
00162 }
00163 
00164 tf::Stamped<tf::Pose> MetaBlock::getTransform(tf::TransformListener *listener,
00165                                               const std::string &frame)
00166 {
00167   tf::Stamped<tf::Pose> pose_to_robot;
00168 
00169   tf::Stamped<tf::Pose> tf_obj(
00170         tf::Pose(
00171           tf::Quaternion(pose_.orientation.x,
00172                          pose_.orientation.y,
00173                          pose_.orientation.z,
00174                          pose_.orientation.w),
00175           tf::Vector3(pose_.position.x,
00176                       pose_.position.y,
00177                       pose_.position.z)),
00178       ros::Time(0), base_frame_);
00179 
00180   //transform the pose
00181   try
00182   {
00183     listener->transformPose(frame, tf_obj, pose_to_robot);
00184   }
00185   catch (tf::TransformException ex)
00186   {
00187    ROS_ERROR("%s",ex.what());
00188   }
00189 
00190 /*  ROS_INFO_STREAM("The pose to the object "
00191                  << " " << pose_to_robot.getOrigin().x()
00192                  << " " << pose_to_robot.getOrigin().y()
00193                  << " " << pose_to_robot.getOrigin().z()
00194                  );*/
00195   return pose_to_robot;
00196 }
00197 
00198 geometry_msgs::PoseStamped MetaBlock::getTransformed(tf::TransformListener *listener,
00199                                                      const std::string &frame)
00200 {
00201   geometry_msgs::PoseStamped pose_to_robot;
00202 
00203   geometry_msgs::PoseStamped pose_obj;
00204   pose_obj.header.stamp = ros::Time(0);
00205   pose_obj.header.frame_id = base_frame_;
00206   pose_obj.pose = pose_;
00207 
00208   //the the pose
00209   try
00210   {
00211     listener->transformPose(frame, pose_obj, pose_to_robot);
00212   }
00213   catch (tf::TransformException ex)
00214   {
00215    ROS_ERROR("%s",ex.what());
00216   }
00217 
00218 /*  ROS_INFO_STREAM("The pose to the object "
00219                  << " " << pose_to_robot.getOrigin().x()
00220                  << " " << pose_to_robot.getOrigin().y()
00221                  << " " << pose_to_robot.getOrigin().z()
00222                  );*/
00223   return pose_to_robot;
00224 }
00225 }


romeo_moveit_actions
Author(s):
autogenerated on Thu Jun 6 2019 21:57:24