Arduino Forum

Forum 2005-2010 (read only) => Software => Troubleshooting => Topic started by: lord-maricek on Jul 16, 2010, 11:17 am

Title: Servo is moving to the wrong position
Post by: lord-maricek on 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]
108
108
108
108
108
108
108
108
110
110
110
110
108
108
108
114
108
111
110
110
110
110
110
108
111
108
108
108
108
108
108
108
108
108
113
110
110
110
110
108
108
108
108
114
111
110
110
110
110
110
108
111
108
114

But why is the servo doing this?
Can somebody please help me?

Greetings
Philipp