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
spring.h
Go to the documentation of this file.
1 /*
2  * spring.h
3  *
4  * This is a OneAxisServo that leaves the position coordinate unscaled
5  * and unshifted. The 0 position is that of initialization of the two joint
6  * parts. It now allows preloading of the spring and more control but also
7  * more errors. Use carefully!
8  *
9  * Created on: Nov 2, 2010
10  * Author: mab
11  */
12 
13 #ifndef SPRING_H_
14 #define SPRING_H_
15 
16 
17 #include <ode_robots/joint.h>
18 #include <ode_robots/oneaxisservo.h>
19 #include <ode_robots/pid.h>
20 #include <ode_robots/angularmotor.h>
21 #include <selforg/controller_misc.h>
22 
23 namespace lpzrobots {
24 
25 /* This is a OneAxisServo that leaves the position coordinate unscaled
26 * and unshifted. The 0 position is that of initialization of the two joint
27 * parts. It now allows preloading of the spring and more control but also
28 * more errors. Use carefully!
29 */
30 class Spring : public OneAxisServo{
31 public:
32  Spring(OneAxisJoint* joint, double _min, double _max,
33  double power, double damp=0.2, double integration=0.0,
34  double maxVel=10.0, double jointLimit = 1.0)
35  : OneAxisServo(joint, _min, _max, power, damp, integration, maxVel, jointLimit, false){
36  }
37  virtual ~Spring(){}
38 
39  /** sets the set point of the servo.
40  Position is relative to initial position of the two parts
41  connected by the spring
42  */
43  virtual void set(double pos){
45 
46  double force = pid.stepNoCutoff(joint->getPosition1(), joint->odeHandle.getTime());
47  force = clip(force,-10*pid.KP, 10*pid.KP); // limit force to 10*KP
48  joint->addForce1(force);
49  if(maxVel>0){
52  }
53  }
54 
55  /** returns the position of the slider in ranges [-1, 1] (scaled by min, max)*/
56  virtual double get(){
57  double pos = joint->getPosition1();
58  return pos;
59  }
60 
61  //want to allow all kinds of borders,
62  virtual void setMinMax(double _min, double _max){
63  min=_min;
64  max=_max;
65  joint->setParam(dParamLoStop, min - fabs(min) * (jointLimit-1));
66  joint->setParam(dParamHiStop, max + fabs(max) * (jointLimit-1));
67  }
68 
69 };
70 
71 }
72 
73 #endif /* SPRING_H_ */
virtual void addForce1(double force)=0
double stepNoCutoff(double newsensorval, double time)
perform one step of the PID controller without cutoffs used for Center-Servos
Definition: pid.cpp:93
virtual ~Spring()
Definition: spring.h:37
double power(void *c, double x)
returns x the power c (as a double)
Definition: controller_misc.cpp:17
virtual void set(double pos)
sets the set point of the servo.
Definition: spring.h:43
double getTime()
Definition: odehandle.h:88
virtual double getPosition1() const =0
virtual void setMinMax(double _min, double _max)
Definition: spring.h:62
Definition: joint.h:108
OdeHandle odeHandle
Definition: joint.h:105
OneAxisJoint * joint
Definition: oneaxisservo.h:143
Spring(OneAxisJoint *joint, double _min, double _max, double power, double damp=0.2, double integration=0.0, double maxVel=10.0, double jointLimit=1.0)
Definition: spring.h:32
double max
Definition: oneaxisservo.h:149
double clip(double r, double x)
clipping function for mapP
Definition: controller_misc.cpp:39
const Primitive * getPart2() const
Definition: joint.h:69
double maxVel
Definition: oneaxisservo.h:151
double jointLimit
joint limit with respect to servo limit
Definition: oneaxisservo.h:152
double min
Definition: oneaxisservo.h:148
PID pid
Definition: oneaxisservo.h:150
void setTargetPosition(double newpos)
Definition: pid.cpp:54
virtual void setParam(int parameter, double value)=0
sets the ODE joint parameter (see ODE manual)
const Primitive * getPart1() const
Definition: joint.h:67
Definition: spring.h:30
double KP
Definition: pid.h:44
bool limitLinearVel(double maxVel)
checks whether the object has higher velocity than maxVel and limits it in case
Definition: primitive.cpp:245
general servo motor to achieve position control
Definition: oneaxisservo.h:38