netft_utils_lean.h
Go to the documentation of this file.
00001 #ifndef NET_FT_UTILS_LEAN_H
00002 #define NET_FT_UTILS_LEAN_H
00003 
00004 #include "ros/ros.h"
00005 #include "std_msgs/String.h"
00006 #include "tf/transform_listener.h"
00007 #include "geometry_msgs/WrenchStamped.h"
00008 #include "netft_utils/Cancel.h"
00009 #include "lpfilter.h"
00010 #include <math.h>
00011 #include "netft_rdt_driver.h"
00012 #include <memory>
00013 #include <future>
00014 
00019 class NetftUtilsLean
00020 {
00021 public:
00022   NetftUtilsLean(ros::NodeHandle* nh);
00023   ~NetftUtilsLean();
00024 
00025   bool initialize(double rate, std::string world, std::string ft, double force = 60.0, double torque = 6.0);
00026   bool setUserInput(std::string world, std::string ft, double force, double torque);
00027   bool run();
00028   void stop();
00029   
00030   // Access methods
00031   bool biasSensor(bool toBias);
00032   bool setMax(double fMaxU, double tMaxU, double fMaxB, double tMaxB);
00033   bool setThreshold(double fThresh, double tThresh);
00034   bool setFilter(bool toFilter, double deltaT, double cutoffFreq);
00035   bool isReady();
00036   bool waitForData(double timeout);
00037   void getWorldData(geometry_msgs::WrenchStamped& data);
00038   void getToolData(geometry_msgs::WrenchStamped& data);
00039   void getRawData(geometry_msgs::WrenchStamped& data);
00040   bool isRunning();
00041   void setFTAddress(std::string ftAddress);
00042   void setFTTopic(std::string ftTopic);
00043 
00044 private:
00045   //Node handle
00046   ros::NodeHandle* n;                               // ROS node handle
00047   
00048   // Initialization
00049   std::string ftAddress;
00050   std::string ftTopic;
00051   bool isInit;
00052   bool hasData;
00053   
00054   //netft class
00055   std::unique_ptr<netft_rdt_driver::NetFTRDTDriver> netft;
00056   
00057   // cycle rate
00058   double cycleRate;
00059   
00060   //LPFilter
00061   LPFilter* lp;                                    // Filter
00062   bool isFilterOn;
00063   double deltaTFilter;
00064   double cutoffFrequency;
00065   bool newFilter;
00066   bool lpExists;
00067 
00068   // Transform listener
00069   tf::TransformListener* listener;
00070   tf::StampedTransform ft_to_world;                // Transform from ft frame to world frame
00071   std::string world_frame;
00072   std::string ft_frame;
00073  
00074   // Wrenches used to hold force/torque and bias data
00075   geometry_msgs::WrenchStamped bias;               // Wrench containing the current bias data in tool frame
00076   geometry_msgs::WrenchStamped raw_data_tool;      // Wrench containing the current raw data from the netft sensor in the tool frame
00077   geometry_msgs::WrenchStamped tf_data_world;      // Wrench containing the transformed (world frame) data with bias and threshold applied
00078   geometry_msgs::WrenchStamped tf_data_tool;       // Wrench containing the transformed (tool frame) data with bias and threshold applied
00079   geometry_msgs::WrenchStamped zero_wrench;        // Wrench of all zeros for convenience
00080   geometry_msgs::WrenchStamped threshold;          // Wrench containing thresholds
00081   geometry_msgs::WrenchStamped raw_topic_data;     // Wrench containing raw topic data
00082   
00083   bool isBiased;                                   // True if sensor is biased
00084   bool isNewBias;                                  // True if sensor was biased this pass
00085   bool waitingForTransform;                        // False after initial transform is supplied
00086   bool isActive;                                   // True if run function has been called
00087   
00088   // Variables used to monitor FT violation and send a cancel move message
00089   netft_utils::Cancel cancel_msg;
00090   static const int MAX_CANCEL = 5;                 // Number of times to send cancel message when max force is exceeded
00091   static const int MAX_WAIT = 100;                 // Number of cycles to wait after cancel message before sending again
00092   int cancel_count;                                // Counter for times to send cancel message when max force is exceeded
00093   int cancel_wait;                                 // Counter of cycles to wait after cancel message before sending again
00094   double forceMaxB;                                // Default max force limit to send cancel when FT is biased
00095   double torqueMaxB;                               // Default max torque limit to send cancel when FT is biased
00096   double forceMaxU;                                // Default max force limit to send cancel when FT is unbiased
00097   double torqueMaxU;                               // Default max torque limit to send cancel when FT is unbiased
00098   
00099   // ROS subscribers
00100   ros::Subscriber ft_sub;
00101   
00102   // ROS publishers
00103   ros::Publisher netft_cancel_pub;
00104   ros::Publisher data_pub;
00105   
00106   // Callback methods
00107   void netftCallback(const geometry_msgs::WrenchStamped& data);
00108   void dataCallback(const geometry_msgs::WrenchStamped::ConstPtr& msg);
00109   
00110   // Threads 
00111   std::future<bool> monitorThread;
00112   std::future<bool> updateThread;
00113   bool toUpdate;
00114   bool toMonitor;
00115   
00116   bool update();
00117   
00118   // Convenience methods
00119   void copyWrench(geometry_msgs::WrenchStamped &in, geometry_msgs::WrenchStamped &out, geometry_msgs::WrenchStamped &bias);
00120   void applyThreshold(double &value, double thresh);
00121   void transformFrame(geometry_msgs::WrenchStamped in_data, geometry_msgs::WrenchStamped &out_data, char target_frame);
00122   void checkMaxForce();
00123   bool monitorData();
00124   
00125   static const bool DEBUG_DATA = true;
00126 };
00127 
00128 #endif


netft_utils
Author(s): Alex von Sternberg , Derek King, Andy Zelenak
autogenerated on Sat Jul 15 2017 02:45:58