Hi everyone, i have a really big servo connected to its own power supply then an arduino nano communicating with it. Its controlled by a gyro sensor but the servo is really glitchy. I have a hunch that its due to unregulated voltage but I want to try something first. When I slow down the servo movement with just a simple delay it works but its choppy. Ive been trying to figure out some code to put a proper delay in but I have had no luck. Ive tried a for function but my problem is I am getting readings from a gyro that I have in the variable value so how do I write the for function the proper way. ill give n example of some code below. When I run this the servo just sweeps back and forth. I dont know how to program the for function to have a delay on the servo as it goes to the gyros position. Much help needed. Thankyou.
#ifdef OUTPUT_READABLE_YAWPITCHROLL
// display Euler angles in degrees
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
value = (180 - (90 + ypr[2] * 180 / M_PI));
int pos = 0;
for (pos = 0; pos <= value; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 0; pos >= value; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
Serial.print("Roll \t");
Serial.println(value);
#endif
}
}
Thank you for our time and effort.