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
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
00046 ros::NodeHandle* n;
00047
00048
00049 std::string ftAddress;
00050 std::string ftTopic;
00051 bool isInit;
00052 bool hasData;
00053
00054
00055 std::unique_ptr<netft_rdt_driver::NetFTRDTDriver> netft;
00056
00057
00058 double cycleRate;
00059
00060
00061 LPFilter* lp;
00062 bool isFilterOn;
00063 double deltaTFilter;
00064 double cutoffFrequency;
00065 bool newFilter;
00066 bool lpExists;
00067
00068
00069 tf::TransformListener* listener;
00070 tf::StampedTransform ft_to_world;
00071 std::string world_frame;
00072 std::string ft_frame;
00073
00074
00075 geometry_msgs::WrenchStamped bias;
00076 geometry_msgs::WrenchStamped raw_data_tool;
00077 geometry_msgs::WrenchStamped tf_data_world;
00078 geometry_msgs::WrenchStamped tf_data_tool;
00079 geometry_msgs::WrenchStamped zero_wrench;
00080 geometry_msgs::WrenchStamped threshold;
00081 geometry_msgs::WrenchStamped raw_topic_data;
00082
00083 bool isBiased;
00084 bool isNewBias;
00085 bool waitingForTransform;
00086 bool isActive;
00087
00088
00089 netft_utils::Cancel cancel_msg;
00090 static const int MAX_CANCEL = 5;
00091 static const int MAX_WAIT = 100;
00092 int cancel_count;
00093 int cancel_wait;
00094 double forceMaxB;
00095 double torqueMaxB;
00096 double forceMaxU;
00097 double torqueMaxU;
00098
00099
00100 ros::Subscriber ft_sub;
00101
00102
00103 ros::Publisher netft_cancel_pub;
00104 ros::Publisher data_pub;
00105
00106
00107 void netftCallback(const geometry_msgs::WrenchStamped& data);
00108 void dataCallback(const geometry_msgs::WrenchStamped::ConstPtr& msg);
00109
00110
00111 std::future<bool> monitorThread;
00112 std::future<bool> updateThread;
00113 bool toUpdate;
00114 bool toMonitor;
00115
00116 bool update();
00117
00118
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