Hello people. Im gonna ask how can ı fix my problem. I want to do robotic hand imitating hand gestures with web camera. I use 10 servos in my project. Hand gestures will be detected by raspberry pi 4 via python. Python code detect hand gestures and deliver to arduino uno after uno controls servo motors. My problem is servos wont work properly. I down my İndex finger but my robotic hand downs ring finger and motors working very slow. Maybe algorithm axis the problem ? I cant solve it. I tried with arduino mega 2560. This time nothing works but arduino uno working loose.
My code here;
#include <Servo.h>
#define numOfValsRec 10
#define digitsPerValRec 1
Servo servoThumb;
Servo servoIndex;
Servo servoMiddle;
Servo servoRing;
Servo servoPinky;
Servo servoPrf;
Servo servoAsena;
Servo servoSelcuk;
Servo servoIrfan;
Servo servoOnur;
int valsRec[numOfValsRec];
int stringLength = numOfValsRec * digitsPerValRec + 1; //$00000
int counter = 0;
bool counterStart = false;
String receivedString;
void setup() {
Serial.begin(9600);
servoThumb.attach(6);
servoIndex.attach(9);
servoMiddle.attach(11);
servoRing.attach(5);
servoPinky.attach(10);
servoPrf.attach(3);
servoAsena.attach(7);
servoSelcuk.attach(4);
servoIrfan.attach(8);
servoOnur.attach(12);
}
void receieveData() {
while (Serial.available())
{
char c = Serial.read();
if (c == '$') {
counterStart = true;
}
if (counterStart) {
if (counter < stringLength) {
receivedString = String(receivedString + c);
counter++;
}
if (counter >= stringLength) {
//$00000
for (int i = 0; i < numOfValsRec; i++)
{
int num = (i * digitsPerValRec) + 1;
valsRec[i] = receivedString.substring(num, num + digitsPerValRec ).toInt();
}
receivedString = "";
counter = 0;
counterStart = false;
}
}
}
}
void loop() {
receieveData();
if (valsRec[0]==1){servoThumb.write(180);}else{servoThumb.write(0);}
if (valsRec[1]==1){servoIndex.write(180);}else{servoIndex.write(0);}
if (valsRec[2]==1){servoMiddle.write(180);}else{servoMiddle.write(0);}
if (valsRec[3]==1){servoRing.write(180);}else{servoRing.write(0);}
if (valsRec[4]==1){servoPinky.write(180);}else{servoPinky.write(0);}
if (valsRec[5]==1){servoPrf.write(180);}else{servoPrf.write(0);}
if (valsRec[6]==1){servoAsena.write(180);}else{servoAsena.write(0);}
if (valsRec[7]==1){servoSelcuk.write(180);}else{servoSelcuk.write(0);}
if (valsRec[8]==1){servoIrfan.write(180);}else{servoIrfan.write(0);}
if (valsRec[9]==1){servoOnur.write(180);}else{servoOnur.write(0);}
}
Here is the python code;
import cvzone.SerialModule
from cvzone.HandTrackingModule \
import HandDetector
import cv2
cap = cv2.VideoCapture(0)
detector = HandDetector(detectionCon=0.3, maxHands=2)
mySerial = cvzone.SerialModule.SerialObject('/dev/ttyUSB0',19200,1)
while True:
# Get image frame
success, img = cap.read()
# Find the hand and its landmarks
hands, img = detector.findHands(img) # with draw
# hands = detector.findHands(img, draw=False) # without draw
if hands:
# Hand 1
hand1 = hands[0]
lmList1 = hand1["lmList"] # List of 21 Landmark points
bbox1 = hand1["bbox"] # Bounding box info x,y,w,h
centerPoint1 = hand1['center'] # center of the hand cx,cy
handType1 = hand1["type"] # Handtype Left or Right
fingers1 = detector.fingersUp(hand1)
mySerial.sendData(fingers1)
if len(hands) == 2:
# Hand 2
hand2 = hands[1]
lmList2 = hand2["lmList"] # List of 21 Landmark points
bbox2 = hand2["bbox"] # Bounding box info x,y,w,h
centerPoint2 = hand2['center'] # center of the hand cx,cy
handType2 = hand2["type"] # Hand Type "Left" or "Right"
fingers2 = detector.fingersUp(hand2)
# Display
cv2.imshow("Image", img)
cv2.waitKey(1)
cap.release()
cv2.destroyAllWindows()
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.