00001 #include <ros/ros.h>
00002 #include <kinematics_msgs/GetKinematicSolverInfo.h>
00003 #include <kinematics_msgs/GetConstraintAwarePositionIK.h>
00004 #include <sensor_msgs/JointState.h>
00005 #include <ompl/util/RandomNumbers.h>
00006 #include <tf/transform_broadcaster.h>
00007 #include <tf/transform_datatypes.h>
00008 #include <arm_navigation_msgs/DisplayTrajectory.h>
00009
00010 int main(int argc, char **argv)
00011 {
00012 ros::init(argc, argv, "get_constraint_aware_ik_test");
00013 ros::NodeHandle rh;
00014 ros::NodeHandle pn("~");
00015
00016 ROS_DEBUG("Starting 'get_constraint_aware_ik_test'...");
00017
00018 std::string ik_service;
00019 pn.param<std::string> ("ik_service", ik_service, "katana_constraint_aware_kinematics/get_constraint_aware_ik");
00020
00021 ros::service::waitForService(ik_service);
00022 ros::service::waitForService("katana_constraint_aware_kinematics/get_ik_solver_info");
00023
00024
00025
00026 ros::ServiceClient ik_client_ =
00027 rh.serviceClient<kinematics_msgs::GetConstraintAwarePositionIK> (ik_service);
00028 ros::ServiceClient query_client =
00029 rh.serviceClient<kinematics_msgs::GetKinematicSolverInfo> ("katana_constraint_aware_kinematics/get_ik_solver_info");
00030 ROS_ERROR("Connect to the necessary services...");
00031
00032
00033 ompl::RNG rng = ompl::RNG();
00034 kinematics_msgs::GetKinematicSolverInfo::Request request;
00035 kinematics_msgs::GetKinematicSolverInfo::Response response;
00036
00037 sensor_msgs::JointState initialState;
00038 arm_navigation_msgs::DisplayTrajectory planned_robot_pose;
00039
00040 if (query_client.call(request, response))
00041 {
00042 for (unsigned int i = 0; i < response.kinematic_solver_info.joint_names.size(); i++)
00043 {
00044
00045
00046 }
00047
00048
00049 initialState.header.stamp = ros::Time::now();
00050 initialState.name = response.kinematic_solver_info.joint_names;
00051 initialState.position.resize(response.kinematic_solver_info.joint_names.size());
00052
00053 for (unsigned int i = 0; i < response.kinematic_solver_info.joint_names.size(); i++)
00054 {
00055
00056
00057
00058
00059
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 }
00080 else
00081 {
00082 ROS_ERROR("Could not call query service");
00083 ros::shutdown();
00084 exit(1);
00085 }
00086
00087
00088 kinematics_msgs::GetConstraintAwarePositionIK::Request gcapik_req;
00089 kinematics_msgs::GetConstraintAwarePositionIK::Response gcapik_res;
00090
00091 sensor_msgs::JointState jointState = initialState;
00092
00093 tf::TransformBroadcaster br;
00094 tf::Transform transform;
00095
00096 do
00097 {
00098 gcapik_req.timeout = ros::Duration(5.0);
00099 gcapik_req.ik_request.ik_link_name = "katana_gripper_tool_frame";
00100
00101
00102
00103
00104 gcapik_req.ik_request.pose_stamped.header.frame_id = "katana_base_link";
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 gcapik_req.ik_request.pose_stamped.pose.position.x = rng.uniformReal(-0.15, 0.15);
00121 gcapik_req.ik_request.pose_stamped.pose.position.y = rng.uniformReal(-0.15, 0.15);
00122 gcapik_req.ik_request.pose_stamped.pose.position.z = rng.uniformReal(-0.10, 0.40);
00123
00124 double value[4];
00125
00126 rng.quaternion(value);
00127
00128 gcapik_req.ik_request.pose_stamped.pose.orientation.x = value[0];
00129 gcapik_req.ik_request.pose_stamped.pose.orientation.y = value[1];
00130 gcapik_req.ik_request.pose_stamped.pose.orientation.z = value[2];
00131 gcapik_req.ik_request.pose_stamped.pose.orientation.w = value[3];
00132
00133
00134
00135 transform.setOrigin(tf::Vector3(gcapik_req.ik_request.pose_stamped.pose.position.x,
00136 gcapik_req.ik_request.pose_stamped.pose.position.y,
00137 gcapik_req.ik_request.pose_stamped.pose.position.z));
00138
00139 transform.setRotation(tf::Quaternion(gcapik_req.ik_request.pose_stamped.pose.orientation.x,
00140 gcapik_req.ik_request.pose_stamped.pose.orientation.y,
00141 gcapik_req.ik_request.pose_stamped.pose.orientation.z,
00142 gcapik_req.ik_request.pose_stamped.pose.orientation.w));
00143
00144 br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "katana_base_link", "katana_goal_pose"));
00145
00146 ROS_DEBUG("cartesian goal pose orientation: %f, %f, %f", gcapik_req.ik_request.pose_stamped.pose.position.x,
00147 gcapik_req.ik_request.pose_stamped.pose.position.y,
00148 gcapik_req.ik_request.pose_stamped.pose.position.z);
00149
00150 ROS_DEBUG("cartesian goal pose orientation: %f, %f, %f, %f", gcapik_req.ik_request.pose_stamped.pose.orientation.x,
00151 gcapik_req.ik_request.pose_stamped.pose.orientation.y,
00152 gcapik_req.ik_request.pose_stamped.pose.orientation.z,
00153 gcapik_req.ik_request.pose_stamped.pose.orientation.w);
00154
00155 gcapik_req.ik_request.ik_seed_state.joint_state.position.resize(response.kinematic_solver_info.joint_names.size());
00156
00157 gcapik_req.ik_request.ik_seed_state.joint_state.name = response.kinematic_solver_info.joint_names;
00158
00159
00160
00161
00162
00163
00164 for (unsigned int i = 0; i < response.kinematic_solver_info.joint_names.size(); i++)
00165 {
00166 gcapik_req.ik_request.ik_seed_state.joint_state.position[i]
00167 = (response.kinematic_solver_info.limits[i].min_position
00168 + response.kinematic_solver_info.limits[i].max_position) / 2.0;
00169 }
00170
00171
00172 ros::Rate loop_rate1(100);
00173 ros::Time end_time = ros::Time::now() + ros::Duration(0.3);
00174
00175 while (ros::ok() && ros::Time::now() < end_time)
00176 {
00177 jointState.header.stamp = ros::Time::now();
00178
00179
00180 br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "katana_base_link", "katana_goal_pose"));
00181
00182 loop_rate1.sleep();
00183 }
00184
00185
00186
00187 bool success = ik_client_.call(gcapik_req, gcapik_res);
00188
00189
00190
00191
00192 if (!success)
00193 {
00194 ROS_ERROR("Could not call service");
00195 break;
00196 }
00197
00198 } while (gcapik_res.error_code.val != gcapik_res.error_code.SUCCESS);
00199
00200
00201 ROS_INFO("Joint Set Up...");
00202
00203 for (unsigned int i = 0; i < gcapik_res.solution.joint_state.name.size(); i++)
00204 {
00205 ROS_INFO("Joint: %s - %f",gcapik_res.solution.joint_state.name[i].c_str(),gcapik_res.solution.joint_state.position[i]);
00206
00207 }
00208
00209 ROS_INFO("...leads to:");
00210
00211
00212 ROS_INFO("pose position: %f, %f, %f", gcapik_req.ik_request.pose_stamped.pose.position.x,
00213 gcapik_req.ik_request.pose_stamped.pose.position.y,
00214 gcapik_req.ik_request.pose_stamped.pose.position.z);
00215
00216 ROS_INFO("pose orientation: %f, %f, %f, %f", gcapik_req.ik_request.pose_stamped.pose.orientation.x,
00217 gcapik_req.ik_request.pose_stamped.pose.orientation.y,
00218 gcapik_req.ik_request.pose_stamped.pose.orientation.z,
00219 gcapik_req.ik_request.pose_stamped.pose.orientation.w);
00220
00221 btScalar roll, pitch, yaw;
00222 btQuaternion q = btQuaternion(gcapik_req.ik_request.pose_stamped.pose.orientation.x,
00223 gcapik_req.ik_request.pose_stamped.pose.orientation.y,
00224 gcapik_req.ik_request.pose_stamped.pose.orientation.z,
00225 gcapik_req.ik_request.pose_stamped.pose.orientation.w);
00226
00227 btMatrix3x3(q).getRPY(roll, pitch, yaw);
00228
00229 ROS_INFO("pose orientation RPY: %f, %f, %f", roll, pitch, yaw);
00230
00231 ROS_INFO("...");
00232
00233
00234 jointState = gcapik_res.solution.joint_state;
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 ros::Rate loop_rate(100);
00250
00251 while (ros::ok())
00252 {
00253 ROS_DEBUG("Publish goal state");
00254
00255 jointState.header.stamp = ros::Time::now();
00256
00257
00258 br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "katana_base_link", "katana_goal_pose"));
00259
00260 loop_rate.sleep();
00261 }
00262 }
00263