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 #include "schlangeservo2.h"
00033
00034 namespace lpzrobots {
00035
00036 SchlangeServo2::SchlangeServo2 ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00037 const SchlangeConf& conf, const char* n)
00038 : Schlange(odeHandle, osgHandle, conf, n)
00039 {
00040
00041
00042 Configurable::insertCVSInfo(name, "$RCSfile: schlangeservo2.cpp,v $",
00043 "$Revision: 1.1.2.2 $");
00044 }
00045
00046 SchlangeServo2::~SchlangeServo2() { }
00047
00048
00049
00050
00051
00052
00053
00054
00055 void SchlangeServo2::setMotors ( const motor* motors, int motornumber )
00056 {
00057 assert(created);
00058 int len = min(motornumber, getMotorNumber())/2;
00059
00060 for (int i = 0; i < len; i++){
00061 servos[i]->set(motors[2*i], motors[2*i+1]);
00062 }
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072 int SchlangeServo2::getSensors ( sensor* sensors, int sensornumber )
00073 {
00074 assert(created);
00075 int len = min(sensornumber, getSensorNumber())/2;
00076
00077 for (int n = 0; n < len; n++) {
00078 sensors[2*n] = servos[n]->get1();
00079 sensors[2*n+1] = servos[n]->get2();
00080 }
00081
00082 return 2*len;
00083 }
00084
00085
00086
00087
00088
00089 void SchlangeServo2::create(const osg::Matrix& pose){
00090 Schlange::create(pose);
00091
00092
00093 for ( int n = 0; n < conf.segmNumber-1; n++ ) {
00094
00095 const Pos& p1(objects[n]->getPosition());
00096 const Pos& p2(objects[n+1]->getPosition());
00097 UniversalJoint* j = new UniversalJoint(objects[n], objects[n+1],
00098 (p1 + p2)/2,
00099 Axis(0,0,1)* pose, Axis(0,1,0)* pose);
00100 j->init(odeHandle, osgHandle, true, conf.segmDia * 1.02);
00101
00102
00103 j->setParam(dParamLoStop, -conf.jointLimit*1.5);
00104 j->setParam(dParamHiStop, conf.jointLimit*1.5);
00105
00106
00107
00108
00109
00110 joints.push_back(j);
00111
00112 UniversalServo* servo = new UniversalServo(j, -conf.jointLimit, conf.jointLimit, conf.motorPower,
00113 -conf.jointLimit, conf.jointLimit, conf.motorPower);
00114 servos.push_back(servo);
00115
00116 frictionmotors.push_back(new AngularMotor2Axis(odeHandle, j,
00117 conf.frictionJoint, conf.frictionJoint)
00118 );
00119 }
00120 }
00121
00122
00123 bool SchlangeServo2::setParam(const paramkey& key, paramval val){
00124 bool rv = Schlange::setParam(key, val);
00125 for (vector<UniversalServo*>::iterator i = servos.begin(); i!= servos.end(); i++){
00126 if(*i) (*i)->setPower(conf.motorPower, conf.motorPower);
00127 }
00128 return rv;
00129 }
00130
00131
00132
00133
00134 void SchlangeServo2::destroy(){
00135 if (created){
00136 Schlange::destroy();
00137 for (vector<UniversalServo*>::iterator i = servos.begin(); i!= servos.end(); i++){
00138 if(*i) delete *i;
00139 }
00140 servos.clear();
00141 }
00142 }
00143
00144 }