jaco_angles_action.cpp
Go to the documentation of this file.
00001 
00046 #include "jaco_driver/jaco_angles_action.h"
00047 #include <jaco_driver/KinovaTypes.h>
00048 #include "jaco_driver/jaco_types.h"
00049 
00050 namespace jaco
00051 {
00052 
00053 JacoAnglesActionServer::JacoAnglesActionServer(JacoComm &arm_comm, ros::NodeHandle &n) : 
00054     arm(arm_comm), 
00055     as_(n, "arm_joint_angles", boost::bind(&JacoAnglesActionServer::ActionCallback, this, _1), false)
00056 {
00057     as_.start();
00058 }
00059 
00060 JacoAnglesActionServer::~JacoAnglesActionServer()
00061 {
00062 
00063 }
00064 
00065 void JacoAnglesActionServer::ActionCallback(const jaco_driver::ArmJointAnglesGoalConstPtr &goal)
00066 {
00067         jaco_driver::ArmJointAnglesFeedback feedback;
00068         jaco_driver::ArmJointAnglesResult result;
00069 
00070         ROS_INFO("Got an angular goal for the arm");
00071 
00072         JacoAngles cur_position;                //holds the current position of the arm
00073 
00074         if (arm.Stopped())
00075         {
00076                 arm.GetAngles(cur_position);
00077                 result.angles = cur_position.Angles();
00078 
00079                 as_.setAborted(result);
00080                 return;
00081         }
00082 
00083         JacoAngles target(goal->angles);
00084         arm.SetAngles(target);
00085 
00086         ros::Rate r(10);
00087  
00088         const float tolerance = 2.0;    //dead zone for position (degrees)
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.GetAngles(cur_position);
00103                 feedback.angles = cur_position.Angles();
00104 
00105                 if (arm.Stopped())
00106                 {
00107                         result.angles = cur_position.Angles();
00108                         as_.setAborted(result);
00109                         return;
00110                 }
00111 
00112                 as_.publishFeedback(feedback);
00113 
00114                 if (target.Compare(cur_position, tolerance))
00115                 {
00116                         ROS_INFO("Angular Control Complete.");
00117 
00118                         result.angles = cur_position.Angles();
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