Go to the documentation of this file.00001
00046 #include "jaco_driver/jaco_pose_action.h"
00047 #include <jaco_driver/KinovaTypes.h>
00048 #include "jaco_driver/jaco_types.h"
00049
00050 namespace jaco
00051 {
00052
00053 JacoPoseActionServer::JacoPoseActionServer(JacoComm &arm_comm, ros::NodeHandle &n) :
00054 arm(arm_comm),
00055 as_(n, "arm_pose", boost::bind(&JacoPoseActionServer::ActionCallback, this, _1), false)
00056 {
00057 as_.start();
00058 }
00059
00060 JacoPoseActionServer::~JacoPoseActionServer()
00061 {
00062
00063 }
00064
00065 void JacoPoseActionServer::ActionCallback(const jaco_driver::ArmPoseGoalConstPtr &goal)
00066 {
00067 jaco_driver::ArmPoseFeedback feedback;
00068 jaco_driver::ArmPoseResult result;
00069 feedback.pose.header.frame_id = goal->pose.header.frame_id;
00070 result.pose.header.frame_id = goal->pose.header.frame_id;
00071
00072 ROS_INFO("Got a cartesian goal for the arm");
00073
00074 ROS_DEBUG("Raw goal");
00075 ROS_DEBUG("X = %f", goal->pose.pose.position.x);
00076 ROS_DEBUG("Y = %f", goal->pose.pose.position.y);
00077 ROS_DEBUG("Z = %f", goal->pose.pose.position.z);
00078
00079 ROS_DEBUG("RX = %f", goal->pose.pose.orientation.x);
00080 ROS_DEBUG("RY = %f", goal->pose.pose.orientation.y);
00081 ROS_DEBUG("RZ = %f", goal->pose.pose.orientation.z);
00082 ROS_DEBUG("RW = %f", goal->pose.pose.orientation.w);
00083
00084 if (ros::ok()
00085 && !listener.canTransform("/jaco_api_origin", goal->pose.header.frame_id,
00086 goal->pose.header.stamp))
00087 {
00088 ROS_ERROR("Could not get transfrom from /jaco_api_origin to %s, aborting cartesian movement", goal->pose.header.frame_id.c_str());
00089 return;
00090 }
00091
00092 geometry_msgs::PoseStamped local_pose;
00093 local_pose.header.frame_id = "/jaco_api_origin";
00094 listener.transformPose(local_pose.header.frame_id, goal->pose, local_pose);
00095
00096 ROS_DEBUG("Transformed MSG");
00097 ROS_DEBUG("X = %f", local_pose.pose.position.x);
00098 ROS_DEBUG("Y = %f", local_pose.pose.position.y);
00099 ROS_DEBUG("Z = %f", local_pose.pose.position.z);
00100
00101 ROS_DEBUG("RX = %f", local_pose.pose.orientation.x);
00102 ROS_DEBUG("RY = %f", local_pose.pose.orientation.y);
00103 ROS_DEBUG("RZ = %f", local_pose.pose.orientation.z);
00104 ROS_DEBUG("RW = %f", local_pose.pose.orientation.w);
00105
00106 JacoPose cur_position;
00107
00108 if (arm.Stopped())
00109 {
00110 arm.GetPosition(cur_position);
00111 local_pose.pose = cur_position.Pose();
00112
00113 listener.transformPose(result.pose.header.frame_id, local_pose, result.pose);
00114 as_.setAborted(result);
00115 return;
00116 }
00117
00118 JacoPose target(local_pose.pose);
00119 arm.SetPosition(target);
00120
00121 ros::Rate r(10);
00122
00123 const float tolerance = 0.05;
00124
00125
00126 while (true)
00127 {
00128 ros::spinOnce();
00129 if (as_.isPreemptRequested() || !ros::ok())
00130 {
00131 arm.Stop();
00132 arm.Start();
00133 as_.setPreempted();
00134 return;
00135 }
00136
00137 arm.GetPosition(cur_position);
00138 local_pose.pose = cur_position.Pose();
00139
00140 listener.transformPose(feedback.pose.header.frame_id, local_pose, feedback.pose);
00141
00142 if (arm.Stopped())
00143 {
00144 result.pose = feedback.pose;
00145 as_.setAborted(result);
00146 return;
00147 }
00148
00149 as_.publishFeedback(feedback);
00150
00151 if (target.Compare(cur_position, tolerance))
00152 {
00153 ROS_INFO("Cartesian Control Complete.");
00154
00155 result.pose = feedback.pose;
00156 as_.setSucceeded(result);
00157 return;
00158 }
00159
00160 r.sleep();
00161 }
00162 }
00163
00164 }