ezn64_usb_control.h
Go to the documentation of this file.
00001 /*********************************************************************************************/
00031 /* Author: Frantisek Durovsky */
00032 
00033 #ifndef EZN64_USB_CONTROL_H
00034 #define EZN64_USB_CONTROL_H
00035 
00036 #include <ros/ros.h>
00037 #include <libusb-1.0/libusb.h>
00038 #include <tf/transform_broadcaster.h>
00039 #include <sensor_msgs/JointState.h>
00040 
00042 #include <schunk_ezn64/reference.h>
00043 #include <schunk_ezn64/set_position.h>
00044 #include <schunk_ezn64/get_error.h>
00045 #include <schunk_ezn64/get_position.h>
00046 #include <schunk_ezn64/acknowledge_error.h>
00047 #include <schunk_ezn64/stop.h>
00048 
00050 namespace schunk_ezn64
00051 {
00052 
00054 class EZN64_usb
00055 {
00056 public:
00057   
00059   EZN64_usb(ros::NodeHandle *nh);
00060   
00061   ~EZN64_usb();
00062   
00064   bool referenceCallback(schunk_ezn64::reference::Request &req,
00065                          schunk_ezn64::reference::Response &res);
00066      
00068   bool getErrorCallback(schunk_ezn64::get_error::Request &req,
00069                         schunk_ezn64::get_error::Response &res);
00070   
00072   bool acknowledgeErrorCallback(schunk_ezn64::acknowledge_error::Request &req,
00073                                 schunk_ezn64::acknowledge_error::Response &res);
00074   
00076   bool setPositionCallback(schunk_ezn64::set_position::Request &req,
00077                            schunk_ezn64::set_position::Response &res);
00078   
00080   bool getPositionCallback(schunk_ezn64::get_position::Request &req,
00081                            schunk_ezn64::get_position::Response &res);
00082   
00084   bool stopCallback(schunk_ezn64::stop::Request &req,
00085                     schunk_ezn64::stop::Response &res);
00086   
00088   void timerCallback(const ros::TimerEvent &event);  
00089   
00091   ros::Publisher joint_pub;
00092   
00094   static const float TF_UPDATE_PERIOD = 0.1;   
00095   
00096 private:
00097     
00099   void reference(libusb_device_handle *handle);
00100    
00102   uint8_t getError(libusb_device_handle *handle);
00103     
00105   void acknowledgeError(libusb_device_handle *handle);
00106   
00108   float getPosition(libusb_device_handle *handle);
00109   
00111   void setPosition(libusb_device_handle *handle, float goal_position);
00112     
00114   void stop(libusb_device_handle *handle);
00115    
00117   void getPeriodicPositionUpdate(libusb_device_handle *handle, float period);
00118   
00121   libusb_device* find_ezn64_dev(int VendorID, int ProductID);
00122   
00124   void print_libusb_dev(libusb_device *dev);
00125 
00127   libusb_device_handle* open_ezn64_dev(libusb_device *dev);
00128   
00130   int close_ezn64_dev(libusb_device_handle *handle, libusb_context *usb_context);
00131 
00133   void usb_write(libusb_device_handle *handle, std::vector<uint8_t> output);
00134   
00136   std::vector<uint8_t> usb_read(libusb_device_handle *handle);
00137   
00139   float IEEE_754_to_float(uint8_t *raw);
00140   
00142   void float_to_IEEE_754(float position, unsigned int *output_array);
00143   
00144   //Launch params
00145   int gripper_id_;
00146   int vendor_id_;
00147   int product_id_;
00148   double update_frequency;
00149 
00150   //Gripper state variales
00151   float act_position_;
00152   uint8_t ezn64_error_;
00153   sensor_msgs::JointState ezn64_joint_state_; 
00154     
00155   //Libusb Variables
00156   libusb_device *ezn64_dev_;
00157   libusb_context *usb_context_;
00158   libusb_device_handle *ezn64_handle_;
00159   
00160   //Consts 
00161   static const double MIN_GRIPPER_POS_LIMIT = 0;
00162   static const double MAX_GRIPPER_POS_LIMIT = 12;
00163   static const double WAIT_FOR_RESPONSE_INTERVAL = 0.5;
00164   static const int    INPUT_BUFFER_SIZE = 512;
00165   static const int    LIBUSB_ENDPOINT = 129;
00166   static const int    LIBUSB_TIMEOUT = 1000;
00167   static const int    LIBUSB_VERBOSITY_LEVEL = 3;
00168   static const int    URDF_SCALE_FACTOR = 1000;
00169   
00170 };  //EZN64_usb
00171 }   //schunk_ezn64
00172 
00173 #endif //EZN64_USB_CONTROL_H


schunk_ezn64
Author(s): Frantisek Durovsky
autogenerated on Fri Feb 12 2016 00:21:41