test_planning_scene_interface.cpp
Go to the documentation of this file.
00001 /*
00002  * test_nav_sbpl.cpp
00003  *
00004  *  Created on: 2 Jul 2012
00005  *      Author: andreas
00006  */
00007 
00008 #include "tidyup_utils/planning_scene_interface.h"
00009 #include "tidyup_utils/transformer.h"
00010 #include "tidyup_msgs/GetPutdownPose.h"
00011 #include "tidyup_utils/arm_state.h"
00012 #include <sstream>
00013 using std::map;
00014 using namespace std;
00015 
00016 geometry_msgs::Pose defaultAttachPose;
00017 geometry_msgs::Pose robotPose; // 2.90178 -3.04816 0.0509599 0 0 0.848432 0.529304
00018 string separator = " ";
00019 
00020 void attachObjectToArm(const string& putdown_object, const string& arm)
00021 {
00022     PlanningSceneInterface* psi = PlanningSceneInterface::instance();
00023     psi->resetPlanningScene();
00024     arm_navigation_msgs::PlanningScene original = psi->getCurrentScene();
00025 
00026     ROS_INFO("attaching object %s to arm %s", putdown_object.c_str(), arm.c_str());
00027     psi->attachObjectToGripper(putdown_object, arm);
00028     geometry_msgs::Pose pose = defaultAttachPose;
00029     psi->updateObject(putdown_object, pose);
00030 
00031     arm_navigation_msgs::RobotState state = psi->getRobotState();
00032     state.multi_dof_joint_state.poses[0] = robotPose;
00033     ArmState::get("/arm_configurations/side_tuck/position/", "left_arm").replaceJointPositions(state.joint_state);
00034     ArmState::get("/arm_configurations/side_tuck/position/", "right_arm").replaceJointPositions(state.joint_state);
00035     ArmState::get("/arm_configurations/side_carry/position/", arm).replaceJointPositions(state.joint_state);
00036     psi->setRobotState(state);
00037 
00038 //    ROS_INFO_STREAM("before send: " << *psi->getAttachedCollisionObject(putdown_object));
00039     psi->sendDiff();
00040 //    ROS_INFO_STREAM("after send: " << *psi->getAttachedCollisionObject(putdown_object));
00041     psi->printDiffToCurrent(original);
00042 //    psi->printObjects();
00043 
00044     tidyup_msgs::GetPutdownPose srv;
00045     srv.request.arm = arm;
00046     srv.request.putdown_object = putdown_object;
00047     srv.request.static_object = "table2_loc4";
00048     if (ros::service::call("/tidyup/request_putdown_pose", srv))
00049     {
00050         if (srv.response.error_code.val == arm_navigation_msgs::ArmNavigationErrorCodes::SUCCESS)
00051             ROS_INFO_STREAM("response: " << srv.response.putdown_pose);
00052         else
00053             ROS_ERROR_STREAM("failed: " << srv.response.error_code);
00054     }
00055     else
00056     {
00057         ROS_ERROR_STREAM("service call failed.");
00058     }
00059 }
00060 
00061 void writePoseToString(std::stringstream& stream, const geometry_msgs::Pose& pose)
00062 {
00063     stream << pose.position.x << separator;
00064     stream << pose.position.y << separator;
00065     stream << pose.position.z << separator;
00066     stream << pose.orientation.x << separator;
00067     stream << pose.orientation.y << separator;
00068     stream << pose.orientation.z << separator;
00069     stream << pose.orientation.w << separator;
00070 }
00071 
00072 bool readPoseFromString(std::stringstream& stream, geometry_msgs::Pose& pose)
00073 {
00074     vector<double> coordinates;
00075     coordinates.resize(7);
00076     for(size_t i = 0; ! stream.eof() && i < coordinates.size(); i++)
00077     {
00078         stream >> coordinates[i];
00079     }
00080     if (!stream.good())
00081         return false;
00082     pose.position.x = coordinates[0];
00083     pose.position.y = coordinates[1];
00084     pose.position.z = coordinates[2];
00085     pose.orientation.x = coordinates[3];
00086     pose.orientation.y = coordinates[4];
00087     pose.orientation.z = coordinates[5];
00088     pose.orientation.w = coordinates[6];
00089     return true;
00090 }
00091 
00092 int main(int argc, char* argv[])
00093 {
00094     // init module code and services
00095     ros::init(argc, argv, "test_planning_scene_interface", ros::init_options::AnonymousName);
00096     ros::NodeHandle nh;
00097     ros::spinOnce();
00098 
00099     defaultAttachPose.position.x = 0.032;
00100     defaultAttachPose.position.y = 0.015;
00101     defaultAttachPose.position.z = 0.0;
00102     defaultAttachPose.orientation.x = 0.707;
00103     defaultAttachPose.orientation.y = -0.106;
00104     defaultAttachPose.orientation.z = -0.690;
00105     defaultAttachPose.orientation.w = 0.105;
00106 
00107     robotPose.position.x = 2.90178;
00108     robotPose.position.y = -3.04816;
00109     robotPose.position.z = 0.0509599;
00110     robotPose.orientation.x = 0.0;
00111     robotPose.orientation.y = 0.0;
00112     robotPose.orientation.z = 0.848432;
00113     robotPose.orientation.w = 0.529304;
00114 
00115 //    std::stringstream formatter;
00116 //    formatter.precision(3);
00117 //    formatter << std::fixed;
00118 //
00119 //    writePoseToString(formatter, defaultAttachPose);
00121 //
00122 //    string serialized = formatter.str();
00123 //    ROS_INFO("serialized: %s", serialized.c_str());
00124 //
00129 //
00130 //    formatter.flush();
00132 
00133 //    geometry_msgs::Pose newPose1;
00134 //    geometry_msgs::Pose newPose2;
00135 //
00136 //    if (! readPoseFromString(formatter, newPose1))
00137 //    {
00138 //        ROS_ERROR("pose decode error");
00139 //    }
00140 //    else
00141 //    {
00142 //        ROS_INFO_STREAM("pose1: "<< newPose1);
00143 //    }
00144 //    if (! readPoseFromString(formatter, newPose2))
00145 //    {
00146 //        ROS_ERROR("pose2 decode error");
00147 //    }
00148 //    else
00149 //    {
00150 //        ROS_INFO_STREAM("pose2: "<< newPose2);
00151 //    }
00152 //
00153 //    return 0;
00154 
00155 //    PlanningSceneInterface::instance()->test();
00156     attachObjectToArm("cup_0", "left_arm");
00157     attachObjectToArm("cup_0", "right_arm");
00158     attachObjectToArm("cup_1", "left_arm");
00159     attachObjectToArm("cup_1", "right_arm");
00160 
00161 //    ros::spin();
00162 }
00163 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


tidyup_tools
Author(s): Andreas Hertle, Christian Dornhege
autogenerated on Wed Dec 26 2012 15:50:57