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