Hi All,
Extremely new to robot programming, so I appreciate your kind help.
I'm currently working with a complete DIY robot project. I've assembled the robot using 5 DOF: waist, elbow, wrist elevation, wrist rotation and gripper. I am working with an Arduino Uno with a DFRobot I/O Expansion Shield V7.1 to connect my 5 DS3218MG servos.
I'm just experimenting with a simple code to learn the basics -- which I've posted below. What I would like help with is in the void setup, I set initial servo positions. Then I go into a simple routine, exercising the joints in a for loop.
The issue I'm experiencing is that when it loops back to the void setup locations, the speed appears to be at a super max speed. It's too fast and I would like a gentle speed like I have in the void loop. I tried adding delays and creating a return speed variable to set. But to no avail.
How can I slow down the void setup servo speed upon return?
Thanks in advance!
[code]
#include <Servo.h>
Servo myservoA;
Servo myservoC;
Servo myservoD;
Servo myservoE;
Servo myservoF;
int i, pos, myspeed, returnspeed;
void setup()
{
// Attach each servo to a specific pin
myservoA.attach(10); // Waist servo at port 10
myservoC.attach(9); // Elbow servo at port 9
myservoD.attach(6); // Wrist elevation servo at port 6
myservoE.attach(5); // Wrist rotation servo at port 5
myservoF.attach(3); // Gripper servo at port 3
returnspeed = 1500;
// Position the waist in the center
myservoA.write(90);
// Position elbow to a higher angle for better arm balance
myservoC.write(140);
// Position the wrist elevation in the center
myservoD.write(90);
// Position the wrist rotation in the center
myservoE.write(90);
// Default to a wide open gripper
myservoF.write(30);
}
void loop()
{
delay(3000);
myspeed = 1500;
for (pos = 0; pos <= myspeed; pos += 1)
{
myservoA.write(int(map(pos, 1, myspeed, 90, 45)));
myservoC.write(int(map(pos, 1, myspeed, 140, 90)));
myservoD.write(int(map(pos, 1, myspeed, 90, 135)));
myservoE.write(int(map(pos, 1, myspeed, 90, 0)));
myservoF.write(int(map(pos, 1, myspeed, 30, 90)));
delay(1);
}
}
[/code]