[Robot Arm Control Project 4] 5-Joint Robot Arm Control Using Two Joysticks

· 2019-11-14 · 4
This practice exercise manufactures a robotic arm based on understanding servo motors, joysticks, and related components from previous robotic arm projects 1, 2, and 3. Materials: Arduino, 2 joysticks, 5 servo motors, battery, robotic arm frame Contents: Five servo motors are operated using analog input values from two joysticks. Additionally, the gripper can be moved through each joystick button. Since excessively fast gripping motion on the robotic arm can damage objects being held, different speeds were calculated for each motor. The circuit connections are as follows. The actual motors use servo motors that operate at 6~7V, so a separate power source was supplied rather than from the Arduino. In the Fritzing diagram, you can see that two power sources are connected to a single ground. For joystick 1 (left): X-axis → A0 (analog input pin) Y-axis → A1 (analog input pin) Z-axis → 12 (digital input pin) connected to the pins, and For joystick 2 (right): X-axis → A2 (analog input pin) Y-axis → A3 (analog input pin) Z-axis → 13 (digital input pin) connected to the pins. Additionally, the servo motor input/output pins were connected to pins 3, 5, 6, 9, and 10 from top to bottom. The code is as follows. ``` #include //header file inclusion Servo servo1; //variable declaration Servo servo2; Servo servo3; Servo servo4; Servo servo6; int motor1 = A0; // connected to Arduino A0 pin for controlling motor1 (rotation axis) int motor2 = A1; // connected to Arduino A1 pin for controlling motor2 (central vertical joint) int motor3 = A3; // connected to Arduino A3 pin for controlling motor3 (gripper vertical joint) int motor4 = A2; // connected to Arduino A2 pin for controlling motor4 (gripper horizontal rotation joint) int angle1, angle2, angle3, angle4, angle6; void setup() { // put your setup code here, to run once: servo1.attach(5); //motor controlling rotation axis => assigned to pin 5 servo1.write(90); servo2.attach(3); //motor controlling central vertical joint => assigned to pin 3 servo2.write(90); servo3.attach(6); //motor controlling gripper vertical joint => assigned to pin 6 servo3.write(90); servo4.attach(9); //motor controlling gripper horizontal rotation joint => assigned to pin 9 servo4.write(90); servo6.attach(10); //motor controlling gripper => assigned to pin 10 pinMode(12,INPUT); //digital input/output pin 12 assigned for left joystick pinMode(13,INPUT); //digital input/output pin 13 assigned for right joystick servo6.write(90); } void loop() { if ((analogRead(motor1) <= 450) && (analogRead(motor1) >= 0)) //to prevent unintended joystick input, the joystick analog input value range is excluded up to -50 from the center value { angle1 = angle1 - ((analogRead(motor1) - 500)/50 ); //appropriate speed value derived through experimentation to control the robotic arm rotation speed if (angle1 <= 0) { angle1 = 0; } servo1.write(angle1); } else if((analogRead(motor1) >= 600) && (analogRead(motor1) <= 1023)) //to prevent unintended joystick input, the joystick analog input value range is excluded up to +100 from the center value { angle1 = angle1 + ((500 - analogRead(motor1))/50 ); if (angle1 >= 180) { angle1 = 180; } servo1.write(angle1); } delay(15); if ((analogRead(motor2) <= 450) && (analogRead(motor2) >= 0)) { angle2 = angle2 + ((500 - analogRead(motor2))/150 ); //for motor2 controlling the central joint, the speed is reduced compared to other motors because fast speed makes control difficult when gripping objects if (angle2 >= 180) { angle2 = 180; } servo2.write(angle2); } else if((analogRead(motor2) >= 600) && (analogRead(motor2) <= 1023)) { angle2 = angle2 - ((analogRead(motor2) - 500)/150 ); if (angle2 <= 0) { angle2 = 0; } servo2.write(angle2); } delay(15); if ((analogRead(motor3) <= 450) && (analogRead(motor3) >= 0)) { angle3 = angle3 + ((500 - analogRead(motor3))/50 ); if (angle3 >= 170) { angle3 = 170; } servo3.write(angle3); } else if((analogRead(motor3) >= 600) && (analogRead(motor3) <= 1023)) { angle3 = angle3 - ((analogRead(motor3) - 500)/50 ); if (angle3 <= 0) { angle3 = 0; } servo3.write(angle3); } delay(15); if ((analogRead(motor4) <= 450) && (analogRead(motor4) >= 0)) { angle4 = angle4 - ((analogRead(motor4) - 500)/50); if (angle4 <= 0) { angle4 = 0; } servo4.write(angle4); } else if((analogRead(motor4) >= 600) && (analogRead(motor4) <= 1023)) { angle4 = angle4 + ((500 - analogRead(motor4))/50 ); if (angle4 >= 170) { angle4 = 170; } servo4.write(angle4); } delay(15); if(digitalRead(12) == LOW)angle6 ++; //when left joystick is pressed, the gripper grasps the object if(digitalRead(13) == LOW)angle6 --; //when right joystick is pressed, the gripper releases the object if(angle6 <= 0) angle6 = 0; if(angle6 >= 180) angle6 = 180; servo6.write(angle6); delay(15); } ``` **During coding, there were mistakes where the robotic arm was damaged frequently while testing to determine the servo motor speed values. For those learning from this article, instead of testing with fast speed initially, I recommend gradually increasing the speed starting from low speed. Additionally, if the gripper part of the robotic arm is made heavy, the servo motor controlling the central joint must be powerful. I recommend programming and designing while considering these points.** Operation video
4
댓글 2
  • 여기다 질문 하셔도 됩니다. 제가 안는것까지 답변 드리겠습니다 ^^
  • 여기다 질문 하셔도 됩니다. 제가 안는것까지 답변 드리겠습니다 ^^