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
ashigaru.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __ASHIGARU_H
25 #define __ASHIGARU_H
26 
27 #include "oderobot.h"
28 #include "raysensorbank.h"
29 
30 #include "primitive.h"
31 #include <selforg/inspectable.h>
32 #include <ode_robots/contactsensor.h>
33 #include <ode_robots/torquesensor.h>
35 
36 // include joints
37 #include <ode_robots/joint.h>
38 #include <ode_robots/oneaxisservo.h>
39 #include <ode_robots/twoaxisservo.h>
40 #include <ode_robots/spring.h>
41 
42 #include "osgprimitive.h"
43 
44 using namespace ASHIGARU;
45 using namespace lpzrobots;
46 
47 namespace lpzrobots {
48 
49 // This is the improved Transform class
50 // The aim is to get the position and some information of child object
51 //
52 class ImpTransform : public Transform{
53 public:
54  // constructor
55  ImpTransform(Primitive* parent, Primitive* child, const Pose& pose);
56  // destructor
57  virtual ~ImpTransform();
58 
59  // get Child pose
60  Pose getChildPose();
61 };
62 
63 
64 /***********************************************************************
65 
66  Here, I determine the parameters of the robot Ashigaru
67 
68  _ Joint Joint Joint
69  / \ TC CT FT
70  | |== o === | === | ====== Leg
71  \ _ / Shld Coxa Femur Tibia
72  Hexagon Body Link Link Link
73 
74 ************************************************************************/
75 
76 /*
77 // The internal parameters of the dynamixel
78 typedef struct {
79  //Unit m, kg
80  double length;
81  double width;
82  double height;
83 
84  double length_axis_to_center;// The length between the center of dynamixel and the axis.
85  double length_from_axis_to_tip; // The length between the axis and the tip of joint material(bra for servo)
86 
87  double mass;
88 }DynaAX12Conf;
89 
90 // The internal parameters of the Hexagon Body
91 typedef struct {
92  //Unit m, kg
93  double length;
94  double height;
95 
96  double mass;
97 }HexagonBodyConf;
98 
99 // The internal parameters of Foot frame (Tibia)
100 typedef struct {
101  //Unit m,kg
102  double length;
103  double width;
104  double height;
105 
106  double footRadius;
107 
108  double mass;
109 }FootFrameConf;
110 
111 typedef struct {
112  // Unit m
113  double length_center_to_TCJ;
114  double length_TCJ_to_CTJ;
115  double length_CTJ_to_FTJ;
116  double length_FTJ_to_Toe;
117 }JointLength;
118 
119 //The internal parameter of the servo
120 typedef struct{
121  // angle limit (rad)
122  // about TC
123  double TC_angle_MAX;
124  double TC_angle_MIN;
125  // about CT
126  double CT_angle_MAX;
127  double CT_angle_MIN;
128  // about FT
129  double FT_angle_MAX;
130  double FT_angle_MIN;
131 
132  //servoParam
133  // input current??
134  double power;
135  // damping coefficience
136  double damp;
137  // Max vel which the servo can get
138  double maxVel;
139 
140 }ServoParam;
141 
142 //! >ASHIGARU Configuration struct
143 typedef struct {
144 
145  double rate;// What rate should I multiple to real length number
146  double massRate; // what rate should I multiple to real mass number
147  double connectLength; // Length between center of the robot and that of another robot when they are connected each other.
148  double wholeMass; // the whole mass of the robot
149 
150  DynaAX12Conf dyna; // Dynamixel's real configuration
151  HexagonBodyConf body; // Body's real config.
152  FootFrameConf foot; // foot's real config.
153  JointLength jLength; // joint length param
154  ServoParam servoParam; // parameter for servo
155 
156 } AshigaruConf;
157 
158 */
159 
160 
161 /** Robot ASHIGARU :-)
162  3 legged robot which could be easily connected each other.
163 */
164 class Ashigaru : public OdeRobot, public Inspectable {
165 public:
166  // Leg location enum
167  enum LegPos {
168  L0, L1, L2, LEG_POS_MAX
169  };
170  // leg use mode (only Leg in this simulation)
171  enum LegPosUsage {
172  LEG, WHEEL, UNUSED
173  };
174  // Leg joint type enum
176  // thoroca-coxal joint for forward (+) and backward (-) movements
177  TC,
178  // coxa-trochanteral joint for elevation (+) and depression (-) of
179  // the leg
180  CT,
181  // femur-tibia joints for extension (+) and flexion (-) of the
182  // tibia
183  FT,
184  // maximum value, used for iteration
185  LEG_JOINT_TYPE_MAX
186  };
187  // motor name of ashigaru
189  // sensor name of ashigaru
191 
192 public: // Functions
193  // Constructor
194  Ashigaru(const OdeHandle& odehandle, const OsgHandle& osgHandle,
195  const AshigaruConf& conf, const std::string& name);
196 
197  // get default configuration (static func because it could be used before construction of the class)
198  static AshigaruConf getDefaultConf();
199 
200  // get Motor name from legPos and joint name
201  static MotorName getMotorName(LegPos leg, LegJointType joint);
202 
203  //destructor
204  virtual ~Ashigaru();
205 
206  /**
207  * updates the OSG nodes of the vehicle
208  */
209  virtual void update();
210 
211  /** sets the pose of the vehicle
212  @param pose desired 4x4 pose matrix
213  */
214  virtual void placeIntern(const osg::Matrix& pose);
215 
216  /** gets Primitives of Leg tibia
217  @param LegPos Number
218  */
219  Primitive* getTibiaPrimitive(LegPos leg);
220 
221 
222  /** returns actual sensorvalues
223  @param sensors sensors scaled to [-1,1]
224  @param sensornumber length of the sensor array
225  @return number of actually written sensors
226  */
227  virtual int getSensorsIntern(sensor* sensors, int sensornumber);
228 
229  /** sets actual motorcommands
230  @param motors motors scaled to [-1,1]
231  @param motornumber length of the motor array
232  */
233  virtual void setMotorsIntern(const double* motors, int motornumber);
234 
235  /** returns number of sensors
236  */
237  virtual int getSensorNumberIntern(){
238  return sensorno;
239  };
240 
241  /** returns number of motors
242  */
243  virtual int getMotorNumberIntern(){
244  return motorno;
245  };
246 
247  /** returns a vector with the positions of all segments of the robot
248  @param poslist vector of positions (of all robot segments)
249  @return length of the list
250  */
251  virtual int getSegmentsPosition(std::vector<Position> &poslist);
252 
253 
254  /** this function is called in each timestep. It should perform robot-internal checks,
255  like space-internal collision detection, sensor resets/update etc.
256  @param globalData structure that contains global data from the simulation environment
257  */
258  virtual void doInternalStuff(GlobalData& globalData);
259 
260  virtual void sense(GlobalData& globalData) override;
261 
262 
263  virtual double& getContactPoints() { return contactPoints; }
264 
265 protected: // Functions
266  /** creates vehicle at desired pose
267  @param pose 4x4 pose matrix
268  */
269  virtual void create(const osg::Matrix& pose);
270 
271  /** destroys vehicle and space
272  */
273  virtual void destroy();
274 
275  /**
276  * Assign a human readable name to a motor. This name is used for the
277  * associated inspectable value as used e.g. in guilogger.
278  *
279  * @param motorNo index of the motor (for standard motors defined by
280  * the MotorName enum)
281  * @param name human readable name for the motor
282  */
283  void nameMotor(const int motorNo, const char* name);
284 
285  /**
286  * Assign a human readable name to a sensor. This name is used for the
287  * associated inspectable value as used e.g. in guilogger.
288  *
289  * @param motorNo index of the motor (for standard motors defined by
290  * the SensorName enum)
291  * @param name human readable name for the sensor
292  */
293  void nameSensor(const int sensorNo, const char* name);
294 
295 
296  // getTorqueSensorData
297  sensor getTorqueData(TorqueSensor* torqueSensor);
298 
299  // convert Pose Matrix(Quatanion) to the roll, pitch, yaw angle (rad)
300  osg::Vec3d convert_Quat_to_RollPitchYaw(osg::Quat quat);
301 
302  // calculate COG Position
303  osg::Vec3d calc_COGPosition(void);
304 
305 
306  /**
307  * Inspectable interface
308  */
309  /*
310  virtual std::list<iparamkey> getInternalParamNames() const { return std::list<iparamkey>(); }
311 
312  virtual std::list<iparamval> getInternalParams() const { return std::list<iparamval>(); }*/
313  /*
314  virtual std::list<Inspectable::iparamkey> getInternalParamNames() const;
315 
316  virtual std::list<Inspectable::iparamval> getInternalParams() const;
317  */
318 
319 protected: // Values
320  // config param
322 
323  //! Leg struct
324  // Contains Objects, joints and servos for each Leg
325  struct Leg{
326  Leg(); // constructor, it make all of the value "0" !!
335  ImpTransform* shoulder;//shoulder trans thats object
342  };
343 
344  //! Trunk struct
345  // Contains Objects for Body (two hexagonal plate)
346 
347  struct Trunk{
348  Trunk(); // constructor, it make all of the value "0"
349  Primitive* tPlate[6];
350  Primitive* tTrans[5];
352  };
353 
354 
356 
357  // created flag
358  bool created; // true if robot was created
359 
360  /** typedefs */
361  typedef std::map<LegPos, HingeJoint*> HingeJointMap;
362  typedef std::map<LegPos, Leg> LegMap;
363  typedef std::map<LegPos, ContactSensor*> LegContactMap;
364  typedef std::map<MotorName, OneAxisServo*> MotorMap;
365  typedef std::map<MotorName, TorqueSensor*> MTorqMap;
366 
367  //typedef std::map<LegPos, LegPosUsage> LegPosUsageMap;
368  //typedef std::map<LegPos, IRSensor*> LegIRSensorMap;
369  typedef std::vector<Primitive*> PrimitiveList; // this is called Primitives
370  typedef std::vector<Joint*> JointList;
371  typedef std::vector<OneAxisServo*> ServoList;
372 
373  // tempolary
374  int sensorno; //number of sensors
375  int motorno; // number of motors
376 
377  // body
379 
380  // information on all legs
382 
383  // all the objects
384  //PrimitiveList objects;
385 
386  // all the joints
387  //JointList joints;
388 
389  // passive servos without a Motorname
391 
392  // contains all active servos
394 
395 
396  // sensors >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
397  // leg contact sensors
400 
401 
402  //RaySensorBank irSensorBank; // a collection of ir sensors
403 
404 };
405 
406 }
407 
408 
409 #endif
MTorqMap motorTorqSensors
Definition: ashigaru.h:399
virtual double & getContactPoints()
Definition: ashigaru.h:263
Data structure for accessing the ODE.
Definition: odehandle.h:44
Class for sensing the torque that are applied to the joint by a motor.
Definition: torquesensor.h:37
Primitive * footSphere
Definition: ashigaru.h:341
OneAxisServo * tcServo
Definition: ashigaru.h:331
Primitive * femur
Definition: ashigaru.h:338
Matrixd Matrix
Definition: osgforwarddecl.h:47
ImpTransform * shoulder
Definition: ashigaru.h:335
OneAxisServo * ftServo
Definition: ashigaru.h:333
std::map< LegPos, ContactSensor * > LegContactMap
Definition: ashigaru.h:363
std::vector< Joint * > JointList
Definition: ashigaru.h:370
double sensor
Definition: types.h:29
OneAxisServo * ctServo
Definition: ashigaru.h:332
Definition: ashigaru.h:172
SliderJoint * footJoint
Definition: ashigaru.h:330
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
HingeJoint * ctJoint
Definition: ashigaru.h:328
Spring * footSpring
Definition: ashigaru.h:334
ServoList passiveServos
Definition: ashigaru.h:390
int motorno
Definition: ashigaru.h:375
std::map< LegPos, Leg > LegMap
Definition: ashigaru.h:362
Primitive * coxa
Definition: ashigaru.h:337
bool created
Definition: ashigaru.h:358
std::vector< OneAxisServo * > ServoList
Definition: ashigaru.h:371
std::map< MotorName, TorqueSensor * > MTorqMap
Definition: ashigaru.h:365
Robot ASHIGARU :-) 3 legged robot which could be easily connected each other.
Definition: ashigaru.h:164
osg::Matrix Pose
Definition: pose.h:35
Definition: ashigaru.h:183
AshigaruSensorNames
Definition: ashigarusensormotordefinition.h:27
LegPosUsage
Definition: ashigaru.h:171
LegContactMap legContactSensors
Definition: ashigaru.h:398
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
Definition: ashigaru.h:177
Trunk trunk
Definition: ashigaru.h:378
Data structure holding all essential global information.
Definition: globaldata.h:57
MotorMap servos
Definition: ashigaru.h:393
Leg struct.
Definition: ashigaru.h:325
ImpTransform * tUpTrans
Definition: ashigaru.h:351
LegPos
Definition: ashigaru.h:167
Interface for inspectable objects.
Definition: inspectable.h:48
ImpTransform * foot
Definition: ashigaru.h:340
virtual int getMotorNumberIntern()
returns number of motors
Definition: ashigaru.h:243
double contactPoints
Definition: ashigaru.h:355
std::map< MotorName, OneAxisServo * > MotorMap
Definition: ashigaru.h:364
Definition: joint.h:304
LegMap legs
Definition: ashigaru.h:381
Definition: ashigaru.h:52
LegJointType
Definition: ashigaru.h:175
AshigaruSensorNames SensorName
Definition: ashigaru.h:190
AshigaruConf conf
Inspectable interface.
Definition: ashigaru.h:321
Abstract class for ODE robots.
Definition: oderobot.h:64
std::map< LegPos, HingeJoint * > HingeJointMap
typedefs
Definition: ashigaru.h:361
std::vector< Primitive * > PrimitiveList
Definition: ashigaru.h:369
AshigaruMotorNames
Definition: ashigarusensormotordefinition.h:112
Definition: spring.h:30
Primitive for transforming a geom (primitive without body) in respect to a body (primitive with body)...
Definition: primitive.h:410
double sensor
Definition: abstractrobot.h:43
Definition: ashigaru.h:180
HingeJoint * tcJoint
Definition: ashigaru.h:327
HingeJoint * ftJoint
Definition: ashigaru.h:329
>ASHIGARU Configuration struct
Definition: ashigarusensormotordefinition.h:222
AshigaruMotorNames MotorName
Definition: ashigaru.h:188
Definition: joint.h:183
Primitive * shoulderBox
Definition: ashigaru.h:336
Primitive * tibia
Definition: ashigaru.h:339
int sensorno
Definition: ashigaru.h:374
general servo motor to achieve position control
Definition: oneaxisservo.h:38
virtual int getSensorNumberIntern()
returns number of sensors
Definition: ashigaru.h:237
Trunk struct.
Definition: ashigaru.h:347