jaco_fingers_action.cpp
Go to the documentation of this file.
00001 
00046 #include "jaco_driver/jaco_fingers_action.h"
00047 #include <jaco_driver/KinovaTypes.h>
00048 #include "jaco_driver/jaco_types.h"
00049 
00050 namespace jaco
00051 {
00052 
00053 JacoFingersActionServer::JacoFingersActionServer(JacoComm &arm_comm, ros::NodeHandle &n) : 
00054     arm(arm_comm), 
00055     as_(n, "finger_joint_angles", boost::bind(&JacoFingersActionServer::ActionCallback, this, _1), false)
00056 {
00057     as_.start();
00058 }
00059 
00060 JacoFingersActionServer::~JacoFingersActionServer()
00061 {
00062 
00063 }
00064 
00065 void JacoFingersActionServer::ActionCallback(const jaco_driver::SetFingersPositionGoalConstPtr &goal)
00066 {
00067         jaco_driver::SetFingersPositionFeedback feedback;
00068         jaco_driver::SetFingersPositionResult result;
00069 
00070         ROS_INFO("Got a finger goal for the arm");
00071 
00072         FingerAngles fingers;           //holds the current position of the fingers
00073 
00074         if (arm.Stopped())
00075         {
00076                 arm.GetFingers(fingers);
00077                 result.fingers = fingers.Fingers();
00078                 as_.setAborted(result);
00079                 return;
00080         }
00081 
00082         FingerAngles target(goal->fingers);
00083         arm.SetFingers(target);
00084 
00085         ros::Rate r(10);
00086  
00087         const float tolerance = 2.0;    //dead zone for position
00088 
00089 
00090         //while we have not timed out
00091         while (true)
00092         {
00093                 ros::spinOnce();
00094                 if (as_.isPreemptRequested() || !ros::ok())
00095                 {
00096                         arm.Stop();
00097                         arm.Start();
00098                         as_.setPreempted();
00099                         return;
00100                 }
00101 
00102                 arm.GetFingers(fingers);
00103                 feedback.fingers = fingers.Fingers();
00104 
00105                 if (arm.Stopped())
00106                 {
00107                         result.fingers = fingers.Fingers();
00108                         as_.setAborted(result);
00109                         return;
00110                 }
00111 
00112                 as_.publishFeedback(feedback);
00113 
00114                 if (target.Compare(fingers, tolerance))
00115                 {
00116                         ROS_INFO("Finger Control Complete.");
00117 
00118                         result.fingers = fingers.Fingers();
00119                         as_.setSucceeded(result);
00120                         return;
00121                 }
00122 
00123                 r.sleep();
00124         }
00125 }
00126 
00127 }


jaco_driver
Author(s): Jeff Schmidt (Clearpath), Alex Bencz (Clearpath), Matt DeDonato (WPI)
autogenerated on Mon Jan 6 2014 11:23:43