yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
DOFBOT SE📖
1.First Trial
  • 1.First Trial
  • 2.Analysis of common problems
  • 3.Calibration offset
  • 4.Precautions for DIY Robotic Arm
  • 5.Robotic arm gripping anomaly solutions
2.Assembly Course
  • 1.Installation video
  • 2.Calibrate the Robotic Arm
  • 3.Install the map
3.Remote Control Course
  • 1.Mobile APP control
  • 2.USB handle control
  • 3.PC software control
4.Preparation
  • 1.Manage APP control service
  • 2.Manage JupyterLab service
  • 3.Write STM32 firmware
  • 4.Introduction to expansion board
5.Basic Control Course
  • 1.Control RGB light
  • 2.Control buzzer
  • 3.Control single servo
  • 4.Read servo angle
  • 5.Control all servo
  • 6.DOFBOT up down left right
  • 7.DOFBOT dancing
  • 8.DOFBOT memory action
  • 9.DOFBOT grab block
  • 10.Porter
  • 11.Stack block
  • 12.USB camera display
  • 13.Synchronous action
6.AI Vision Basic Course
  • 1.Gesture Recognition
  • 2.Color threshold adjustment Color calibration
  • 3.Color recognition
  • 4.Face recognition
  • 5.Garbage recognition
  • 6.Yolo object recognition
  • 7.Real-time web view
7.2D Visual Tracking Course
  • 1.PID algorithm basics
  • 2.Color block positioning
  • 3.Color block tracking
  • 4.Face positioning
  • 5.Face tracking
  • 6.Gesture recognition fixed action
8.2D Visual Grasping Course
  • 0.Visual positioning
  • 1.Gesture recognition stack blocks
  • 2.Color recognition grab blocks
  • 3.Catch game
  • 4.Color sorting and stacking
  • 5.Garbage sorting
  • 6.Color interaction
9.2D Mediapipe Course
  • 1.Hand detection
  • 2.Posture detection
  • 3.Overall inspection
  • 4.Face detection
  • 5.Face recognition
  • 6.Face effects
  • 7.3D object recognition
  • 8.Paintbrush
  • 9.Finger control
  • 10.Gesture recognition
  • 11.Gesture control robotic arm action group
  • 12.Arm posture control robotic arm
  • 13.Palm Targeting
  • 14.Robotic arm tracks the palm
  • 15.Fingertip trajectory recognition
  • 16.Fingertip trajectory control robotic arm
  • 17.Gesture Grasp and Release Objects
  • 18.Finger Control Robot Arm
10.AI Large Model Voice Module (Must Read)
  • 1. Introduction to AI Large Model Voice Module
  • 2. Flash the firmware (Must read)
  • 3. Modify the wake-up word and command word
11.2D Voice Control Course
  • 1.Simple Voice Control
  • 2.Smart Voice Control
  • 3.Voice Action Control
  • 4.Memory Learning Mode
  • 5.Color Recognition with Voice Broadcast
  • 6.Color Recognition and Grasping with Voice Broadcast
  • 7.Color Recognition and Sorting with Voice Broadcast
  • 8.Voice Recognition Target Tracking
  • 9.Voice Control Stacking
  • 10.Voice Control Color Sorting
  • 11.Garbage Recognition with Voice Broadcast
  • 12.Garbage Sorting with Voice Broadcast
12.Robotic Arm Control and Inverse Kinematics
  • 1. Robotic arm ROS control
  • 2. Inverse solution
13.3D Sorting and Grasping Course
  • 1.AprilTag ID sorting
  • 2.MediaPipe Gesture-AprilTag ID sorting
  • 3.MediaPipe Gesture-AprilTag distance sorting
  • 4.Block color sorting
  • 5.Block different shape sorting
  • 6.Yolov11 garbage sorting
14.3D Tracking Course
  • 1.AprilTag Tracking
  • 2.Color Block Tracking
  • 3.KCF Object Tracking
15.3D Voice Control for Sorting & Tracking Course
  • 1.Voice Control AprilTag ID Sorting
  • 2.Voice Control Color Block Sorting
  • 3.Voice Control Yolov11 Garbage Recognition Sorting
  • 4.Voice Control AprilTag Tracking
  • 5.Voice Control Color Block Tracking
  • 6.Voice Control Object Tracking
16.AI Model Basics
  • 1.AI large model types and principles
  • 2.RAG retrieval enhancement and model training samples
  • 3.Embodied intelligent robot system architecture
  • 4.Embodied intelligent functions core source code
17.AI Model Development
  • 1. Register a model service provider account
  • 2. Configure API-KEY
  • 3. Introduction to Dify
  • 4. Basic Dify Features
  • 5. AI Large Model Development - chatbot
  • 6. Deploy the RAG knowledge base
  • 7. RAG knowledge base + chatbot
  • 8. AI agent workflow
18.AI Model – Text Version
  • 1.Semantic understand instruction following
  • 2.Multimodal visual understand
  • 3.Text Large Model + robotic arm control
  • 4.Multimodal Large Model+video understanding
  • 5.Multimodal Large Model+robotic arm gripping
  • 6.Multimodal Large Model+robotic arm tracking
  • 7.Multimodal Large Model+robotic arm sorting
  • 8.Multimodal Large Model+robotic arm handling
  • 9.Multimodal Large Model+Color Blocks Back In Place
  • 10.Multimodal Large Model + Intent Prediction + Robotic Arm Gripping
  • 11.Text Large Model + YOLOv11 + Intelligent Garbage Classification
19.AI Model – Voice Version
  • 1.Semantic understand instruction following
  • 2.Multimodal visual understand
  • 3.Text Large Model + robotic arm control
  • 4.Multimodal Large Model+video understanding
  • 5.Multimodal Large Model+robotic arm gripping
  • 6.Multimodal Large Model+robotic arm tracking
  • 7.Multimodal Large Model+robotic arm sorting
  • 8.Multimodal Large Model+robotic arm handling
  • 9.Multimodal Large Model+Color Blocks Back In Place
  • 10.Multimodal Large Model + Intent Prediction + Robotic Arm Gripping
  • 11.Text Large Model + YOLOv11 + Intelligent Garbage Classification
20.AI Model – Fun Applications
  • 1.AI Butler-Intent Inference
  • 2.AI Encyclopedia-Arithmetic Master
  • 3.AI Encyclopedia-You asked I Pointed
  • 4.AI Encyclopedia-Nutritional Analysis
  • 5.AI Encyclopedia-Problem Solving Expert
  • 6.AI Encyclopedia-English Spelling
  • 7.AI Butler-Garbage Sorting
  • 8.AI Top Chef
21.MoveIt2 Course
  • 1. MoveIt Configuration
  • 2. MoveIt Usage
  • 3. MoveIt Drive Real Robot
  • 4. MoveIt Random Movement
  • 5. MoveIt Forward Kinematics Design
  • 6. MoveIt Inverse Kinematics Design
  • 7. MoveIt Cartesian Path
  • 8. MoveIt Scene Design
  • 9. MoveIt Trajectory Planning
  • 10. MoveIt Collision Detection
22.YOLOv11 Development Course
  • 1. YOLO Environment Setup
  • 2. CLI Usage
  • 3. Object Detection
  • 4. Instance Segmentation
  • 5. Pose Estimation
  • 6. Image Classification
  • 7. Oriented Bounding Boxes Object Detection
  • 8. Model Conversion
  • 9. Model Prediction
23. Linux Operating System
  • 1.Introduction to Linux system
  • 2.Ubuntu file system
  • 3.Ubuntu common commands
  • 4.Ubuntu common editors
  • 5.Ubuntu software operation commands
  • 6.Virtual machine installation
  • 7.SSH remote control
  • 8.VNC remote control
  • 9.Transfer files remotely
  • 10.Driver library and communication
  • 11.Static IP and hotspot mode
  • 12.Bind device ID
  • 13.Capacity expansion and resource allocation
  • 14.Update system software sources
  • 15.Set root user password
  • 16.sudo free password
  • 17.Connect to WiFi network
  • 18.View system version
  • 19.Customized service management
  • 20.Back up system image
24.OpenCV Course
  • 1.Introduction to Open Source CV
  • 2.Image reading and display
  • 3.Picture writing
  • 4.Image Quality
  • 5.Pixel operations
  • 6.Image zoom
  • 7.Picture cut
  • 8.Picture pan
  • 9.Picture mirroring
  • 10.Affine transformation
  • 11.Picture rotation
  • 12.perspective transformation
  • 13.Grayscale processing
  • 14.Binary image
  • 15.Edge green detection
  • 16.Line segment drawing
  • 17.Rectangular circle drawing
  • 18.Text and picture drawing
25.Advanced Visuals Course
  • 1. QR Code
  • 2. Human Pose Estimation
  • 3. Object Detection
  • 4. AR Vision
  • 5. ROS + OpenCV Basics
26.ROS2 Basic Course
  • 1.Introduction to ROS2
  • 2.ROS2 install Humble
  • 3.ROS2 development environment
  • 4.ROS2 workspace
  • 5.ROS2 function package
  • 6.ROS2 node
  • 7.ROS2 topic communication
  • 8.ROS2 service communication
  • 9.ROS2 action communication
  • 10.ROS2 custom interface message
  • 11.ROS2 parameter service case
  • 12.ROS2 meta-function package
  • 13.ROS2 distributed communication
  • 14.ROS2 DDS
  • 15.ROS2 time related API
  • 16.ROS2 common command tools
  • 17.ROS2 rviz2 use
  • 18.ROS2 rqt toolbox
  • 19.ROS2 Launch startup file configuration
  • 20.ROS2 recording and playback tool
  • 21.ROS2 URDF model
  • 22.ROS2 Gazebo simulation platform
  • 23.ROS2 TF2 coordinate transformation
27.Jupyter Lab Usage Course
  • 0.Read the document before operation
  • 1.Jupyter Lab environment construction
  • 2.Basic use of Jupyter Widgets
  • 3.Launch JupyterLab
  • 4.How to Use JupyterLab
Download
  • APP(iOS/Android)
  • VM File
  • Instruction manual
  • Hardware_3DModelFile
  • PC_Software
  • Code
  • Communication Protocol-Python Library
  • Tools
Download ZIP

Welcome to DOFBOT SE repository

0.Visual positioning

Visual Positioning

This section contains theoretical knowledge. It is not a standalone gameplay mode, but a prerequisite and theoretical foundation for learning courses [7. Color Sorting and Stacking] and [8. Garbage Sorting].

xxxxxxxxxx
#Run the gameplay
dofbot_ws/src/dofbot_color_identify/scripts/颜色分拣color_sort.ipynb
#Or
dofbot_ws/src/dofbot_color_stacking/scripts/颜色堆叠color stacking play.ipynb
#You can see the following example images

Frame Calibration

The purpose of calibration is to convert the position of the object's center in the field of view to the actual distance from the robotic arm's base coordinate position.

  • Example image

image-20240509183450030

  • Operation process

(1) After starting all code blocks, the interface is displayed at the bottom of the code. Click the [calibration_model] button to enter calibration mode. Then you can adjust the slider.

(2) Adjust the slider so that the frame completely appears in the field of view and the edges of the frame are fully detected. Slider [joint1] controls servo 1 for left-right adjustment, slider [joint2] controls servo 2 for up-down adjustment, slider [threshold] adjusts the image edge binarization detection threshold. Note: The four edges of the frame must be clearly identified without external interference.

(3) Click the [calibration_ok] button to complete calibration. At the same time, the adjusted parameters will be written to the configuration file. When starting next time, if there are no issues, no adjustment is needed - just click calibrate and confirm.

(4) At this point, calibration is complete, as shown in the figure below. If an error occurs during calibration, click the [calibration_cancel] button to cancel the calibration result, then recalibrate.

image-20240509183537493

  • Code design

Image processing, extracting contour points

xxxxxxxxxx
# Convert image to grayscale
gray = cv.cvtColor(self.image, cv.COLOR_BGR2GRAY)
# Use Gaussian blur on the image
gray = cv.GaussianBlur(gray, (5, 5), 1)
# Image binarization operation
ref, threshold = cv.threshold(gray, self.threshold_num, 255,
cv.THRESH_BINARY)
# Get structuring elements of different shapes
kernel = np.ones((3, 3), np.uint8)
# Morphological opening operation
blur = cv.morphologyEx(threshold, cv.MORPH_OPEN, kernel, iterations=4)
# Extraction mode
mode = cv.RETR_EXTERNAL
# Extraction method
method = cv.CHAIN_APPROX_NONE
# Get contour point set (coordinates) - slight difference between python2 and python3
# Hierarchical relationship
# Parameter 1: Input binary image, Parameter 2: extraction mode, Parameter 3: extraction method
contours, hierarchy = cv.findContours(blur, mode, method)

Draw contours, return edge points of contours

xxxxxxxxxx
# Traverse point set
for i, c in enumerate(contours):
# Calculate contour area
area = cv.contourArea(c)
# Set contour area range
if h * w / 2 < area < h * w:
# Calculate moments of polygon
mm = cv.moments(c)
cx = mm['m10'] / mm['m00']
cy = mm['m01'] / mm['m00']
# Draw contour area
cv.drawContours(self.image, contours, i, (255, 255, 0), 2)
# Get contour edge points
dp = np.squeeze(cv.approxPolyDP(c, 100, True))
# Draw center
cv.circle(self.image, (int(cx), int(cy)), 5, (0, 0, 255),-1)

Perspective transformation, transform the detected contour into a (640,480) image

xxxxxxxxxx
#Classify the contour points detected by edge detection into top-left, bottom-left, bottom-right, top-right
for i in range(len(dp)):
if dp[i][0]<320 and dp[i][1]<240: upper_left=dp[i]
if dp[i][0]<320 and dp[i][1]>240: lower_left=dp[i]
if dp[i][0]>320 and dp[i][1]>240: lower_right=dp[i]
if dp[i][0]>320 and dp[i][1]<240: upper_right=dp[i]
# The four vertices in the original image
pts1 = np.float32([upper_left, lower_left, lower_right, upper_right])
# The four vertices after transformation
pts2 = np.float32([[0, 0], [0, 480], [640, 480], [640, 0]])
# Calculate perspective transformation from four pairs of corresponding points
M = cv.getPerspectiveTransform(pts1, pts2)
# Apply perspective transformation to the image
Transform_img = cv.warpPerspective(image, M, (640, 480))

For detailed code, see

dofbot_ws/src/dofbot_color_identify/scripts/dofbot_config.py

Or

dofbot_ws/src/dofbot_color_stacking/scripts/dofbot_config.py

Positioning Calculation

  • Object positioning calculation in the field of view

The camera on the robotic arm sees the widest field of view of the ground at a 45-degree oblique angle. At this angle, the frame in the field of view appears trapezoidal. After perspective transformation, the four edges of the frame are transformed into the four edges of the image.

Therefore, there is a proportional relationship between the distance from the object's center point in the field of view to the center of the image (640,480) and the actual distance from the object's center to the center of the frame (160,160).

​x
Lateral calculation, longitudinal calculation is similar:
​
(point_x-image_x)/640=(object_x-x)/160
​
Based on the robotic arm base coordinate system (introduced in URDF visualization)
​
point_x: Lateral coordinate of the object's center point in the field of view
​
image_x: Lateral coordinate of the image center point
​
object_x: Lateral coordinate of the actual object's center point
​
x: Position of the base coordinate system, which is 0 at this time
​
160: Frame side length in millimeters
​
In random sorting, only object_x is unknown and random; all others are known
  • Positioning calculation example code
xxxxxxxxxx
(a, b) = (round(((point_x - 320) / 4000), 5), round(((480 - point_y) /
​
3000) * 0.8+0.19, 5))
​
(a,b): Coordinates in the base coordinate system, converted from the object's center point coordinates in the field of view.
​
(point_x - 320) / 4000: Distance of the object from the frame center point in the x direction.
​
(480- point_y) / 3000: Distance of the object from the frame center point in the y direction.
​
0.19: Coordinate of the base coordinate center point to the nearest edge of the frame, manually measured, there is some deviation, can be adjusted appropriately.
​
0.8: Adjustment for errors caused by different distances from the camera, can be adjusted appropriately.
​
((480 - point_y) / 3000) * 0.8+0.19: Distance of the object from the base coordinate center point in the y direction.
  • Inverse kinematics angle adjustment

After obtaining the object's positioning in the base coordinate system, inverse kinematics calculates the angles each joint of the robotic arm needs to rotate to reach the specified posture.

Since the movement range of the robotic arm joints is 0°~180°, negative angle values cannot be reached. When the inverse solution exceeds the limit and a negative value appears, adjust appropriately.

xxxxxxxxxx
if joints[2] < 0:
    joints[1] += joints[2] * 3 / 5
    joints[3] += joints[2] * 3 / 5
    joints[2] = 0

Gripper Calculation

image-20240509184259611

Since different end effectors are generally used for different use scenarios, the inverse kinematics solution calculates the pose of the robotic arm's end, not the end of the end effector (gripper, suction cup, etc.).

The chassis coordinate system is called the base coordinate system, the red-green-blue coordinate system at the gripper is called the end coordinate system, and the gripper is called the end effector. Now, the inverse kinematics solution calculates the position the end coordinate system (not the gripper's grasping position) needs to reach. For the robotic arm shown in the figure, before solving the inverse, we need to obtain the position information the end coordinate system needs to reach (i.e., the pose information of the end coordinate system). So how to solve this?

For the pose, we set clockwise rotation around the axis (negative for counterclockwise, positive for clockwise) as follows:

xxxxxxxxxx
// Set different grasping poses according to object distance
​
double Roll = 2.5 * request.tar_y * 100 - 207.5;
​
double Pitch = 0;
​
double Yaw = 0;
  • Calculate offset angle

image-20240509184424845

xxxxxxxxxx
double init_angle = atan2(double(request.tar_y), double(request.tar_x));

atan2() is the arctangent function, an enhanced version of atan() that can determine the quadrant double

atan2(double y, double x);

The function of atan2() is to calculate the arctangent value of y/x. atan2() is an enhanced version of atan() that can determine the quadrant. The arctangent function atan2() and the tangent function tan() have opposite functions:

tan() is to find the tangent value of an angle given the radian value of the angle; while atan2() is to find the radian value of an angle given the tangent value (i.e., y/x).

  • Find the projection length of the gripper on the hypotenuse, corresponding to the xy plane, as shown in the right figure

image-20240509184508120

Measure the gripper length, tool_param=0.12; unit is meters.

xxxxxxxxxx
double dist = tool_param * sin((180 + Roll) * DE2RA);
  • Find the length of the robotic arm projected onto the xy plane (excluding the gripper part), the corresponding distance is shown in the upper right figure, excluding the red part.
xxxxxxxxxx
double distance = hypot(request.tar_x, request.tar_y) - dist;
  • Find the end position (excluding gripper), the corresponding position is the x, y coordinates shown in the upper right figure

double x = distance * cos(init_angle);

xxxxxxxxxx
double y = distance * sin(init_angle);
  • The final step is to find the z-axis coordinate

We need to find the z coordinate of the end coordinate system in the base coordinate system. See the left upper figure triangle, use trigonometric functions to find the vertical leg height.

double z = tool_param * cos((180 + Roll) * DE2RA);
Gesture recognition fixed action
Gesture recognition stack blocks

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文