/* ----------------------------------------------------------------- */ /* 'ZServoClass.cc' */ /* Servo- Functions */ /* */ /* last modified 07/04/2003 */ /* used to Initialize and Release Servos */ /* */ /* */ /* */ /* */ /* (C) Jochen Zimmermann */ /* ----------------------------------------------------------------- */ #include "ZHeaders.h" #include /* //Headerfile is included by ZHeaders.h #include "ZServoClass.h" */ //Single Instance is globally created Servo Servo::SingleInstance; //constructor //initialises members Servo::Servo() { limit[RHIPS]=35; limit[RHIPB]=127; limit[RKNEE]=127; limit[RANKB]=127; limit[RANKS]=30; limit[LHIPS]=35; limit[LHIPB]=127; limit[LKNEE]=127; limit[LANKB]=127; limit[LANKS]=30; for(int i=0;iPrint("Servos are not initialized!"); key->Wait(); return 0; } int i,j,k,counter=0,dist,togo,max=0; if( speed ==0) return 0; if( speed < 1) speed = 1; togo=speed; for (i=0;i128+limit[i]) pos[i] = 128+limit[i]; else if (pos[i]<128-limit[i]) pos[i] = 128-limit[i]; } //maximum distance to go for (i=0;imax ) max=abs(pos[i]-position[i]); } for(j=0;j0) SERVOSet(handle[i],position[i]++); if(togo<0) SERVOSet(handle[i],position[i]--); } for(k=0;k<((10-speed)*94);k++) OSWait(0); //consumes 10.66µs per call, so that 94*10.66µs consume approx. 1ms } return (max*(10-speed)*1000+60); } //retrieve actual servoangles void Servo::Get(int* pos) { if(position==NULL) return; for(int i=0;i0 && pos< NUMBEROFSERVOS) return 128+limit[ pos]; if(pos<0 && pos>-NUMBEROFSERVOS) return 128-limit[-pos]; else return -1; //error } //drive servos relative to actual position int Servo::Move(int* delta, int speed) { int ret=0; for(int i=0;i