Libbarrett  1.2.4
include/barrett/systems/low_level_wam_wrapper.h
00001 /*
00002         Copyright 2009, 2010 Barrett Technology <support@barrett.com>
00003 
00004         This file is part of libbarrett.
00005 
00006         This version of libbarrett is free software: you can redistribute it
00007         and/or modify it under the terms of the GNU General Public License as
00008         published by the Free Software Foundation, either version 3 of the
00009         License, or (at your option) any later version.
00010 
00011         This version of libbarrett is distributed in the hope that it will be
00012         useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License along
00017         with this version of libbarrett.  If not, see
00018         <http://www.gnu.org/licenses/>.
00019 
00020         Further, non-binding information about licensing is available at:
00021         <http://wiki.barrett.com/libbarrett/wiki/LicenseNotes>
00022 */
00023 
00024 /*
00025  * low_level_wam_wrapper.h
00026  *
00027  *  Created on: Feb 2, 2010
00028  *      Author: dc
00029  */
00030 
00031 #ifndef BARRETT_SYSTEMS_LOW_LEVEL_WAM_WRAPPER_H_
00032 #define BARRETT_SYSTEMS_LOW_LEVEL_WAM_WRAPPER_H_
00033 
00034 
00035 #include <vector>
00036 
00037 #include <Eigen/Core>
00038 #include <libconfig.h++>
00039 
00040 #include <barrett/detail/ca_macro.h>
00041 #include <barrett/units.h>
00042 #include <barrett/products/puck.h>
00043 #include <barrett/products/low_level_wam.h>
00044 #include <barrett/products/safety_module.h>
00045 
00046 #include <barrett/systems/abstract/execution_manager.h>
00047 #include <barrett/systems/abstract/system.h>
00048 #include <barrett/systems/abstract/single_io.h>
00049 
00050 
00051 namespace barrett {
00052 namespace systems {
00053 
00054 
00055 template<size_t DOF>
00056 class LowLevelWamWrapper {
00057         BARRETT_UNITS_TEMPLATE_TYPEDEFS(DOF);
00058 
00059 public:         System::Input<jt_type>& input;
00060 public:         System::Output<jp_type>& jpOutput;
00061 public:         System::Output<jv_type>& jvOutput;
00062 
00063 
00064 public:
00065         // genericPucks must be ordered by joint and must break into torque groups as arranged
00066         LowLevelWamWrapper(ExecutionManager* em, const std::vector<Puck*>& genericPucks,
00067                         SafetyModule* safetyModule, const libconfig::Setting& setting,
00068                         std::vector<int> torqueGroupIds = std::vector<int>(),
00069                         const std::string& sysName = "LowLevelWamWrapper");
00070         ~LowLevelWamWrapper() {}
00071 
00072         LowLevelWam<DOF>& getLowLevelWam() { return llw; }
00073         const LowLevelWam<DOF>& getLowLevelWam() const { return llw; }
00074 
00075         thread::Mutex& getEmMutex() const { return sink.getEmMutex(); }
00076 
00077 protected:
00078         class Sink : public System, public SingleInput<jt_type> {
00079         public:
00080                 Sink(LowLevelWamWrapper* parent, ExecutionManager* em,
00081                                 const std::string& sysName = "LowLevelWamWrapper::Sink") :
00082                         System(sysName),
00083                         SingleInput<jt_type>(this),
00084                         parent(parent)
00085                 {
00086                         // Update every execution cycle because this is a sink.
00087                         if (em != NULL) {
00088                                 em->startManaging(*this);
00089                         }
00090                 }
00091                 virtual ~Sink() { mandatoryCleanUp(); }
00092 
00093         protected:
00094                 virtual void operate();
00095 
00096                 LowLevelWamWrapper* parent;
00097 
00098         private:
00099                 DISALLOW_COPY_AND_ASSIGN(Sink);
00100         };
00101 
00102 
00103         class Source : public System {
00104         // IO
00105         public:         Output<jp_type> jpOutput;
00106         protected:      typename Output<jp_type>::Value* jpOutputValue;
00107         public:         Output<jv_type> jvOutput;
00108         protected:      typename Output<jv_type>::Value* jvOutputValue;
00109 
00110 
00111         public:
00112                 Source(LowLevelWamWrapper* parent, ExecutionManager* em,
00113                                 const std::string& sysName = "LowLevelWamWrapper::Sink") :
00114                         System(sysName),
00115                         jpOutput(this, &jpOutputValue), jvOutput(this, &jvOutputValue),
00116                         parent(parent)
00117                 {
00118                         // Update every execution cycle to prevent heartbeat
00119                         // faults. Depending on connections, this System
00120                         // might not be called for a period of time. In this
00121                         // situation, the pucks would stop reporting
00122                         // positions and the safety system would assume they
00123                         // had died.
00124                         if (em != NULL) {
00125                                 em->startManaging(*this);
00126                         }
00127                 }
00128                 virtual ~Source() { mandatoryCleanUp(); }
00129 
00130         protected:
00131                 virtual void operate();
00132 
00133                 LowLevelWamWrapper* parent;
00134 
00135         private:
00136                 DISALLOW_COPY_AND_ASSIGN(Source);
00137         };
00138 
00139 
00140         LowLevelWam<DOF> llw;
00141 
00142         Sink sink;
00143         Source source;
00144 
00145 private:
00146         DISALLOW_COPY_AND_ASSIGN(LowLevelWamWrapper);
00147 
00148 public:
00149         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00150 };
00151 
00152 
00153 }
00154 }
00155 
00156 
00157 // include template definitions
00158 #include <barrett/systems/detail/low_level_wam_wrapper-inl.h>
00159 
00160 
00161 #endif /* BARRETT_SYSTEMS_LOW_LEVEL_WAM_WRAPPER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines