00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #ifndef _ROBOT_CONTROL_KINEMATICS_IKORCONTROLLER_
00026 #define _ROBOT_CONTROL_KINEMATICS_IKORCONTROLLER_
00027 
00028 #include <robot/control/kinematics/kinematics>
00029 
00030 #include <robot/Controller>
00031 #include <robot/Controllable>
00032 #include <robot/Robot>
00033 #include <robot/control/kinematics/InverseKinematicsSolver>
00034 
00035 
00036 namespace robot {
00037 namespace control {
00038 namespace kinematics {
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 class IKORController : public robot::Controller, public robot::Controllable
00064 {
00065 public:
00066   enum IKMethod { LeastNorm, FSPLagrangian };
00067 
00068   IKORController(IKMethod method, ref<robot::Robot> robot, Int manipulatorIndex,
00069                  bool platformActive = false, bool orientationControl = true,
00070                  base::Orient::Representation orientationRepresentation = base::Orient::EulerRPY);
00071 
00072   virtual String className() const { return String("IKORController"); }
00073 
00074 
00075 
00076   virtual void setControlInterface(ref<ControlInterface> controlInterface);
00077 
00078   virtual bool isConnected() const { return (manipulatorInterface!=0); }
00079 
00080   virtual bool iterate(const base::Time& time);
00081 
00082   virtual array<std::pair<String,String> > controlInterfaces() const; 
00083 
00084   virtual ref<ControlInterface> getControlInterface(String interfaceName="") throw(std::invalid_argument);
00085 
00086 
00087   void setProximityDangerDistance(Real d) { this->d = d; }
00088   
00089 protected:
00090   IKMethod method;                 
00091   ref<const robot::Robot> robot;   
00092   bool platformActive;             
00093   bool orientationControl;         
00094   base::Orient::Representation orientRep;
00095 
00096   robot::KinematicChain manipChain;    
00097 
00098   Real d; 
00099   
00100 
00101   ref<InverseKinematicsSolver>     ikSolver;
00102   InverseKinematicsSolver::OptimizationMethod      optMethod;
00103   InverseKinematicsSolver::OptimizationCriterion   optCriterion;
00104   InverseKinematicsSolver::OptimizationConstraints optConstraints;
00105   Vector tx; 
00106   mutable Vector x;     
00107   mutable Vector q;     
00108 
00109   ref<ControlInterface> manipulatorInterface; 
00110   ref<ControlInterface> proxInterface;        
00111 
00112 
00113 
00114 
00115   void calcEEPositionOrientation();
00116 
00117   
00118 
00119 
00120   class EEPositionControlInterface : public robot::ControlInterface
00121   {
00122   public:
00123     EEPositionControlInterface(ref<IKORController> c, const String& interfaceName, const String& interfaceType)
00124       : c(c) { setName(interfaceName); setType(interfaceType); }
00125     EEPositionControlInterface(const EEPositionControlInterface& copy)
00126       : c(copy.c) {}
00127 
00128     virtual String className() const { return String("EEPositionControlInterface"); }
00129     virtual Object& clone() const { return *NewObj EEPositionControlInterface(*this); } 
00130 
00131     Int inputSize() const;
00132     String inputName(Int i) const; 
00133     Real getInput(Int i) const;
00134     const Vector& getInputs() const;
00135     
00136     Int outputSize() const;
00137     String outputName(Int i) const; 
00138     void setOutput(Int i, Real value);
00139     void setOutputs(const Vector& values);
00140    
00141   protected:
00142     ref<IKORController> c;
00143 
00144   };
00145   
00146 
00147 
00148   class LinkPositionsControlInterface : public robot::ControlInterface
00149   {
00150   public:
00151     LinkPositionsControlInterface(ref<IKORController> c, const String& interfaceName, const String& interfaceType)
00152       : c(c) { setName(interfaceName); setType(interfaceType); }
00153     LinkPositionsControlInterface(const LinkPositionsControlInterface& copy)
00154       : c(copy.c) {}
00155 
00156     virtual String className() const { return String("LinkPositionsControlInterface"); }
00157     virtual Object& clone() const { return *NewObj LinkPositionsControlInterface(*this); } 
00158 
00159     Int inputSize() const;
00160     String inputName(Int i) const; 
00161     Real getInput(Int i) const;
00162     const Vector& getInputs() const;
00163     
00164     Int outputSize() const;
00165     String outputName(Int i) const; 
00166     void setOutput(Int i, Real value);
00167     void setOutputs(const Vector& values);
00168    
00169   protected:
00170     ref<IKORController> c;
00171 
00172   };
00173 
00174   mutable Vector linkPositions; 
00175 
00176 
00177   static array<String> inputName;  
00178   static array<String> outputName; 
00179 
00180   
00181 
00182   friend class EEPositionControlInterface;
00183 };
00184 
00185 
00186 }
00187 }
00188 } 
00189 
00190 #endif