Hello Everyone,
I am currently an undergraduate student working on a summer research project, and I have a question about controlling the angular position of a servo motor using a servo drive and an Arduino Uno (In particular, the servo motor is a Leadshine BLM57050 and the servo drive is a Leadshine ACS306).
Currently, I am able to run the servo motor with an Arduino Uno using the following code,
int PUL_pin = 6; //Declaration of the PUL signal control pin as pin 8
int DIR_pin = 9; //Declaration of the DIR signal control pin as pin 9
void setup() {
//Setup code to run once:
pinMode(PUL_pin, OUTPUT);
pinMode(DIR_pin, OUTPUT);
}
void loop() {
digitalWrite(PUL_pin, LOW);
delayMicroseconds(1000);
digitalWrite(PUL_pin, HIGH);
digitalWrite(DIR_pin, HIGH);
}
However, this code will continuously run the servo motor and provides no positional control.
I was wondering, how would I be able to code the Arduino such that it allows for angular position control of the servo motor?
As of know, I know that 4000 pulse signals (PUL signals) allow for one complete rotation of the servo motor, and there is an associated linear function where based upon an input of the angular position of the servo motor, the output will be the amount of PUL signals needed to reach the specified angular position of the servo.
To control the amount of PUL signals sent to the servo drive would I have to insert a for loop within the void loop() function?
As of now, I am under the belief that the void loop() function runs continuously, which results in PUL signals being continuously sent to the servo drive (which results in the continuous motion of the servo motor). Is this a correct assumption? Is there any way for me to set this loop such that it only runs for a specified amount of iterations rather than continuously?
Any help is greatly appreciated. Thanks!