After a week of searching...
I have built a robotic arm run by a Pi 3. It has 5 servos, as well as a stepper motor. I have code written see, (Pastebin). And I am not able to get each servo motor to move incrementally when the key press function is called. I can make the servos move to positions, but not move in between whenever I press the button.
Ideally the code would call a servo up function, and the servo would move up by increments of 20 every time the function is called.
This is the main focus:
def shoulder_up(): for spwm in range(1000, 2000, 20): pi.set_servo_pulsewidth(shoulderpin, spwm) time.sleep(0.4) pi.set_servo_pulsewidth(shoulderpin, 0)
When this is called, I need the servo to move a small increment to the left. This means closer to a 1000 pwm signal value. I cannot determine how to make it move the increment every time based on the previous movement. The code currently just moves the servo through the defined range.
I would like to try to use this, but I cannot get the variables to change.
def shoulder_up(): global spwm global nspwm spwm = nspwm pi.set_servo_pulsewidth(shoulderpin, spwm) nspwm = spwm + 20
Every time the loop runs, I want spwm to change and become 20 higher. For some reason I cant get it to change. It goes to 1520 every time.
Any help on this would be appreciated. Yes my code is in alpha, so it is messy and a little nonuniform.