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

2. Inverse solution

Inverse Kinematics

1. Function Description

After the node program starts, it provides a /dofbot_kinemarics service. This service provides both fk and ik services. You can choose to call fk or ik by specifying kin.name. The fk service takes the current angle values of the 6 servos (joint values) as input and outputs the current end-effector pose of the robotic arm. This pose includes xyz coordinates and Euler angles (roll, pitch, yaw); The ik service takes the end-effector pose of the robotic arm (xyz coordinates and Euler angle values) as input and outputs the angle values of the 6 servos (joints). When grasping objects in 3D space later, we need to first read the current end-effector pose of the robotic arm, then identify the center of the object and obtain a new pose coordinate through coordinate transformation, and finally call ik to calculate the value of each servo.

2. Startup and Operation

2.1 Startup

Enter in the terminal:

xxxxxxxxxx
# Start the inverse kinematics program
ros2 run dofbot_info kinemarics_dofbot
# Start the ROS control robotic arm program
ros2 run dofbot_driver arm_driver

After the inverse kinematics node program starts, it provides a service. To check this, enter in the terminal:

xxxxxxxxxx
ros2 node info /kinemarics_dofbot

image-20260320163705862

In the listed service list, there is /dofbot_kinemarics. This is the inverse kinematics service. Use the following command to view the related information of this service:

xxxxxxxxxx
ros2 service type /dofbot_kinemarics

image-20260320163726383

As shown in the image above, the service type data of /dofbot_kinemarics is the custom dofbot_interface/srv/Kinemarics. The specific parameters are the content in Args below. We can use the following command to see what content is included in the dofbot_interface/srv/Kinemarics data type:

xxxxxxxxxx
ros2 interface show dofbot_interface/srv/Kinemarics

image-20260320163824089

Here, the --- divides the two parts. The upper part is the request (which can be understood as the input parameters), and the lower part is the response (which can be understood as the output return value). There is an additional kin_name in the request part, which distinguishes whether we are calling IK or FK. If you want to call the IK service, assign IK to kin_name; otherwise, assign the FK value to kin_name to call the FK service. Parameters in the request part:

  • tar_x: x value of the target position, unit is m
  • tar_y: y value of the target position, unit is m
  • tar_z: z value of the target position, unit is m
  • Roll: Roll value of the target pose, unit is radians
  • Pitch: Pitch value of the target pose, unit is radians
  • Yaw: Yaw value of the target pose, unit is radians

The above 6 are parameters that must be assigned when calling IK.

  • cur_joint1: current angle value of servo #1, unit is degrees
  • cur_joint2: current angle value of servo #2, unit is degrees
  • cur_joint3: current angle value of servo #3, unit is degrees
  • cur_joint4: current angle value of servo #4, unit is degrees
  • cur_joint5: current angle value of servo #5, unit is degrees
  • cur_joint6: current angle value of servo #6, unit is degrees

The above 6 are parameters that must be assigned when calling FK.

  • kin_name: the name of the service to call, ik or fk

Parameters in the response part:

  • joint1: angle value of servo #1, unit is degrees
  • joint1: angle value of servo #2, unit is degrees
  • joint1: angle value of servo #3, unit is degrees
  • joint1: angle value of servo #4, unit is degrees
  • joint1: angle value of servo #5, unit is degrees
  • joint1: angle value of servo #6, unit is degrees

The above 6 values are the 6 servo angle values returned after calling the IK service.

  • x: x value of the calculated end-effector position, unit is m
  • y: y value of the calculated end-effector position, unit is m
  • z: z value of the calculated end-effector position, unit is m
  • Roll: Roll value of the calculated end-effector position, unit is radians
  • Pitch: Pitch value of the calculated end-effector position, unit is radians
  • Yaw: Yaw value of the calculated end-effector position, unit is radians

The above 6 parameters are the end-effector position and pose returned after calling the FK service.

2.2 Operation

2.2.1 FK

First, let's move the robotic arm to a certain state, then based on this state, read out the end-effector position and pose, and compare it with the actual measured values to see if it is accurate. From the previous lesson "ROS Control Robotic Arm", we can use the topic to publish a robotic arm pose first. For example, publish [90,120,30,30,90,90]. Enter in the terminal:

xxxxxxxxxx
ros2 topic pub /TargetAngle dofbot_interface/ArmJoint "id: 0
run_time: 1000
angle: 0.0
joints: [90,120,30,30,90,90]"

Press Enter to publish the message, and the robotic arm moves to the specified pose. Then, we call the FK service, writing the just-set [90,120,30,30,90,90] into the current values of the 6 servos, which are cur_joint1 to cur_joint6. Additionally, assign fk to kin_name. Enter in the terminal:

xxxxxxxxxx
ros2 service call /dofbot_kinemarics dofbot_interface/srv/Kinemarics "{tar_x: 0.0, tar_y: 0.0, tar_z: 0.0, roll: 0.0, pitch: 0.0, yaw: 0.0, cur_joint1: 90.0,
  cur_joint2: 120.0, cur_joint3: 30.0, cur_joint4: 30.0, cur_joint5: 90.0, cur_joint6: 90.0,
  kin_name: 'fk'}"

Press Enter, and the response will be printed in the terminal, as shown in the image below:

image-20260320163921908

From the printed response, we can see that the xyz of the robotic arm end-effector position and the Euler angles Roll, Pitch, Yaw representing the robotic arm end-effector pose are: x=-0.14624000005840623, y=0.0007025520000000001, z=0.26420041152256324, Roll=7.3464102067096675e-06, Pitch=3.661037138843959e-06, Yaw=-3.141592653589793. From these data, we can know that the robotic arm end-effector is 0.0007025520000000001 meters to the left of the base coordinate system, 0.14624000005840623 meters forward, and 0.26420041152256324 meters high. The pose can be considered unchanged. We can roughly measure the distance from the robotic arm end-effector to the base coordinate system with a ruler to see if it matches the calculated xyz values.

2.2.2 IK

First, let's send the following message to make the robotic arm extend upward. Enter in the terminal:

xxxxxxxxxx
ros2 topic pub /TargetAngle dofbot_interface/ArmJoint "id: 0
run_time: 1000
angle: 0.0
joints: [90,90,90,90,90,90]"

Then, we call the IK service. By giving the position and pose parameters of the robotic arm end-effector, we calculate what the values of each servo of the robotic arm should be to achieve this position and pose. Taking the xyz and Euler angles previously calculated by FK as the target position and pose as an example, enter in the terminal:

xxxxxxxxxx
ros2 service call /dofbot_kinemarics dofbot_interface/srv/Kinemarics "{tar_x: -0.14624000005840623, tar_y: 0.0007025520000000001, tar_z: 0.26420041152256324, roll: 7.3464102067096675e-06, pitch: 3.661037138843959e-06, yaw: -3.141592653589793, cur_joint1: 00.0,
  cur_joint2: 0.0, cur_joint3: 0.0, cur_joint4: 0.0, cur_joint5: 0.0, cur_joint6: 0.0,
  kin_name: 'ik'}"

Press Enter, and the response will be printed in the terminal, as shown in the image below:

image-20260320165139492

From the printed response, we can see that the calculated joint1-joint6 correspond to the values of the 6 servos. After rounding each joint, they are [90,120,30,30,90,0]. Let's try to publish the calculated joint1-joint6 to the robotic arm control node via the topic to make it move to the specified pose. Enter in the terminal:

xxxxxxxxxx
ros2 topic pub /TargetAngle dofbot_interface/ArmJoint "id: 0
run_time: 1000
angle: 0.0
joints: [90,120,30,30,90,0]"

Press Enter to make the robotic arm move to the specified pose. Then, we use a ruler to measure whether the distance from the robotic arm end-effector to the base coordinate system matches the xyz we input. A tolerance of 1cm is acceptable. This is because each servo of the robotic arm cannot be guaranteed to be completely identical at the factory, and there are slight differences.

3. Program Flowchart

image-20240924110534308

4. Core Code Analysis

Code path:

xxxxxxxxxx
/home/yahboom/dofbot_ws/src/dofbot_info/src/kinemarics_dofbot.cpp

Import related header files:

xxxxxxxxxx
#include <iostream>
#include <vector>
#include "rclcpp/rclcpp.hpp"
#include <kdl/chain.hpp>
#include <kdl/tree.hpp>
#include <kdl/segment.hpp>
#include <kdl/frames_io.hpp>
#include <kdl/chainiksolverpos_lma.hpp>
#include <kdl/chainfksolverpos_recursive.hpp>
#include <kdl_parser/kdl_parser.hpp>
#include "dofbot_interface/srv/kinemarics.hpp"
#include "dofbot_kinematics.h"

Define some constants:

​x
// Radian to degree
const float RA2DE = 180.0f / M_PI;
// Degree to radian
const float DE2RA = M_PI / 180.0f;
// URDF model, when doing inverse kinematics, the urdf model will be used as a parameter input for calculation
const char *urdf_file = "/home/yahboom/dofbot_ws/src/dofbot_urdf/urdf/dofbot.urdf";
​

Main function:

xxxxxxxxxx
auto server_node = rclcpp::Node::make_shared("kinemarics_dofbot");
auto service = server_node->create_service<dofbot_interface::srv::Kinemarics>(
    "dofbot_kinemarics", srvicecallback);

Service callback function srvicecallback:

FK service part:

xxxxxxxxxx
if (request->kin_name == "fk") {
    // Get the current joint angles from the service request
    // 从服务请求中获取当前关节角度
    double joints[]{
        request->cur_joint1, request->cur_joint2, request->cur_joint3,
        request->cur_joint4, request->cur_joint5
    };
    
    // Container for the initial joint angles 
    // 初始关节角度容器
    vector<double> initjoints;
    
    // Container for the resulting end-effector position and orientation
    // 末端执行器位置和姿态的结果
    vector<double> initpos;
    
    // Convert joint angles from degrees to radians
    // 将关节角度从度转换为弧度
    for (int i = 0; i < 5; ++i) {
        initjoints.push_back((joints[i] - 90) * DE2RA);
    }
    
    // Call the forward kinematics function to calculate end-effector pose
    // 调用正向运动学函数计算末端执行器位姿
    if (getFK(urdf_file, initjoints, initpos)) {
        // Log the FK input joint angles for debugging
        // 记录FK输入关节角度以便调试
        RCLCPP_INFO(rclcpp::get_logger("rclcpp"), 
                    "FK Input Joints: J1=%.2f, J2=%.2f, J3=%.2f, J4=%.2f, J5=%.2f",
                    joints[0], joints[1], joints[2], joints[3], joints[4]);
        
        // Log the FK output pose (position + orientation)
        // 记录FK输出位姿(位置 + 姿态)
        RCLCPP_INFO(rclcpp::get_logger("rclcpp"), 
                    "FK Output Pose: X=%.4f, Y=%.4f, Z=%.4f, Roll=%.4f, Pitch=%.4f, Yaw=%.4f",
                    initpos.at(0), initpos.at(1), initpos.at(2),
                    initpos.at(3), initpos.at(4), initpos.at(5));
        
        // Fill the response with the computed pose
        // 将计算得到的位姿填入响应
        response->x = initpos.at(0);
        response->y = initpos.at(1);
        response->z = initpos.at(2);
        response->roll = initpos.at(3);
        response->pitch = initpos.at(4);
        response->yaw = initpos.at(5);
    } 
    .....
}

IK service part:

if (request->kin_name == "ik") {
    // Define the end-effector pose (position and orientation)
    // 定义末端执行器位姿(位置和姿态)
    double xyz[]{request->tar_x, request->tar_y, request->tar_z};
    double rpy[]{request->roll, request->pitch, request->yaw};
    
    // Vectors to store target position, orientation, and output joint angles
    // 存储目标位置、姿态和输出关节角的向量
    vector<double> targetXYZ;
    vector<double> targetRPY;
    vector<double> outjoints;
    
    // Copy input position values to targetXYZ vector
    // 将输入的位置值复制到targetXYZ向量
    for (int k = 0; k < 3; ++k) targetXYZ.push_back(xyz[k]);
    
    // Copy input orientation values (RPY) to targetRPY vector
    // 将输入的姿态值(RPY)复制到targetRPY向量
    for (int l = 0; l < 3; ++l) targetRPY.push_back(rpy[l]);
    
    // Log the IK input parameters for debugging
    // 记录IK输入参数以便调试
    RCLCPP_INFO(rclcpp::get_logger("rclcpp"), 
                "IK Input Target: X=%.4f, Y=%.4f, Z=%.4f, Roll=%.4f, Pitch=%.4f, Yaw=%.4f",
                xyz[0], xyz[1], xyz[2], rpy[0], rpy[1], rpy[2]);
    
    // Call the inverse kinematics solver
    // 调用逆运动学求解器
    if (getIK(urdf_file, targetXYZ, targetRPY, outjoints)) {
        // Log the IK output joint angles
        // 记录IK输出的关节角度
        RCLCPP_INFO(rclcpp::get_logger("rclcpp"), 
                    "IK Output Joints: J1=%.2f, J2=%.2f, J3=%.2f, J4=%.2f, J5=%.2f",
                    (outjoints.at(0) * RA2DE) + 90, 
                    (outjoints.at(1) * RA2DE) + 90,
                    (outjoints.at(2) * RA2DE) + 90, 
                    (outjoints.at(3) * RA2DE) + 90,
                    (outjoints.at(4) * RA2DE) + 90);
        
        // Set the response joint angles
        // 设置响应关节角度
        response->joint1 = (outjoints.at(0) * RA2DE) + 90;
        response->joint2 = (outjoints.at(1) * RA2DE) + 90;
        response->joint3 = (outjoints.at(2) * RA2DE) + 90;
        response->joint4 = (outjoints.at(3) * RA2DE) + 90;
        response->joint5 = (outjoints.at(4) * RA2DE) + 90;
    }
    .......
}
Robotic arm ROS control
AprilTag ID sorting

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/中文