Welcome to DOFBOT SE repository
18.Finger Control Robot Arm
Finger Control Robotic Arm
1. Introduction
The finger control robotic arm function is based on finger control, with the added capability of controlling the robotic arm's vertical movement.
2. Finger Control
Press the [F key] to switch recognition effects. Through the distance between the thumb and index finger (open/close), you can control the image effect.
2.1. Startup
- Enter the following command to start the program
xxxxxxxxxxros2 run dofbot_mediapipe 18_HandCtrlArm

Now place your fingers in the camera frame. The current finger open/close percentage will be displayed. When the percentage is less than 40, the robotic arm moves downward. When the percentage is greater than 50, the robotic arm moves upward.
Press Ctrl+c in the terminal to exit the program.
2.2. Source Code
Source code location:
xxxxxxxxxx/home/yahboom/dofbot_ws/src/dofbot_mediapipe/dofbot_mediapipe/18_HandCtrlArm.py
x#!/usr/bin/env python3# encoding: utf-8import mathimport timeimport cv2 as cvimport numpy as npimport mediapipe as mpimport rclpyfrom rclpy.node import Nodefrom Arm_Lib import Arm_Devicefrom threading import Threadclass HandDetector: def __init__(self, mode=False, maxHands=2, detectorCon=0.5, trackCon=0.5): self.tipIds = [4, 8, 12, 16, 20] self.mpHand = mp.solutions.hands self.mpDraw = mp.solutions.drawing_utils self.hands = self.mpHand.Hands( static_image_mode=mode, max_num_hands=maxHands, min_detection_confidence=detectorCon, min_tracking_confidence=trackCon ) self.lmDrawSpec = mp.solutions.drawing_utils.DrawingSpec(color=(0, 0, 255), thickness=-1, circle_radius=15) self.drawSpec = mp.solutions.drawing_utils.DrawingSpec(color=(0, 255, 0), thickness=10, circle_radius=10) def get_dist(self, point1, point2): x1, y1 = point1 x2, y2 = point2 return abs(math.sqrt(math.pow(abs(y1 - y2), 2) + math.pow(abs(x1 - x2), 2))) def calc_angle(self, pt1, pt2, pt3): point1 = self.lmList[pt1][1], self.lmList[pt1][2] point2 = self.lmList[pt2][1], self.lmList[pt2][2] point3 = self.lmList[pt3][1], self.lmList[pt3][2] a = self.get_dist(point1, point2) b = self.get_dist(point2, point3) c = self.get_dist(