Libbarrett  1.2.4
sandbox/tensioner.h
00001 /*
00002  * tensioner.h
00003  *
00004  *  Created on: Jun 14, 2011
00005  *      Author: CJ Valle
00006  */
00007 
00008 #ifndef TENSIONER_H_
00009 #define TENSIONER_H_
00010 
00011 #include <stdexcept>
00012 #include <cmath>
00013 
00014 #include <syslog.h>
00015 #include <unistd.h> /* for close() */
00016 
00017 #include <barrett/units.h>
00018 #include <barrett/systems/abstract/single_io.h>
00019 
00020 namespace barrett {
00021 namespace systems {
00022 
00023 template <size_t DOF>
00024 class Tensioner : public barrett::systems::SingleIO<typename barrett::units::JointTorques<DOF>::type, typename barrett::units::JointTorques<DOF>::type> {
00025         BARRETT_UNITS_TEMPLATE_TYPEDEFS(DOF);
00026 
00027 public:
00028         explicit Tensioner(ExecutionManager* em, const std::string& sysName = "Tensioner") :
00029                 barrett::systems::SingleIO<jt_type,jt_type>(sysName)
00030         {
00031                 watching = false;
00032                 if (em != NULL) em->startManaging(*this);
00033         }
00034 
00035         void activate(int m, double l)
00036         {
00037                 motor = m;
00038                 limit = l;
00039                 watching = true;
00040 
00041         }
00042 
00043         void deactivate()
00044         {
00045                 watching = false;
00046         }
00047 
00048 protected:
00049 
00050         virtual void operate()
00051         {
00052                 if (watching) 
00053                 {
00054                         torques = this->input.getValue();
00055                         if (fabs(torques[motor]) > limit)
00056                         {
00057                                 watching = false;
00058                         }
00059                 }
00060         }
00061 
00062 public:
00063         bool watching;
00064         int motor;
00065         double limit;
00066         jt_type torques;
00067 };
00068 }}
00069 #endif /* TENSIONER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines