Libbarrett  1.2.4
include/barrett/systems/wam.h
Go to the documentation of this file.
00001 
00034 #ifndef BARRETT_SYSTEMS_WAM_H_
00035 #define BARRETT_SYSTEMS_WAM_H_
00036 
00037 
00038 #include <vector>
00039 
00040 #include <boost/thread.hpp>
00041 #include <Eigen/Core>
00042 #include <libconfig.h++>
00043 
00044 #include <barrett/detail/ca_macro.h>
00045 #include <barrett/units.h>
00046 #include <barrett/products/low_level_wam.h>
00047 #include <barrett/products/puck.h>
00048 #include <barrett/products/safety_module.h>
00049 #include <barrett/math/kinematics.h>
00050 
00051 #include <barrett/systems/low_level_wam_wrapper.h>
00052 #include <barrett/systems/first_order_filter.h>
00053 #include <barrett/systems/converter.h>
00054 #include <barrett/systems/summer.h>
00055 #include <barrett/systems/gain.h>
00056 #include <barrett/systems/tuple_grouper.h>
00057 #include <barrett/systems/tuple_splitter.h>
00058 
00059 #include <barrett/systems/kinematics_base.h>
00060 #include <barrett/systems/gravity_compensator.h>
00061 #include <barrett/systems/tool_position.h>
00062 #include <barrett/systems/tool_velocity.h>
00063 #include <barrett/systems/tool_orientation.h>
00064 
00065 #include <barrett/systems/pid_controller.h>
00066 #include <barrett/systems/tool_orientation_controller.h>
00067 #include <barrett/systems/tool_force_to_joint_torques.h>
00068 #include <barrett/systems/tool_torque_to_joint_torques.h>
00069 
00070 
00071 namespace barrett {
00072 namespace systems {
00073 
00074 
00075 template<size_t DOF>
00076 class Wam {
00077 public:
00078         BARRETT_UNITS_TEMPLATE_TYPEDEFS(DOF);
00079 
00080 
00081         // these need to be before the IO references
00082         LowLevelWamWrapper<DOF> llww;
00083         KinematicsBase<DOF> kinematicsBase;
00084         GravityCompensator<DOF> gravity;
00085         FirstOrderFilter<jv_type> jvFilter;
00086         ToolPosition<DOF> toolPosition;
00087         ToolVelocity<DOF> toolVelocity;
00088         ToolOrientation<DOF> toolOrientation;
00089         TupleGrouper<cp_type, Eigen::Quaterniond> toolPose;
00090 
00091         Converter<jt_type> supervisoryController;
00092         Gain<jt_type, double> jtPassthrough;
00093         PIDController<jp_type, jt_type> jpController;
00094         PIDController<jv_type, jt_type> jvController1;
00095         FirstOrderFilter<jt_type> jvController2;
00096         PIDController<cp_type, cf_type> tpController;
00097         ToolForceToJointTorques<DOF> tf2jt;
00098         ToolOrientationController<DOF> toController;
00099         ToolTorqueToJointTorques<DOF> tt2jt;
00100 
00101         // tool orientation + tool position control
00102         TupleSplitter<cp_type, Eigen::Quaterniond> tpoSplitter;
00103         PIDController<cp_type, cf_type> tpoTpController;
00104         ToolForceToJointTorques<DOF> tpoTf2jt;
00105         ToolOrientationController<DOF> tpoToController;
00106         ToolTorqueToJointTorques<DOF> tpoTt2jt;
00107         Summer<jt_type, 2> tpoSum;
00108 
00109         Summer<jt_type, 3> jtSum;
00110         enum {JT_INPUT = 0, GRAVITY_INPUT, SC_INPUT};
00111 
00112 
00117 public:         System::Input<jt_type>& input;
00118 public:         System::Output<jp_type>& jpOutput;
00119 public:         System::Output<jv_type>& jvOutput;
00120 
00121 
00122 public:
00127         Wam(ExecutionManager* em, const std::vector<Puck*>& genericPucks,
00128                         SafetyModule* safetyModule, const libconfig::Setting& setting,
00129                         std::vector<int> torqueGroupIds = std::vector<int>(),
00130                         const std::string& sysName = "Wam");
00133         ~Wam();
00136         template<typename T>
00137         void trackReferenceSignal(System::Output<T>& referenceSignal);  //NOLINT: non-const reference for syntax
00140         const jp_type& getHomePosition() const;
00143         jt_type getJointTorques() const;
00146         jp_type getJointPositions() const;
00149         jv_type getJointVelocities() const;
00152         cp_type getToolPosition() const;
00155         cv_type getToolVelocity() const;
00158         Eigen::Quaterniond getToolOrientation() const;
00161         pose_type getToolPose() const;
00164         math::Matrix<6,DOF> getToolJacobian() const;
00165 
00168         void gravityCompensate(bool compensate = true);
00171         bool updateGravity(double val = -9.8);
00174         bool isGravityCompensated();
00182         void moveHome(bool blocking = true);
00183         void moveHome(bool blocking, double velocity);
00184         void moveHome(bool blocking, double velocity, double acceleration);
00193         void moveTo(const jp_type& destination, bool blocking = true, double velocity = 0.5, double acceleration = 0.5);
00194         void moveTo(const cp_type& destination, bool blocking = true, double velocity = 0.1, double acceleration = 0.2);
00195         void moveTo(const Eigen::Quaterniond& destination, bool blocking = true, double velocity = 0.5, double acceleration = 0.5);
00196         void moveTo(const pose_type& destination, bool blocking = true, double velocity = 0.1, double acceleration = 0.2);
00197         template<typename T> void moveTo(const T& currentPos, /*const typename T::unitless_type& currentVel,*/ const T& destination, bool blocking, double velocity, double acceleration);
00202         bool moveIsDone() const;
00207         void idle();
00208 
00211         thread::Mutex& getEmMutex() const { return llww.getEmMutex(); }
00214         LowLevelWam<DOF>& getLowLevelWam() { return llww.getLowLevelWam(); }
00215         const LowLevelWam<DOF>& getLowLevelWam() const { return llww.getLowLevelWam(); }
00216 
00217 protected:
00218         template<typename T> T currentPosHelper(const T& currentPos);
00219         template<typename T> void moveToThread(const T& currentPos, const T& destination, double velocity, double acceleration, bool* started, boost::shared_future<boost::thread*> threadPtrFuture);
00220 
00221         bool doneMoving;
00222         boost::thread_group mtThreadGroup;
00223 
00224         // Used to calculate TP and TO if the values aren't already being calculated in the control loop.
00225         mutable math::Kinematics<DOF> kin;
00226 
00227 private:
00228         DISALLOW_COPY_AND_ASSIGN(Wam);
00229 
00230 public:
00231         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00232 };
00233 
00234 
00235 }
00236 }
00237 
00238 
00239 // include template definitions
00240 #include <barrett/systems/detail/wam-inl.h>
00241 
00242 
00243 #endif /* BARRETT_SYSTEMS_WAM_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines