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
nejihebi.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2012 by1 *
3  * Timo Nachstedt <nachstedt@physik3.gwdg.de> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  * *
20  ***************************************************************************/
21 
22 #ifndef LPZROBOTS_ODE_ROBOTS_ROBOTS_NEJIHEBI_H_
23 #define LPZROBOTS_ODE_ROBOTS_ROBOTS_NEJIHEBI_H_
24 
25 #include <ode_robots/oderobot.h>
26 
27 // forward declarations
28 namespace lpzrobots {
29  class Box;
30  class Color;
31  class Cylinder;
32  class HingeJoint;
33  class TwoAxisServoVel;
34 }
35 
36 
37 namespace lpzrobots{
38  /**
39  * Nejihebi Robot
40  *
41  * This is a snake-like robot with screw drive mechanism as developed at
42  * the Matsuno Lab in Kyoto, Japan. For details on the real robot see:
43  *
44  * Fukushima et al: Modeling and Control of a Snake-Like Robot Using the
45  * Screw-Drive Mechanism. IEEE Transactions on Robotics 28(3), 2012.
46  *
47  */
48  class Nejihebi : public OdeRobot, public Inspectable {
49  public:
50 
51  /**
52  * Struct containing all the configuration options for the nejihebi robot
53  */
54  struct Conf {
55  /** number of screw elements */
57  /** configurations for the two ball bearings at the robot head */
58  struct {
59  /** color of ball bearing */
61  /** mass of each ball bearing */
62  double mass;
63  /** radius of each ball bearing */
64  double radius;
65  /** color of the stick holding the ball bearing */
67  /** length of the stick holding the ball bearing */
68  double stickLength;
69  /** mass of the stick holding the ball bearing */
70  double stickMass;
71  /** width of the stick holding the ball bearing */
72  double stickWidth;
73  } ballBearing;
74  /** configurations for the blades holding the passive wheels */
75  struct {
76  /** angle of the blades versus the screw axis */
77  double angle;
78  /** color of the blades */
79  Color color;
80  /** height of the blades */
81  double height;
82  /** length of the blades */
83  double length;
84  /** mass of each blade */
85  double mass;
86  /** number of wheels per blade */
87  int wheels;
88  /** width of each blade */
89  double width;
90  } blade;
91  /** configurations for the robot head */
92  struct {
93  /** color of the robot head */
94  Color color;
95  /** height of the robot head */
96  double height;
97  /** length of the robot head */
98  double length;
99  /** mass of the robot head */
100  double mass;
101  /** width of the robot head */
102  double width;
103  } head;
104  /** configurations for the inner non-rotating part of the screw
105  * elements */
106  struct {
107  /** length of inner body behind the screw center */
108  double backLength;
109  /** color of the inner body */
110  Color color;
111  /** length of inner body before the screw center */
112  double frontLength;
113  /** height of the inner body */
114  double height;
115  /** mass of the inner body */
116  double mass;
117  /** width of the inner body */
118  double width;
119  } innerBody;
120  /** configurations for the joints between the screw elements */
121  struct {
122  /** damping of the joint servo motors */
123  double damping;
124  /** maximum velocity of the joint servo motors */
125  double maxVel;
126  /** configurations for the pitch (up-down) servo motors */
127  struct {
128  /** minimum angle [rad] */
129  double minAngle;
130  /** maximum angle [rad] */
131  double maxAngle;
132  /** maximum power */
133  double power;
134  } pitch;
135  /** configurations for the yaw (left-right) servo motors */
136  struct {
137  /** minimum angle [rad] */
138  double minAngle;
139  /** maximum angle [rad] */
140  double maxAngle;
141  /** maximum power */
142  double power;
143  } yaw;
144  } jointUnit;
145  /** configurations for the basic ring of the screw elements */
146  struct {
147  /** number of blades per screw element */
148  int blades;
149  /** color of screw ring */
150  Color color;
151  /** mass of screw ring */
152  double mass;
153  /** maximum torque for screw ring */
154  double maxForce;
155  /** maximum speed for screw ring */
156  double maxSpeed;
157  /** radius of screw ring */
158  double radius;
159  /** width of screw ring */
160  double width;
161  } screwbase;
162  /** configurations for the passive wheels */
163  struct {
164  /** decides if the wheel axis will be visible */
166  /** size of the wheel axis if visible */
167  double axisSize;
168  /** color of the passive wheels */
169  Color color;
170  /** mass of each passive wheel */
171  double mass;
172  /** radius of the circle on which the wheels are placed */
173  double posradius;
174  /** offset of the center of the position circle and the screw
175  * center */
176  double posshift;
177  /** angle size of the circle segment on which the wheels are
178  * placed */
179  double possegment;
180  /** radius of the passive wheels */
181  double radius;
182  /** width of the passive wheels */
183  double width;
184  } wheel;
185  };
186 
187  /**
188  * Constructor
189  *
190  * @param odeHandle data structure for accessing ODE
191  * @param osgHandle data structure for accessing OSG
192  * @param conf configuration object
193  * @param name name to display for this robot
194  */
196  const Conf& conf = getDefaultConf(),
197  const std::string& name = "ScrewDriveSnake");
198 
199  /**
200  * Destructor
201  */
202  virtual ~Nejihebi();
203 
204  /**
205  * Returns the current configuration of the robot
206  * @return current configuration
207  */
208  const Conf& getConf() const;
209 
210  /**
211  * Returns default configuration.
212  *
213  * This method returns a configuration object with the default
214  * configuration for the robot which is supposed to be as close as
215  * possible to the real robot.
216  *
217  * @return default configuration
218  */
219  static Conf getDefaultConf();
220 
222 
224 
225  /**
226  * Returns main primitive of the robot.
227  *
228  * This method returns the primitive of the robot that is used for
229  * tracking and camera following. For the Nejihebi robot that is the
230  * robot head object
231  *
232  * @return pointer to the robot head primitive
233  */
234  virtual Primitive* getMainPrimitive() const;
235 
236  /**
237  * Returns number of motors.
238  *
239  * @return number of motors
240  */
241  virtual int getMotorNumberIntern();
242 
243  /**
244  * Returns number of sensors.
245  *
246  * @return number of sensors
247  */
248  virtual int getSensorNumberIntern();
249 
250  /**
251  * Returns current sensor values
252  *
253  * This method returns all the sensor values of the robot. They are scaled
254  * into the interval -1 to 1. Let N be the number of screws for the
255  * current robot object. Then the sensor values are as follows:
256  *
257  * 0 : rotation angle of first screw (foremost screw) [-pi, pi]
258  * ...
259  * N-1 : rotation angle of N-th screw (backmost screw) [-pi, pi]
260  * N : position of first yaw yoint (foremost joint) [-pi, pi]
261  * N+1 : angle velocity of first yaw joint [-maxVel, maxVel]
262  * N+2 : position of first pitch joint [-pi, pi]
263  * N+3 : angle velocity of first pitch joint [-maxVel, maxVel]
264  * N+4 : position of second yaw joint
265  * ...
266  * 5N-5 : angle velocity of last pitch joint
267  *
268  * @param sensors sensor array to which the sensors scaled to [-1,1] will
269  * be written
270  * @param sensornumber length of the sensor array
271  * @return number of actually written sensors
272  */
273  virtual int getSensorsIntern(sensor* sensors, int sensornumber);
274 
275  /**
276  * Assigns a name to a motor.
277  *
278  * This method assigns a human readable name to a motor. This name is used
279  * for the associated inspectable value of the wiring as used e.g. in
280  * guilogger.
281  *
282  * @param motorNo index of the motor
283  * @param name human readable name for the motor
284  */
285  void nameMotor(const int motorNo, const std::string& name);
286 
287  /**
288  * Assigns a name to sensor.
289  *
290  * This method assigns a human readable name to a sensor. This name is
291  * used for the associated inspectable value of the wiring as used e.g.
292  * in guilogger.
293  *
294  * @param sensorNo index of the sensor
295  * @param name human readable name for the sensor
296  */
297  void nameSensor(const int sensorNo, const std::string& name);
298 
299  /**
300  * Sets the pose of the vehicle
301  *
302  * @param pose desired pose matrix
303  */
304  virtual void placeIntern(const osg::Matrix& pose);
305 
306  /**
307  * Sets current motorcommands
308  *
309  * This method is used to deliver motor commands to the robots. If N is
310  * the number of screw elements of the robot then the meaning of the motor
311  * commands is as follows:
312  *
313  * 0 : goal speed for first screw (foremost screw) [-maxVel, maxVel]
314  * N-1 : goal speed for N-th screw (backmost screw) [-maxVel, maxVel]
315  * N : goal position for first yaw joint [-pi, pi]
316  * N+1 : goal position for first pitch joint [-pi, pi]
317  * N+2 : goal position for second yaw joint [-pi, pi]
318  * ...
319  * 3N-3 : goal position for last pitch joint [-pi, pi]
320  * 3N-2 : torque limit for first yaw joint [0:1]
321  * 3N-1 : torque limit for first pitch joint [0:1]
322  * 3N : torque limit for second yaw joint [0:1]
323  * ...
324  * 5N-5 : torque limit for last pitch joint [0:1]
325  *
326  * @param motors motors scaled to [-1,1]
327  * @param motornumber length of the motor array
328  */
329  virtual void setMotorsIntern(const double* motors, int motornumber);
330 
331  private:
332 
333  /** Struct to hold all relevant parts of a screw element */
334  struct Screw {
335  Cylinder * screwBase;
336  Box * innerPart;
337  HingeJoint * joint;
338  };
339 
340  /**
341  * Creates vehicle at desired position
342  *
343  * @param pose 4x4 pose matrix defining desired position
344  */
345  void create(const osg::Matrix& pose);
346 
347  /**
348  * Creates a screw element at the desired position.
349  *
350  * This method creates a single screw element at the desired position.
351  * With the parameter inverted you can switch between left-turning
352  * and right-turning screw elements.
353  *
354  * @param pose 4x3 pose matrix defining desired position
355  */
356  Screw createScrew(const osg::Matrix& pose, const bool inverted);
357 
358  /** pointer to the head box of the robot*/
359  Box* head;
360  /** vector holding all structs for all screw elements */
361  std::vector<Screw> screws;
362  /** vector holding all joint servo motors */
363  std::vector<TwoAxisServoVel*> servos;
364  /** configuration object of the robot */
365  Conf conf;
366  };
367 }
368 
369 
370 #endif /* LPZROBOTS_ODE_ROBOTS_ROBOTS_SCREWDRIVESNAKE_H_ */
virtual Primitive * getMainPrimitive() const
Returns main primitive of the robot.
Definition: nejihebi.cpp:342
virtual void placeIntern(const osg::Matrix &pose)
Sets the pose of the vehicle.
Definition: nejihebi.cpp:380
double mass
mass of each ball bearing
Definition: nejihebi.h:62
Inspectable::iparamkeylist getInternalParamNames() const
The list of the names of all internal parameters given by getInternalParams().
Definition: nejihebi.cpp:308
Data structure for accessing the ODE.
Definition: odehandle.h:44
const Conf & getConf() const
Returns the current configuration of the robot.
Definition: nejihebi.cpp:250
Cylinder primitive.
Definition: primitive.h:326
Matrixd Matrix
Definition: osgforwarddecl.h:47
bool axisVisible
decides if the wheel axis will be visible
Definition: nejihebi.h:165
void nameMotor(const int motorNo, const std::string &name)
Assigns a name to a motor.
Definition: nejihebi.cpp:376
double angle
angle of the blades versus the screw axis
Definition: nejihebi.h:77
Nejihebi(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const Conf &conf=getDefaultConf(), const std::string &name="ScrewDriveSnake")
Constructor.
Definition: nejihebi.cpp:35
double sensor
Definition: types.h:29
double posradius
radius of the circle on which the wheels are placed
Definition: nejihebi.h:173
iparamkey name
Definition: inspectable.h:251
struct lpzrobots::Nejihebi::Conf::@4 ballBearing
configurations for the two ball bearings at the robot head
double backLength
length of inner body behind the screw center
Definition: nejihebi.h:108
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
struct lpzrobots::Nejihebi::Conf::@7 innerBody
configurations for the inner non-rotating part of the screw elements
double width
width of each blade
Definition: nejihebi.h:89
double maxVel
maximum velocity of the joint servo motors
Definition: nejihebi.h:125
double possegment
angle size of the circle segment on which the wheels are placed
Definition: nejihebi.h:179
struct lpzrobots::Nejihebi::Conf::@10 wheel
configurations for the passive wheels
struct lpzrobots::Nejihebi::Conf::@8 jointUnit
configurations for the joints between the screw elements
void nameSensor(const int sensorNo, const std::string &name)
Assigns a name to sensor.
Definition: nejihebi.cpp:372
double height
height of the blades
Definition: nejihebi.h:81
double maxAngle
maximum angle [rad]
Definition: nejihebi.h:131
virtual void setMotorsIntern(const double *motors, int motornumber)
Sets current motorcommands.
Definition: nejihebi.cpp:384
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
double length
length of the blades
Definition: nejihebi.h:83
Definition: color.h:32
struct lpzrobots::Nejihebi::Conf::@8::@11 pitch
configurations for the pitch (up-down) servo motors
Box primitive.
Definition: primitive.h:267
std::list< SensorAttachment > sensors
Definition: oderobot.h:269
double maxForce
maximum torque for screw ring
Definition: nejihebi.h:154
double power
maximum power
Definition: nejihebi.h:133
Interface for inspectable objects.
Definition: inspectable.h:48
double minAngle
minimum angle [rad]
Definition: nejihebi.h:129
double stickWidth
width of the stick holding the ball bearing
Definition: nejihebi.h:72
Color color
color of ball bearing
Definition: nejihebi.h:60
double stickMass
mass of the stick holding the ball bearing
Definition: nejihebi.h:70
Struct containing all the configuration options for the nejihebi robot.
Definition: nejihebi.h:54
OsgHandle osgHandle
Definition: oderobot.h:278
virtual int getMotorNumberIntern()
Returns number of motors.
Definition: nejihebi.cpp:346
OdeHandle odeHandle
Definition: oderobot.h:277
double axisSize
size of the wheel axis if visible
Definition: nejihebi.h:167
Inspectable::iparamvallist getInternalParams() const
Definition: nejihebi.cpp:325
double damping
damping of the joint servo motors
Definition: nejihebi.h:123
double radius
radius of each ball bearing
Definition: nejihebi.h:64
virtual int getSensorsIntern(sensor *sensors, int sensornumber)
Returns current sensor values.
Definition: nejihebi.cpp:354
struct lpzrobots::Nejihebi::Conf::@8::@12 yaw
configurations for the yaw (left-right) servo motors
Abstract class for ODE robots.
Definition: oderobot.h:64
double maxSpeed
maximum speed for screw ring
Definition: nejihebi.h:156
struct lpzrobots::Nejihebi::Conf::@6 head
configurations for the robot head
int blades
number of blades per screw element
Definition: nejihebi.h:148
virtual int getSensorNumberIntern()
Returns number of sensors.
Definition: nejihebi.cpp:350
virtual ~Nejihebi()
Destructor.
Definition: nejihebi.cpp:43
Definition: joint.h:183
int numberOfScrews
number of screw elements
Definition: nejihebi.h:56
static Conf getDefaultConf()
Returns default configuration.
Definition: nejihebi.cpp:254
std::list< iparamkey > iparamkeylist
Definition: inspectable.h:59
double posshift
offset of the center of the position circle and the screw center
Definition: nejihebi.h:176
std::list< iparamval > iparamvallist
Definition: inspectable.h:61
Color stickColor
color of the stick holding the ball bearing
Definition: nejihebi.h:66
int wheels
number of wheels per blade
Definition: nejihebi.h:87
struct lpzrobots::Nejihebi::Conf::@9 screwbase
configurations for the basic ring of the screw elements
std::list< MotorAttachment > motors
Definition: oderobot.h:270
double stickLength
length of the stick holding the ball bearing
Definition: nejihebi.h:68
struct lpzrobots::Nejihebi::Conf::@5 blade
configurations for the blades holding the passive wheels
double frontLength
length of inner body before the screw center
Definition: nejihebi.h:112
Nejihebi Robot.
Definition: nejihebi.h:48