00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "schlangeservo.h"
00048
00049 namespace lpzrobots {
00050
00051 SchlangeServo::SchlangeServo ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00052 const SchlangeConf& conf, const char* n)
00053 : Schlange(odeHandle, osgHandle, conf, n)
00054 {
00055
00056
00057 Configurable::insertCVSInfo(name, "$RCSfile: schlangeservo.cpp,v $",
00058 "$Revision: 1.5.4.6 $");
00059 }
00060
00061 SchlangeServo::~SchlangeServo() { }
00062
00063
00064
00065
00066
00067
00068
00069
00070 void SchlangeServo::setMotors ( const motor* motors, int motornumber )
00071 {
00072 assert(created);
00073 int len = min(motornumber, (int)servos.size());
00074
00075 for (int i = 0; i < len; i++){
00076 servos[i]->set(motors[i]);
00077 }
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087 int SchlangeServo::getSensors ( sensor* sensors, int sensornumber )
00088 {
00089 assert(created);
00090 int len = min(sensornumber, getSensorNumber());
00091
00092 for (int n = 0; n < len; n++) {
00093 sensors[n] = servos[n]->get();
00094 }
00095
00096 return len;
00097 }
00098
00099
00100
00101
00102
00103 void SchlangeServo::create(const osg::Matrix& pose){
00104 Schlange::create(pose);
00105
00106
00107 for ( int n = 0; n < conf.segmNumber-1; n++ ) {
00108
00109 Pos p1(objects[n]->getPosition());
00110 Pos p2(objects[n]->getPosition());
00111 HingeJoint* j = new HingeJoint(objects[n], objects[n+1],
00112 (objects[n]->getPosition() + objects[n+1]->getPosition())/2,
00113 Axis(0,0,1)* pose);
00114 j->init(odeHandle, osgHandle, true, conf.segmDia * 1.02);
00115
00116
00117 j->setParam(dParamLoStop, -conf.jointLimit*1.5);
00118 j->setParam(dParamHiStop, conf.jointLimit*1.5);
00119
00120
00121
00122
00123
00124 joints.push_back(j);
00125
00126 HingeServo* servo = new HingeServo(j, -conf.jointLimit, conf.jointLimit, conf.motorPower);
00127 servos.push_back(servo);
00128
00129 frictionmotors.push_back(new AngularMotor1Axis(odeHandle, j, conf.frictionJoint) );
00130 }
00131 }
00132
00133 bool SchlangeServo::setParam(const paramkey& key, paramval val){
00134 bool rv = Schlange::setParam(key, val);
00135 for (vector<HingeServo*>::iterator i = servos.begin(); i!= servos.end(); i++){
00136 if(*i) (*i)->setPower(conf.motorPower);
00137 }
00138 return rv;
00139 }
00140
00141
00142
00143
00144 void SchlangeServo::destroy(){
00145 if (created){
00146 Schlange::destroy();
00147 for (vector<HingeServo*>::iterator i = servos.begin(); i!= servos.end(); i++){
00148 if(*i) delete *i;
00149 }
00150 servos.clear();
00151 }
00152 }
00153
00154 }