spring.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef SPRING_H_
00014 #define SPRING_H_
00015
00016
00017 #include <ode_robots/joint.h>
00018 #include <ode_robots/oneaxisservo.h>
00019 #include <ode_robots/pid.h>
00020 #include <ode_robots/angularmotor.h>
00021 #include <selforg/controller_misc.h>
00022
00023 namespace lpzrobots {
00024
00025
00026
00027
00028
00029
00030 class Spring : public OneAxisServo{
00031 public:
00032 Spring(OneAxisJoint* joint, double _min, double _max,
00033 double power, double damp=0.2, double integration=0.0,
00034 double maxVel=10.0, double jointLimit = 1.0)
00035 : OneAxisServo(joint, _min, _max, power, damp, integration, maxVel, jointLimit, false){
00036 }
00037 virtual ~Spring(){}
00038
00039
00040
00041
00042
00043 virtual void set(double pos){
00044 pid.setTargetPosition(pos);
00045
00046 double force = pid.stepNoCutoff(joint->getPosition1(), joint->odeHandle.getTime());
00047 force = clip(force,-10*pid.KP, 10*pid.KP);
00048 joint->addForce1(force);
00049 if(maxVel>0){
00050 joint->getPart1()->limitLinearVel(maxVel);
00051 joint->getPart2()->limitLinearVel(maxVel);
00052 }
00053 }
00054
00055
00056 virtual double get(){
00057 double pos = joint->getPosition1();
00058 return pos;
00059 }
00060
00061
00062 virtual void setMinMax(double _min, double _max){
00063 min=_min;
00064 max=_max;
00065 joint->setParam(dParamLoStop, min - fabs(min) * (jointLimit-1));
00066 joint->setParam(dParamHiStop, max + fabs(max) * (jointLimit-1));
00067 }
00068
00069 };
00070
00071 }
00072
00073 #endif