Go Down

### Topic: Servo is moving to the wrong position (Read 758 times)previous topic - next topic

#### lord-maricek

##### Jul 16, 2010, 11:17 am
Hi,

for my autopilot project, I want to let a servo go to a calculated position. But when I do this, the servo is moving to the 180 degrees positon and then back to the calculated positon.This happends each secound.
Code: [Select]
`while(!wp1){    get_gps();    get_mh();    calc.get_nwp_info(flat,flon,wpk1[0],wpk1[1],&distance,&qdm);    new_servo_pos = calc.get_servo_pos((float)mh,qdm);    se.write(new_servo_pos);    delay(15);    if(distance<1.0){      wp1=true;    }    if(millis()>=time+2000){      Serial.print("Welcher Wegpunkt: ");Serial.println("WP1");      Serial.print("Start Lat: ");printFloat(flat,5);Serial.println("");      Serial.print("Ziel Lat: ");printFloat(wpk1[0],5);Serial.println("");      Serial.print("Lon: ");printFloat(flon,5);Serial.println("");      Serial.print("Ziel Lon: ");printFloat(wpk1[1],5);Serial.println("");      Serial.print("MH: ");Serial.println(mh);      Serial.print("QDM: ");Serial.println(qdm);      Serial.print("Servo: ");Serial.println(new_servo_pos);      Serial.print("Fahrtregler: ");Serial.println(fahrt.read());      Serial.print("Distance: ");Serial.println(distance);      Serial.println("_______________________________________");      time = millis();    }    Serial.println(se.read());  }`
This is the code from the project. I tried it at PWM, analog and normal ports. I used to Serial function to give out the data, and it's normal, in the variable I am saving the servo position is only the number the servo has to go to. Here is a part of it:
Code: [Select]
`108108108108108108108108110110110110108108108114108111110110110110110108111108108108108108108108108108113110110110110108108108108114111110110110110110108111108114`
But why is the servo doing this?