00001 /*************************************************************************** 00002 * Copyright (C) 2005-2011 LpzRobots development team * 00003 * Georg Martius <georg dot martius at web dot de> * 00004 * Frank Guettler <guettler at informatik dot uni-leipzig dot de * 00005 * Frank Hesse <frank at nld dot ds dot mpg dot de> * 00006 * Ralf Der <ralfder at mis dot mpg dot de> * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 * * 00023 ***************************************************************************/ 00024 #ifndef __ANGULARMOTOR_H 00025 #define __ANGULARMOTOR_H 00026 00027 #include <list> 00028 #include "joint.h" 00029 00030 namespace lpzrobots { 00031 00032 /** Abstract angular motor class. This is a wrapper for ODE's AMotor. 00033 */ 00034 class AngularMotor { 00035 public: 00036 /// creates a AMotor attached to the same bodies as the given joint. 00037 AngularMotor(const OdeHandle& odeHandle, Joint* joint); 00038 00039 // destroys the AMotor 00040 virtual ~AngularMotor (); 00041 00042 /// returns the number of Axis of this Motor 00043 virtual int getNumberOfAxes() = 0; 00044 00045 /** sets the desired speed of the motor at the given axis. 00046 @param velocity Desired motor velocity (this will be an angular or linear velocity). 00047 */ 00048 virtual void set(int axisNumber, double velocity) = 0; 00049 /** returns the speed (PositionRate) at the given axis, or zero if the axis is out of range*/ 00050 virtual double get(int axisNumber) = 0; 00051 00052 /** sets the maximal force the motor has 00053 */ 00054 virtual void setPower(double power) = 0; 00055 00056 /// return the maximal force 00057 virtual double getPower(); 00058 00059 00060 /** sets the desired speed of all motor. 00061 @param velocities double array with desired velocities 00062 @param len length of the given array 00063 @return number actually returned velocities 00064 */ 00065 virtual int set(const double* velocities, int len); 00066 /** returns the speed (PositionRate) of all axis 00067 @param velocities double array to fill in the velocities 00068 @param len length of the given array 00069 @return number actually returned velocities 00070 */ 00071 virtual int get(double* velocities, int len); 00072 00073 /// returns the joint to which this motor is attached 00074 virtual Joint* getJoint() = 0; 00075 00076 //sets the parameter for a motor 00077 virtual void setParam(int parameter, double value); 00078 00079 /// return the ODE joint parameter (see ODE manual) 00080 virtual double getParam(int parameter); 00081 00082 00083 protected: 00084 dJointID motor; 00085 }; 00086 00087 00088 /// Angular motor for OneAxisJoints 00089 class AngularMotor1Axis : public AngularMotor { 00090 public: 00091 /** Constuct a motor attached to a OneAxisJoint. It will its axis of course. 00092 @param power The maximum force or torque that the motor will use to achieve the desired velocity. 00093 This must always be greater than or equal to zero. 00094 Setting this to zero (the default value) turns off the motor. 00095 */ 00096 AngularMotor1Axis(const OdeHandle& odeHandle, OneAxisJoint* joint, double power); 00097 virtual ~AngularMotor1Axis() {} 00098 00099 virtual int getNumberOfAxes() { return 1; }; 00100 00101 /** sets the desired speed of the motor at the given axis. 00102 @param axisNumber is ignored because have only one axis 00103 @param velocity Desired motor velocity (this will be an angular or linear velocity). 00104 */ 00105 virtual void set(int axisNumber, double velocity); 00106 /** returns the speed (PositionRate) at the given axis, or zero if the axis is out of range 00107 @param axisNumber is ignored because have only one axis 00108 */ 00109 virtual double get(int axisNumber) ; 00110 00111 virtual void setPower(double power); 00112 00113 virtual Joint* getJoint() { return joint; } 00114 protected: 00115 OneAxisJoint* joint; 00116 }; 00117 00118 /// Angular motor for TwoAxisJoints 00119 class AngularMotor2Axis : public AngularMotor { 00120 public: 00121 /** Constuct a motor attached to a TwoAxisJoint. It will its two axis of course. 00122 @param power The maximum force or torque that the motor will use to achieve the desired velocity. 00123 This must always be greater than or equal to zero. 00124 Setting this to zero (the default value) turns off the motor. 00125 */ 00126 AngularMotor2Axis(const OdeHandle& odeHandle, TwoAxisJoint* joint, double power1, double power2); 00127 virtual ~AngularMotor2Axis() {} 00128 00129 /// returns the number of Axis of this Motor 00130 virtual int getNumberOfAxes() { return 2; }; 00131 00132 /** sets the desired speed of the motor at the given axis. 00133 @param axisNumber either 0 or 1 00134 @param velocity Desired motor velocity (this will be an angular or linear velocity). 00135 */ 00136 virtual void set(int axisNumber, double velocity); 00137 virtual double get(int axisNumber) ; 00138 00139 virtual void setPower(double power); 00140 virtual void setPower(double power1, double power2); 00141 00142 /// return the maximal force 00143 virtual double getPower2(); 00144 00145 00146 virtual Joint* getJoint() { return joint; } 00147 protected: 00148 TwoAxisJoint* joint; 00149 }; 00150 00151 00152 /// Angular motor for Ball Joints with Euler control 00153 class AngularMotor3AxisEuler : public AngularMotor { 00154 public: 00155 /** Constuct a motor attached to a BallJoint. 00156 @param axis1 axis relative to body 1 00157 @param axis3 axis relative to body 2 (must be perpendicular to axis1 00158 (the axis 2 is calculated automatically) 00159 @param power The maximum force or torque that the motor will use to achieve the desired velocity. 00160 This must always be greater than or equal to zero. 00161 Setting this to zero (the default value) turns off the motor. 00162 */ 00163 AngularMotor3AxisEuler(const OdeHandle& odeHandle, BallJoint* joint, 00164 const Axis& axis1, const Axis& axis3, double power); 00165 00166 /// returns the number of Axis of this Motor 00167 virtual int getNumberOfAxes() { return 3; }; 00168 00169 /** sets the desired speed of the motor at the given axis. 00170 @param axisNumber either 0 or 1 00171 @param velocity Desired motor velocity (this will be an angular or linear velocity). 00172 */ 00173 virtual void set(int axisNumber, double velocity); 00174 /** returns the speed (PositionRate) at the given axis, or zero if the axis is out of range*/ 00175 virtual double get(int axisNumber) ; 00176 00177 /** sets the maximal force the motor has 00178 */ 00179 virtual void setPower(double power); 00180 00181 virtual Joint* getJoint() { return joint; } 00182 00183 protected: 00184 BallJoint* joint; 00185 }; 00186 00187 /// Angular motor for arbitrary Joints with custom axis (up to 3) 00188 class AngularMotorNAxis : public AngularMotor { 00189 public: 00190 /** Constuct a motor attached to any Joint (not Sliders!). 00191 The axis have to be provided by the user. 00192 @param axis list of axis vector and power If empty then it motor is disabled. 00193 Power is the maximum force or torque that the motor will use to achieve the desired velocity. 00194 This must always be greater than or equal to zero. 00195 Setting this to zero (the default value) turns off the motor. 00196 */ 00197 AngularMotorNAxis(const OdeHandle& odeHandle, Joint* joint, 00198 std::list<std::pair<double, Axis > > axis); 00199 00200 virtual ~AngularMotorNAxis() {} 00201 00202 /// returns the number of Axis of this Motor 00203 virtual int getNumberOfAxes(); 00204 00205 /** sets the desired speed of the motor at the given axis. 00206 @param velocity Desired motor velocity (this will be an angular or linear velocity). 00207 */ 00208 virtual void set(int axisNumber, double velocity); 00209 /** returns the speed (PositionRate) at the given axis, or zero if the axis is out of range 00210 The problem is, that we don't have actual information available. 00211 So we return the last set position!. 00212 */ 00213 virtual double get(int axisNumber) ; 00214 00215 virtual void setPower(double power); 00216 00217 virtual Joint* getJoint() { return joint; } 00218 00219 protected: 00220 Joint* joint; 00221 }; 00222 00223 00224 00225 } 00226 #endif