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
constantmotor.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 CONSTANTMOTOR_H_
25 #define CONSTANTMOTOR_H_
26 
27 #include <memory>
28 
29 #include "motor.h"
30 
31 
32 namespace lpzrobots {
33 
34  /**
35  Wrapper for Motor to have a constant set value (resulting in getMotorNumber()=0)
36  */
37  class ConstantMotor : public Motor {
38  public:
39  /// motor to wrap and constant values (for first and second motor value, all others = value1)
40  ConstantMotor(std::shared_ptr<Motor> motor, double value1=0.0, double value2=0.0)
41  : motor(motor), value1(value1), value2(value2)
42  { }
43 
44  virtual void init(Primitive* own, Joint* joint = 0) override {
45  motor->init(own, joint);
46  }
47 
48  virtual int getMotorNumber() const override { return 0; };
49 
50  virtual bool act(GlobalData& globaldata) {
51  int len = motor->getMotorNumber();
52  double* dat = new double[len];
53  std::fill_n( dat, len, value1);
54  if(len>1) dat[1]=value2;
55  motor->set(dat,len);
56  return true;
57  };
58 
59  // does nothing. the actions are done in act
60  virtual int set(const motor* values, int length) { return 0;};
61  protected:
62  std::shared_ptr<Motor> motor;
63  double value1;
64  double value2;
65  };
66 
67 }
68 
69 #endif /* !MOTOR_H_ */
Wrapper for Motor to have a constant set value (resulting in getMotorNumber()=0)
Definition: constantmotor.h:37
ConstantMotor(std::shared_ptr< Motor > motor, double value1=0.0, double value2=0.0)
motor to wrap and constant values (for first and second motor value, all others = value1) ...
Definition: constantmotor.h:40
virtual bool act(GlobalData &globaldata)
performs the actions, This is usually called in doInternalStuff() from the robot
Definition: constantmotor.h:50
Definition: joint.h:41
double value2
Definition: constantmotor.h:64
Abstact base class for attachable motors.
Definition: motor.h:35
virtual int getMotorNumber() const override
return the dimensionality of this motor
Definition: constantmotor.h:48
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
virtual void init(Primitive *own, Joint *joint=0) override
initialises motor with body of robot
Definition: constantmotor.h:44
Data structure holding all essential global information.
Definition: globaldata.h:57
double value1
Definition: constantmotor.h:63
double motor
Definition: types.h:30
virtual int set(const motor *values, int length)
sends the action commands to the motor.
Definition: constantmotor.h:60
std::shared_ptr< Motor > motor
Definition: constantmotor.h:60