Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
kuka.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2013 *
3  * wbj *
4  * Frank Hesse <fhesse at physik3 dot gwdg dot de> *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  * *
21  ***************************************************************************/
22 #ifndef __KUKA_H
23 #define __KUKA_H
24 
25 #include "ode_robots/oderobot.h"
26 #include <vector>
27 #include "ode_robots/oneaxisservo.h"
28 #include "ode_robots/relativepositionsensor.h"
29 #include <osg/io_utils>
30 #include <math.h>
31 
32 /*
33 //the inverse kinematics from the fuerte package
34 #include "models/models.hpp"
35 #include "src/chain.hpp"
36 #include <src/frames_io.hpp>
37 //#include <src/chainiksolverpos_lma.hpp>
38 #include <src/chainiksolverpos_nr.hpp>
39 #include <src/chainiksolverpos_nr_jl.hpp>
40 #include <src/chainfksolver.hpp>
41 #include <src/chainfksolverpos_recursive.hpp>
42 #include <src/chainiksolvervel_pinv.hpp>
43 #include <src/chainiksolvervel_pinv_nso.hpp>
44 #include <src/chainiksolvervel_pinv_givens.hpp>
45 #include <src/chainiksolvervel_wdls.hpp>
46 #include <src/chainiksolverpos_lma.hpp>
47 
48 //#include <orocos_kinematics_dynamics/orocos_kdl/src/chainiksolverpos_lma.hpp>
49 */
50 namespace lpzrobots {
51 
52  class Primitive;
53  class Hinge2Joint;
54 
55  /**Robot that emulates the Kuka lightweight robot arm,
56  consisting of 5 arm segments, one endeffector upon and a small box representing
57  the Tool-Center-Point (TCP) of the endeffector where different tools
58  can be mounted.
59  All segments are linked with hinge joints, whch allow a One-axis-rotation above
60  the x- or z- axis.
61  Relative position sensors can measure its relative position to given objects.
62  The sensors have to be normalized with the maximal distance, they will measure during the simulation (default = 1).
63  */
64  class Kuka : public OdeRobot{
65  public:
66  friend class Kuka2;
67  /**
68  * constructor of robot
69  * @param odeHandle data structure for accessing ODE
70  * @param osgHandle ata structure for accessing OSG
71  * @param size scaling of the robot (original size = 1)
72  * @param objectsOfInterest a list of primitives (objects, obstacles) to which the robot will measure its relative position
73  */
74  Kuka(const OdeHandle& odeHandle, const OsgHandle& osgHandle, const std::string& name,
75  double size=1, std::vector<Primitive*> objectsOfInterest = std::vector<Primitive*>());
76 
77  virtual ~Kuka(){
78  destroy();
79  };
80 
81  /**
82  * updates the OSG nodes of the vehicle
83  */
84  virtual void update();
85 
86 
87  /** sets the pose of the vehicle
88  @param pose desired pose matrix
89  */
90  virtual void placeIntern(const osg::Matrix& pose);
91 
92  /** returns actual sensorvalues see kuka.cpp to see what values are returned
93  @param sensors sensors scaled to [-1,1]
94  @param sensornumber length of the sensor array
95  @return number of actually written sensors
96  */
97  virtual int getSensorsIntern(sensor* sensors, int sensornumber);
98 
99  /** sets actual motorcommands
100  @param motors motors scaled to [-1,1]
101  @param motornumber length of the motor array
102  */
103  virtual void setMotorsIntern(const double* motors, int motornumber);
104 
105  /** blocks and reactivates joints during the simulations
106  the blocked joint will be set to its initial position
107  @param jointNo the index of the only joint that is to be blocked
108  */
109  virtual void blockJoints(int joint);
110 
111  /** grasps an object by creating a fixed joint between the gripper (outermost primitive of the arm)
112  and a desired object
113  @param the primitive that is to be grasped
114  */
115  virtual bool grasp(Primitive *object);
116 
117 /* grasps an object by creating a fixed joint between the gripper (outermost primitive of the arm)
118  and a desired object and sets the sensor value 23 to the given value
119  @param the primitive that is to be grasped
120  @param sensor23 value that is to be returned by sensor 23 as long as the object is grasped.
121  */
122  virtual bool grasp(Primitive *object, int sensor23);
123 
124  /** releases the grasped object
125  */
126  virtual void release();
127 
128 
129  /** returns number of sensors
130  */
131  virtual int getSensorNumberIntern(){
132  return sensorno;
133  };
134 
135  /** returns number of motors
136  */
137  virtual int getMotorNumberIntern(){
138  return motorno;
139  };
140 
141  /** switches between manual Control (motor commands written into the manualCommands-vector) and Controller commands
142  */
143  virtual void toggleManualControlMode();
144 
145 
146  /** enables the manual command mode an moves the arm to its initial upright position
147  */
148  virtual void candle(){
149  manualControl = true;
150  for (int i=0; i<motorno; i++) {manualCommands[i] = 0;}
151  };
152 
153  /** returns the desired position of a joint during the manua control mode:
154  the current target position the joint is moving to or
155  has already reached.
156  @param number of the joint
157  */
158  virtual double getJointTarget(int jointno){
159  return manualCommands[jointno];
160  };
161 
162  /** prints the current joint configuration as a vector of reals € [-1,1] and as a vector of degrees
163  only available in manual control mode
164  */
165  virtual void printJointConf();
166 
167  /**moves a joint to a desired position, only available in manual Control Mode
168  @param jointno the number of the joint to be moved
169  @param pos the desired position of the joint. Must be in [-1,1]
170  */
171  virtual void moveJoint(int jointno, double pos);
172 
173  /** returns a pointer to the endeffector
174  */
176  return endeffector;
177  }
178  /** returns a pointer to the gripper (the uppermost primitive)
179  */
180  virtual Primitive* getGripper(){
181  return gripper;
182  }
183  /** prints the position of the endeffector
184  */
185  virtual void printEndeffectorPosition(){
186  //The LpZ Position
187  std::cout<< "Lpz Endeffector Position: \t";
188  Pos p = endeffector->getPosition();
189  p.print();
190  }
191 
192  /** prints the pose of the endeffector
193  */
194  virtual void printEndeffectorPose(){
195  std::cout << "Pose des Endeffektors: "<< endeffector->getPose()<< "\n";
196  }
197 
198 /* sets the reference of the first relative-distance-sensor to the given object
199  --> afterwards sensors 15-17 will return the relative distances of the endeffector to the object*/
200  virtual void setReference(Primitive* target){
201  relSensors[0]->setReference(target);
202  };
203 
204 //the following methods are for a specific simulation and have to be used with care
205 // they require the KDL orocos files
206 
207 
208  /* calculate the inverse Kinematics
209  @params the desired position in a KDL::Frame
210  @params the KDL::JntArray where the joint conf should be written
211  @return returns 0 if everything was ok, -3 if max iterations exceeded (desired position could be not reachable)
212  */
213  //virtual int getIK(KDL::Frame pos_goal, KDL::JntArray* q_target);
214 
215  /** will move the endeffector to the desired position
216  by transforming the Cartesian Position into a joint configuration
217  and writing this jnt conf into the manualCommands array
218  @param the desired position and Pose in a 4x4 KDL-Frame
219  3x3 as rotation 3x position
220  1x4 irrelevant 1
221  you can use the KDL::Frame( Vector )-Constructor for zero rotation
222  */
223  //virtual void moveEndeffectorTo(KDL::Frame);
224 
225  /** moves the arm over an object
226  @param the Main primitive of the target object
227  */
228  //virtual void moveOverObject(Primitive* targetObj);
229 
230  //virtual void moveTowardsObject(Primitive* targetObj);
231 
232  /** generate a random move using the IK Solver
233  */
234  //virtual void randomMove();
235 
236  /* prints the current joint configuration and the cartesian position of
237  the endeffector calculated by the orocos-KDL bib
238  */
239  //virtual void jntToPos();
240 
241  /* moves the endeffector in neg direction along one axis using the IK solver
242  1/-1 move in positve/negative x direction
243  2/-2 move in positve/negative y direction
244  3/-3 move in positve/negative z direction
245  */
246  //virtual void moveAlongAxis(int axis);
247 
248  /** returns the orientation that minimizes the distance between the TCP and the center of the target object
249  @param pos the Position of the endeffector
250  @param target the Position of the target
251  */
252  //virtual KDL::Rotation getRotation(KDL::Vector pos, KDL::Vector target);
253 
254  /** returns the orientation that minimizes the distance between the TCP and the center of the target object
255  @param pos the Position of the endeffector
256  @param target the Position of the target
257  */
258  //virtual KDL::Rotation getRotation(Position pos, Position target);
259 
260 
261 
262  protected:
263  /** creates vehicle at desired pose
264  @param pose 4x4 pose matrix
265  */
266  virtual void create(const osg::Matrix& pose);
267 
268  /** destroys vehicle and space
269  */
270  virtual void destroy();
271 
272 
273  /** returns the maximal power of a motor
274  */
275  int getPower( int i);
276 
277  /** returns the maximal velocity of a motor
278  */
279  int getVelocity( int i);
280 
281 
282  /** additional things for collision handling can be done here
283  */
284  static void mycallback(void *data, dGeomID o1, dGeomID o2);
285 
286  bool created; // true if robot was created
287  double length; // length of segments
288  double width; // width of segments
289  double cmass; // mass of segments
290  double gripper_radius; // radius of the gripper
291  double socketSize; //size of the socket - the lowest segment of the Kuka arm, the segment that is fixed to the environment
292  double endeffector_radius; //the radius of the endeffector
293 
294 
295  int sensorno; // number of sensors
296  int motorno; // number of motors
297  int segmentsno; // number of arm segments
298  int jointsno; // number of joints
299  bool grasped; // true if robot holds an object
300  bool gripper_active; // true if gripper tried to grasp something. Will be reset after one simstep.
301  double simSize; //will hold the size of the simulation (e.o. Kuka constructor)
302 
303  Joint* griff; //can be used to grasp objects
304  Primitive* endeffector; //pointer to the endeffector
305  Primitive* gripper; //pointer to the gripper
306 
307  bool manualControl; //used to block the motorcommands sent by the controller and enable the manual
308  // control mode
309  std::vector< double > manualCommands; //used to store the manually entered motorcommands. the joint destinations have to be given in radians
310 
311  std::vector< OneAxisJoint * > joints; //list of all joints , specified as OneAxis to ease use of servos
312  std::vector<double> speed; // factor for adjusting speed of robot for each joint individually
313  std::vector<double> max_force; // maximal force for motors
314  std::vector <OneAxisServo*> hingeServos; //Servos for the joints
315  std::vector<Primitive*> objectsOfInterest; // list of all objects the arm can/must keep track of/ interact/sense distance
316 
317  std::vector< RelativePositionSensor* > relSensors; //list of all sensors the kuka uses to measure distances
318 
319 //these
320 
321 //especially for my bachelor thesis:
322  int sensor23;
323 
324  /*
325  //stuff for the KDL orocos kinematics handling
326  KDL::Rotation lastRotation;
327  KDL::Vector lastPosition;
328  KDL::Chain chain;
329  KDL::JntArray lastJointConf;
330  std::vector<KDL::Rotation> orientations; //stores orientations for the e.o. getIK()
331 */
332 
333 
334  };
335 
336 }
337 #endif
double width
Definition: kuka.h:288
std::vector< double > speed
Definition: kuka.h:312
friend class Kuka2
Definition: kuka.h:66
virtual void printJointConf()
prints the current joint configuration as a vector of reals € [-1,1] and as a vector of degrees only ...
Definition: kuka.cpp:458
Data structure for accessing the ODE.
Definition: odehandle.h:44
virtual double getJointTarget(int jointno)
returns the desired position of a joint during the manua control mode: the current target position th...
Definition: kuka.h:158
double cmass
Definition: kuka.h:289
Robot that emulates the Kuka lightweight robot arm, consisting of 5 arm segments, one endeffector upo...
Definition: kuka.h:64
virtual int getSensorNumberIntern()
returns number of sensors
Definition: kuka.h:131
Matrixd Matrix
Definition: osgforwarddecl.h:47
std::vector< Primitive * > objectsOfInterest
Definition: kuka.h:315
Kuka(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const std::string &name, double size=1, std::vector< Primitive * > objectsOfInterest=std::vector< Primitive * >())
constructor of robot
Definition: kuka.cpp:56
Definition: joint.h:41
double simSize
Definition: kuka.h:301
std::vector< RelativePositionSensor * > relSensors
Definition: kuka.h:317
virtual void create(const osg::Matrix &pose)
will move the endeffector to the desired position by transforming the Cartesian Position into a joint...
Definition: kuka.cpp:212
double sensor
Definition: types.h:29
virtual void printEndeffectorPosition()
prints the position of the endeffector
Definition: kuka.h:185
Definition: pos.h:36
virtual ~Kuka()
Definition: kuka.h:77
Primitive * gripper
Definition: kuka.h:305
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual void candle()
enables the manual command mode an moves the arm to its initial upright position
Definition: kuka.h:148
int segmentsno
Definition: kuka.h:297
Primitive * endeffector
Definition: kuka.h:304
double endeffector_radius
Definition: kuka.h:292
virtual int getMotorNumberIntern()
returns number of motors
Definition: kuka.h:137
virtual void setReference(Primitive *target)
Definition: kuka.h:200
virtual Primitive * getEndeffector()
returns a pointer to the endeffector
Definition: kuka.h:175
int motorno
Definition: kuka.h:296
virtual Primitive * getGripper()
returns a pointer to the gripper (the uppermost primitive)
Definition: kuka.h:180
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
virtual void placeIntern(const osg::Matrix &pose)
sets the pose of the vehicle
Definition: kuka.cpp:191
bool manualControl
Definition: kuka.h:307
virtual Pose getPose() const
returns the pose
Definition: primitive.cpp:187
virtual void moveJoint(int jointno, double pos)
moves a joint to a desired position, only available in manual Control Mode
Definition: kuka.cpp:477
virtual int getSensorsIntern(sensor *sensors, int sensornumber)
returns actual sensorvalues see kuka.cpp to see what values are returned
Definition: kuka.cpp:142
bool gripper_active
Definition: kuka.h:300
std::list< SensorAttachment > sensors
Definition: oderobot.h:269
std::vector< double > manualCommands
Definition: kuka.h:309
std::vector< double > max_force
Definition: kuka.h:313
bool grasped
Definition: kuka.h:299
Joint * griff
Definition: kuka.h:303
virtual void release()
releases the grasped object
Definition: kuka.cpp:410
void print() const
Definition: pos.h:56
OsgHandle osgHandle
Definition: oderobot.h:278
OdeHandle odeHandle
Definition: oderobot.h:277
int sensor23
Definition: kuka.h:322
std::vector< OneAxisJoint * > joints
Definition: kuka.h:311
int jointsno
Definition: kuka.h:298
virtual void toggleManualControlMode()
switches between manual Control (motor commands written into the manualCommands-vector) and Controlle...
Definition: kuka.cpp:309
std::vector< OneAxisServo * > hingeServos
Definition: kuka.h:314
virtual void printEndeffectorPose()
prints the pose of the endeffector
Definition: kuka.h:194
Abstract class for ODE robots.
Definition: oderobot.h:64
virtual bool grasp(Primitive *object)
grasps an object by creating a fixed joint between the gripper (outermost primitive of the arm) and a...
Definition: kuka.cpp:362
virtual Pos getPosition() const
returns the position
Definition: primitive.cpp:181
static void mycallback(void *data, dGeomID o1, dGeomID o2)
additional things for collision handling can be done here
virtual void blockJoints(int joint)
blocks and reactivates joints during the simulations the blocked joint will be set to its initial pos...
Definition: kuka.cpp:323
virtual void destroy()
destroys vehicle and space
Definition: kuka.cpp:437
bool created
Definition: kuka.h:286
virtual void update()
updates the OSG nodes of the vehicle
Definition: kuka.cpp:201
double gripper_radius
Definition: kuka.h:290
int getPower(int i)
returns the maximal power of a motor
Definition: kuka.cpp:420
double socketSize
Definition: kuka.h:291
int getVelocity(int i)
returns the maximal velocity of a motor
Definition: kuka.cpp:428
virtual void setMotorsIntern(const double *motors, int motornumber)
sets actual motorcommands
Definition: kuka.cpp:117
double length
Definition: kuka.h:287
std::list< MotorAttachment > motors
Definition: oderobot.h:270
int sensorno
Definition: kuka.h:295