jaco_arm_trajectory_node.h
Go to the documentation of this file.
00001 
00012 #ifndef JACO_ARM_TRAJECTORY_NODE_H_
00013 #define JACO_ARM_TRAJECTORY_NODE_H_
00014 
00015 #include <ros/ros.h>
00016 
00017 #include <actionlib/client/simple_action_client.h>
00018 #include <actionlib/server/simple_action_server.h>
00019 #include <boost/foreach.hpp>
00020 #include <boost/thread/recursive_mutex.hpp>
00021 #include <control_msgs/FollowJointTrajectoryAction.h>
00022 #include <control_msgs/GripperCommandAction.h>
00023 #include <ecl/geometry.hpp>
00024 #include <wpi_jaco_msgs/AngularCommand.h>
00025 #include <wpi_jaco_msgs/CartesianCommand.h>
00026 #include <wpi_jaco_msgs/EStop.h>
00027 #include <wpi_jaco_msgs/GetAngularPosition.h>
00028 #include <wpi_jaco_msgs/GetCartesianPosition.h>
00029 #include <wpi_jaco_msgs/HomeArmAction.h>
00030 #include <wpi_jaco_msgs/JacoFK.h>
00031 #include <wpi_jaco_msgs/QuaternionToEuler.h>
00032 #include <sensor_msgs/JointState.h>
00033 #include <std_msgs/Bool.h>
00034 #include <std_srvs/Empty.h>
00035 
00036 #include <jaco_sdk/Kinova.API.UsbCommandLayerUbuntu.h>
00037 
00038 #define NUM_JACO_JOINTS 6
00039 
00040 #define LARGE_ACTUATOR_VELOCITY 0.8378 //maximum velocity of large actuator (joints 1-3) (rad/s)
00041 #define SMALL_ACTUATOR_VELOCITY 1.0472 //maximum velocity of small actuator (joints 4-6) (rad/s)
00042 #define TIME_SCALING_FACTOR 1.5 //keep the trajectory at a followable speed
00043 
00044 #define DEG_TO_RAD (M_PI/180)
00045 #define RAD_TO_DEG (180/M_PI)
00046 
00047 //gains for trajectory follower
00048 #define KP 300.0
00049 #define KV 20.0
00050 #define ERROR_THRESHOLD .03 //threshold in radians for combined joint error to consider motion a success
00051 
00052 //gains for finger controller
00053 #define KP_F 7.5
00054 #define KV_F 0.05
00055 #define KI_F 0.1
00056 
00057 //control types
00058 #define ANGULAR_CONTROL 1
00059 #define CARTESIAN_CONTROL 2
00060 
00061 #define NO_ERROR 1 //no error from Kinova API
00062 
00063 namespace jaco
00064 {
00065 
00073 class JacoArmTrajectoryController
00074 {
00075 public:
00076   typedef actionlib::SimpleActionServer<control_msgs::FollowJointTrajectoryAction> TrajectoryServer;
00077   typedef actionlib::SimpleActionServer<control_msgs::GripperCommandAction>        GripperServer;
00078   typedef actionlib::SimpleActionServer<wpi_jaco_msgs::HomeArmAction>              HomeArmServer;
00079 
00080   typedef actionlib::SimpleActionClient<control_msgs::GripperCommandAction>        GripperClient;
00081 
00087   JacoArmTrajectoryController(ros::NodeHandle nh, ros::NodeHandle pnh);
00088 
00092   virtual ~JacoArmTrajectoryController();
00093 
00097   void update_joint_states();
00098 
00103   void home_arm(const wpi_jaco_msgs::HomeArmGoalConstPtr &goal);
00104 
00109   void execute_trajectory(const control_msgs::FollowJointTrajectoryGoalConstPtr &goal);
00110 
00122   void execute_smooth_trajectory(const control_msgs::FollowJointTrajectoryGoalConstPtr &goal);
00123 
00132   void execute_joint_trajectory(const control_msgs::FollowJointTrajectoryGoalConstPtr &goal);
00133 
00138   void execute_gripper(const control_msgs::GripperCommandGoalConstPtr &goal);
00139 
00144   void execute_gripper_radian(const control_msgs::GripperCommandGoalConstPtr &goal);
00145 
00146 private:
00147   bool loadParameters(const ros::NodeHandle n);
00152   void angularCmdCallback(const wpi_jaco_msgs::AngularCommand& msg);
00153 
00158   void cartesianCmdCallback(const wpi_jaco_msgs::CartesianCommand& msg);
00159 
00166   void fingerPositionControl(float f1, float f2, float f3);
00167 
00175   void executeAngularTrajectoryPoint(TrajectoryPoint point, bool erase);
00176 
00185   void executeCartesianTrajectoryPoint(TrajectoryPoint point, bool erase);
00186 
00196   bool getAngularPosition(wpi_jaco_msgs::GetAngularPosition::Request &req, wpi_jaco_msgs::GetAngularPosition::Response &res);
00197 
00207   bool getCartesianPosition(wpi_jaco_msgs::GetCartesianPosition::Request &req,
00208                             wpi_jaco_msgs::GetCartesianPosition::Response &res);
00209 
00217   bool eStopCallback(wpi_jaco_msgs::EStop::Request &req, wpi_jaco_msgs::EStop::Response &res);
00218 
00225   bool eraseTrajectoriesCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res);
00226 
00227   // Messages
00228   ros::Publisher joint_state_pub_; 
00229   ros::Publisher cartesianCmdPublisher; 
00230   ros::Publisher angularCmdPublisher; 
00231   ros::Publisher armHomedPublisher; 
00232   ros::Subscriber cartesianCmdSubscriber; 
00233   ros::Subscriber angularCmdSubscriber; 
00234 
00235   // Services
00236   ros::ServiceClient jaco_fk_client; 
00237   ros::ServiceClient qe_client; 
00238   ros::ServiceServer angularPositionServer; 
00239   ros::ServiceServer cartesianPositionServer; 
00240   ros::ServiceServer eStopServer; 
00241   ros::ServiceServer eraseTrajectoriesServer;
00242 
00243   ros::Timer joint_state_timer_; 
00244 
00245   // Actionlib
00246   TrajectoryServer*  trajectory_server_; 
00247   TrajectoryServer*  smooth_trajectory_server_; 
00248   TrajectoryServer*  smooth_joint_trajectory_server_; 
00249   GripperServer*     gripper_server_; 
00250   GripperServer*     gripper_server_radian_; 
00251   HomeArmServer*     home_arm_server_;
00252 
00253   GripperClient*     gripper_client_; 
00254 
00255   boost::recursive_mutex api_mutex;
00256 
00257   bool eStopEnabled;
00258 
00259   bool arm_initialized;
00260 
00261   // Parameters
00262   std::string   arm_name_;
00263   std::string   topic_prefix_;
00264   double        finger_scale_;
00265   double        finger_error_threshold_; //threshold in the JACO API's finger position units to consider a finger position reached
00266   double        max_curvature_;
00267   double        max_speed_finger_;
00268   double        gripper_open_;
00269   double        gripper_closed_;
00270   int           num_fingers_;
00271   int           num_joints_;
00272   bool          kinova_gripper_;
00273 
00274   std::vector<std::string> joint_names;
00275   std::vector<double>      joint_pos_;
00276   std::vector<double>      joint_vel_;
00277   std::vector<double>      joint_eff_;
00278 
00279   unsigned int controlType; //current state of control
00280 
00281 };
00282 
00283 }
00284 
00285 #endif


wpi_jaco_wrapper
Author(s): David Kent
autogenerated on Thu Jun 6 2019 19:43:31