Libbarrett  1.2.4
include/barrett/products/product_manager.h
00001 
00026 /*
00027  * @file product_manager.h
00028  *
00029  * @date Jan 3, 2011
00030  * @author D Cody
00031  * @author JP Hagstrand
00032  */
00033 
00034 #ifndef BARRETT_PRODUCTS_PRODUCT_MANAGER_H_
00035 #define BARRETT_PRODUCTS_PRODUCT_MANAGER_H_
00036 
00037 
00038 #include <vector>
00039 
00040 #include <libconfig.h++>
00041 
00042 #include <barrett/detail/ca_macro.h>
00043 #include <barrett/thread/abstract/mutex.h>
00044 #include <barrett/bus/abstract/communications_bus.h>
00045 #include <barrett/products/puck.h>
00046 #include <barrett/products/hand.h>
00047 #include <barrett/products/gimbals_hand_controller.h>
00048 #include <barrett/products/safety_module.h>
00049 #include <barrett/products/force_torque_sensor.h>
00050 
00051 
00052 namespace barrett {
00053 
00054 // Forward declarations
00055 namespace systems{
00056 
00057 template<size_t DOF> class Wam;
00058 class ExecutionManager;
00059 class RealTimeExecutionManager;
00060 
00061 }
00062 
00063 
00064 class ProductManager {
00065 public:
00066         static const std::string DEFAULT_CONFIG_FILE;  // = "/etc/barrett/default.conf"
00067 
00068         explicit ProductManager(const char* configFile = NULL, bus::CommunicationsBus* bus = NULL);
00069         virtual ~ProductManager();
00070 
00071         void enumerate();
00072         void cleanUpAfterEstop();
00073         void wakeAllPucks() const { Puck::wake(getPucks()); }
00074 
00075         bool foundSafetyModule() const;
00076         SafetyModule* getSafetyModule();
00077 
00078         const std::vector<Puck*>& getWamPucks() const;
00079         bool foundWam() const { return foundWam3() || foundWam4() || foundWam7(); } 
00080         bool foundWam3() const;
00081         bool foundWam4() const;
00082         bool foundWam7() const;
00083         bool foundWam7Wrist() const;
00084         bool foundWam7Gimbals() const;
00085 
00086         void waitForWam(bool promptOnZeroing = true);
00087         const char* getWamDefaultConfigPath();
00088         systems::Wam<3>* getWam3(bool waitForShiftActivate = true, const char* configPath = NULL);
00089         systems::Wam<4>* getWam4(bool waitForShiftActivate = true, const char* configPath = NULL);
00090         systems::Wam<7>* getWam7(bool waitForShiftActivate = true, const char* configPath = NULL);
00091 
00092         systems::RealTimeExecutionManager* getExecutionManager(
00093                         double period_s = DEFAULT_LOOP_PERIOD, int rt_priority = 50);
00094         void startExecutionManager();
00095 
00096         bool foundForceTorqueSensor() const;
00097         ForceTorqueSensor* getForceTorqueSensor();
00098 
00099         const std::vector<Puck*>& getHandPucks() const;
00100         bool foundHand() const;
00101         Hand* getHand();
00102 
00103         bool foundGimbalsHandController() const;
00104         GimbalsHandController* getGimbalsHandController();
00105 
00106         const std::vector<Puck*>& getPucks() const { return pucks; }
00107         Puck* getPuck(int id) const;
00108         void deletePuck(Puck* p);
00109 
00110         libconfig::Config& getConfig() { return config; }
00111         const bus::CommunicationsBus& getBus() const { return *bus; }
00112         virtual thread::Mutex& getMutex() const { return bus->getMutex(); }
00113 
00114 
00115         static const size_t MAX_WAM_DOF = 7;
00116         static const double DEFAULT_LOOP_PERIOD = 0.002;
00117         static const int SAFETY_MODULE_ID = 10;
00118         static const int FIRST_WAM_ID = 1;
00119         static const int FIRST_HAND_ID = 11;
00120         static const int FORCE_TORQUE_SENSOR_ID = 8;
00121 
00122 protected:
00123         void destroyEstopProducts();
00124         bool verifyWamPucks(const size_t dof) const;
00125 
00126         libconfig::Config config;
00127         bus::CommunicationsBus* bus;
00128         bool deleteBus;
00129         std::vector<Puck*> pucks;
00130         std::vector<Puck*> wamPucks;
00131         std::vector<Puck*> handPucks;
00132 
00133         SafetyModule* sm;
00134         systems::RealTimeExecutionManager* rtem;
00135         systems::Wam<3>* wam3;
00136         systems::Wam<4>* wam4;
00137         systems::Wam<7>* wam7;
00138         ForceTorqueSensor* fts;
00139         Hand* hand;
00140         GimbalsHandController* ghc;
00141 
00142 private:
00143         bool wam7FoundHelper(int poles) const;
00144 
00145         DISALLOW_COPY_AND_ASSIGN(ProductManager);
00146 };
00147 
00148 
00149 }
00150 
00151 
00152 #endif /* BARRETT_PRODUCTS_PRODUCT_MANAGER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines