netft_utils.h
Go to the documentation of this file.
00001 #ifndef NET_FT_UTILS_H
00002 #define NET_FT_UTILS_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/SetBias.h"
00009 #include "netft_utils/SetMax.h"
00010 #include "netft_utils/SetThreshold.h"
00011 #include "netft_utils/SetToolData.h"
00012 #include "netft_utils/SetFilter.h"
00013 #include "netft_utils/GetDouble.h"
00014 #include "netft_utils/Cancel.h"
00015 #include "lpfilter.h"
00016 #include <math.h>
00017 
00022 class NetftUtils
00023 {
00024 public:
00025   NetftUtils(ros::NodeHandle nh);
00026   ~NetftUtils();
00027 
00028   void initialize();
00029   void setUserInput(std::string world, std::string ft, double force, double torque);
00030   void update();
00031 
00032 private:
00033   //Node handle
00034   ros::NodeHandle n;                               // ROS node handle
00035   
00036   //LPFilter
00037   LPFilter* lp;                                    // Filter
00038   bool isFilterOn;
00039   double deltaTFilter;
00040   double cutoffFrequency;
00041   bool newFilter;
00042 
00043   // Transform listener
00044   tf::TransformListener* listener;
00045   tf::StampedTransform ft_to_world;                // Transform from ft frame to world frame
00046   std::string world_frame;
00047   std::string ft_frame;
00048  
00049   // Wrenches used to hold force/torque and bias data
00050   geometry_msgs::WrenchStamped bias;               // Wrench containing the current bias data in tool frame
00051   geometry_msgs::WrenchStamped weight_bias;        // Wrench containing the bias at a measurement pose (to measure the weight)
00052   geometry_msgs::WrenchStamped raw_data_world;     // Wrench containing the current raw data from the netft sensor transformed into the world frame
00053   geometry_msgs::WrenchStamped raw_data_tool;      // Wrench containing the current raw data from the netft sensor in the tool frame
00054   geometry_msgs::WrenchStamped tf_data_world;      // Wrench containing the transformed (world frame) data with bias and threshold applied
00055   geometry_msgs::WrenchStamped tf_data_tool;       // Wrench containing the transformed (tool frame) data with bias and threshold applied
00056   geometry_msgs::WrenchStamped zero_wrench;        // Wrench of all zeros for convenience
00057   geometry_msgs::WrenchStamped threshold;          // Wrench containing thresholds
00058   
00059   double payloadWeight;                            // Used in gravity compensation
00060   double payloadLeverArm;                          // Used in gravity compensation. The z-coordinate to payload CoM (in sensor's raw frame)
00061   
00062   bool isBiased;                                   // True if sensor is biased
00063   bool isNewBias;                                  // True if sensor was biased this pass
00064   bool isNewGravityBias;                           // True if gravity compensation was applied this pass
00065   bool isGravityBiased;                            // True if gravity is compensated
00066   
00067   // Variables used to monitor FT violation and send a cancel move message
00068   netft_utils::Cancel cancel_msg;
00069   static const int MAX_CANCEL = 5;                 // Number of times to send cancel message when max force is exceeded
00070   static const int MAX_WAIT = 100;                 // Number of cycles to wait after cancel message before sending again
00071   int cancel_count;                                // Counter for times to send cancel message when max force is exceeded
00072   int cancel_wait;                                 // Counter of cycles to wait after cancel message before sending again
00073   double forceMaxB;                                // Default max force limit to send cancel when FT is biased
00074   double torqueMaxB;                               // Default max torque limit to send cancel when FT is biased
00075   double forceMaxU;                                // Default max force limit to send cancel when FT is unbiased
00076   double torqueMaxU;                               // Default max torque limit to send cancel when FT is unbiased
00077   
00078   // ROS subscribers
00079   ros::Subscriber raw_data_sub;
00080   
00081   // ROS publishers
00082   ros::Publisher netft_raw_world_data_pub;
00083   ros::Publisher netft_world_data_pub;
00084   ros::Publisher netft_tool_data_pub;
00085   ros::Publisher netft_cancel_pub;
00086   
00088   // ROS services
00090   ros::ServiceServer bias_service;
00091   ros::ServiceServer gravity_comp_service;
00092   ros::ServiceServer set_max_service;
00093   ros::ServiceServer theshold_service;
00094   ros::ServiceServer weight_bias_service;
00095   ros::ServiceServer get_weight_service;
00096   ros::ServiceServer filter_service;
00097 
00099   // Callback methods
00101   
00102   // Runs when a new datapoint comes in
00103   void netftCallback(const geometry_msgs::WrenchStamped::ConstPtr& data);
00104   
00105   // Set the readings from the sensor to zero at this instant and continue to apply the bias on future readings.
00106   // This doesn't account for gravity i.e. it will not change if the sensor's orientation changes.
00107   // Run this method when the sensor is stationary to avoid inertial effects.
00108   bool fixedOrientationBias(netft_utils::SetBias::Request &req, netft_utils::SetBias::Response &res);
00109   
00110   // Set the readings from the sensor to zero at this instant.
00111   // Calculate the payload's mass and center of mass so gravity can be compensated for, even as the sensor changes orientation.
00112   // It's assumed that the payload's center of mass is located on the sensor's central access.
00113   // Run this method when the sensor is stationary to avoid inertial effects.
00114   // It assumes the Z-axis of the World tf frame is up.
00115   bool compensateForGravity(netft_utils::SetBias::Request &req, netft_utils::SetBias::Response &res);
00116   
00117   bool setMax(netft_utils::SetMax::Request &req, netft_utils::SetMax::Response &res);
00118   bool setWeightBias(netft_utils::SetBias::Request &req, netft_utils::SetBias::Response &res);
00119   bool getWeight(netft_utils::GetDouble::Request &req, netft_utils::GetDouble::Response &res);
00120   bool setThreshold(netft_utils::SetThreshold::Request &req, netft_utils::SetThreshold::Response &res);
00121   bool setFilter(netft_utils::SetFilter::Request &req, netft_utils::SetFilter::Response &res);
00122 
00123   // Convenience methods
00124   void copyWrench(geometry_msgs::WrenchStamped &in, geometry_msgs::WrenchStamped &out, geometry_msgs::WrenchStamped &bias);
00125   void applyThreshold(double &value, double thresh);
00126   void transformFrame(geometry_msgs::WrenchStamped in_data, geometry_msgs::WrenchStamped &out_data, char target_frame);
00127   void checkMaxForce();
00128 };
00129 
00130 #endif


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