0% found this document useful (0 votes)
6 views10 pages

Robotic Arm Visual Processing Guide

Uploaded by

HamiTal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Robotic Arm Visual Processing Guide

Uploaded by

HamiTal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program Analysis

1. File Path

The program file is stored in:

/home/ubuntu/armpi_pro/src/visual_processing/scripts/visual_processing_node.py

(image analysis)

/home/ubuntu/armpi_pro/src/intelligent_grasp/scripts/intelligent_grasp_node.py

(picking control)

2. Program Performance

After the game starts, the robotic arm will rotate back and forth to search for
target. The target will be marked with a bounding box once it is detected. At
this pint, robotic arm will slowly move towards the target, and then grip and
place it at a specific position.
3. Program Analysis

Note: please back up the initial program before making any modifications. It is

prohibited editing the source code files directly to prevent making changes in an

incorrect manner that could lead to robot malfunctions, rendering them irreparable.

3.1 Import Parameter Module

Imported Module Function

The sys module of Python is imported to

import sys access to system-related functionalities and

variables.

The OpenCV library of Python is imported

import cv2 to perform image processing and computer

vision-related functions.

The time module of Python is imported to

import time perform time-related functionalities, such as

delay operations.

The math module of Python is imported to

import math perform mathematical operations and

functions.

The Python library rosy is imported for


import rospy
communication and interaction with ROS.

The NumPy library is imported and is

import numpy as np renamed as np for performing array and

matrix operations.
The Misc module is imported from

from armpi_pro import Misc arm_pi_pro package to handle the

recognized rectangular data.

The apriltag module is imported from

from armpi_pro import apriltag arm_pi_pro package to perform Apriltag

recognition and processing.

The “RLock” class and “Timer” class is

from threading import RLock, Timer imported from the threading module of

Python for thread-related operations.

All service message types are imported

from std_srvs.srv import * from the std_srvs in ROS for defining and

using standard service messages.

All message types are imported form the

from std_msgs.msg import * std_msgs package in ROS for defining and

using standard messages.

The image message type is imported from

from sensor_msgs.msg import Image the sensor_msgs packages for processing

image data.

The Result message type is imported from


from visual_processing.msg import
the visual_processing package for the
Result
message of image processing results.

The SetParam service type is imported


from visual_processing.srv import
from the visual_processing packages for
SetParam
using customs service related to parameter
settings.

The Led message type is imported form the

from [Link] import Led [Link] module for controlling or

representing the LED status on a sensor.

All message types are imported from the

chassis_control.msg module, which

from chassis_control.msg import * indicated that all message types defined in

this module is imported to perform the

chassis control.

The SetTarget service type is imported

from visual_patrol.srv import SetTarget from the visual_patrol.srv module is used to

set a target for line following.

The MultiRawIdPosDur message type is

from hiwonder_servo_msgs.msg imported from the

import MultiRawIdPosDur hiwonder_servo_msgs.msg module for

controlling servos.

The PID class is imported from the

from armpi_pro import PID armpi_pro module to perform PID

algorithm.

The bus_servo_control module is imported

from armpi_pro import from the armpi_pro module, including the

bus_servo_control functions and methods related to the servo

control.

from kinematics import ik_transform The ik_transform function is imported from


the kinematics module to perform

conversion of inverse kinematics.

3.2 Program Logic

The image information is obtained through camera,

By using the camera to capture the visual information, the robotic arm moves
back and forth to locate a colored block. When the block is recognized, the
detected image will be processed to obtain the position information of the
colored block. Then, control the robotic arm to grip the block and place it at a
designated position.
3.3 Code Analysis

From the above diagram flow, the program is mainly used for multiple colors
recognition function and servo control.

3.3.1 Image Processing

Initializing Functions and variables


Binarization

Use the inRange () function from the cv2 library to binarize the image

The first parameter “frame_lab” is the input image.

The second parameter “tuple(color_range['min'])” is the lower limit of threshold.

The third parameter “tuple(color_range['max'])” is the upper lower of threshold.

Dilation and Erosion

To reduce interference and make a smooth image, it is necessary to perform


dilation and erosion operations on the image.

erode() function is applied to erode image. Here uses an example of the code
“eroded = [Link](frame_mask,
[Link](cv2.MORPH_RECT, (2, 2)))” as example. The
meaning of parameters in parentheses are as follow:

The first parameter “frame_mask” is the input image.

The second parameter “[Link](cv2.MORPH_RECT, (2, 2))”


is the structural elements and kernel that determines the nature of operation.
The first parameter in parentheses is the shape of kernel and the second
parameter is the size of kernel.

dilate() function is applied to dilate image. The meaning of parameters in


parentheses is the same as the parameters of erode() function.

Obtain the contour of the maximum area

After processing the above image, obtain the contour of the recognition target.
The findContours() function from the cv2 library is involved in this process.

The erode() function is applied to erode. Here uses an example of code


“contours = [Link](dilated, cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_NONE)[-2]”.

The first parameter “dilated” is the input image.

The second parameter “cv2.RETR_EXTERNAL” is the contour retrieval mode.

The third parameter “cv2.CHAIN_APPROX_NONE)[-2]” is the approximation


method for contours.

Find the maximum contour from the obtained contours. To avoid interference,
set a minimum value. Only when the area is greater than this minimum value,
the target contour will take effect.

Obtain Position Information

The minAreaRect() function from the cv2 library is used to obtain the minimum
enclosing circle and its center coordinates for the target contour. The circle()
function is employed to display the circumferential in the feedback image.
Determine the color block with the largest area.

3.3.2 Gripping Control

The position of the target on x, y and z axes are obtained after processing
image. Then get the target position calculated by inverse kinematics and grip
it.

The inverse kinematics takes “[Link]((0, round(y_dis + offset_y,


4), -0.08), -180, -180, 0)” as example and the meaning of parameters in
parentheses are as follow:

The first parameter is “(0, round(y_dis + offset_y, 4)”. “0” is the position of the
target on x-axis. “round(y_dis, 4)” is the position of the target on y-axis.
“round(z_dis, 4)” is the position of the target on z-axis.
The second parameter “-180” is the angle of x-axis.

The third parameter “-180” is the range of the pitch angle.

The fourth parameter “0” is the range of pitch angle.

The servo control uses an example of code


“bus_servo_control.set_servos(joints_pub, 20, ( (3, servo_data['servo3']),
(4, servo_data['servo4']), (5, servo_data['servo5']), (6, x_dis)))” and the
meaning of parameters in parentheses is as follow:

The first parameter “joints_pub” is to publish the message of servo control


node.

The second parameter “20” is the running time.

The third parameter is “( (3, servo_data['servo3']), (4, servo_data['servo4']),


(5, servo_data['servo5']), (6, x_dis)”. Among them, “3” is the servo number.
“servo_data['servo3']” and the rest of parameters are the servo angle.

Common questions

Powered by AI

The use of the PID class significantly enhances the program's performance in motion control by continuously adjusting the robotic arm's movements to optimize accuracy and stability. The PID algorithm calculates error values as the difference between desired positions and measured positions, and adjusts motor inputs to minimize this error over time. This dynamic adjustment is crucial for tasks requiring precision, like gripping and positioning, thereby improving the overall efficiency of the robotic arm .

The image processing module utilizes binarization, dilation, and erosion techniques to identify and isolate the target color blocks. Binarization is performed using the inRange() function from OpenCV, which sets threshold limits for color detection to simplify the image into a binary one. Dilation and erosion operations are applied using cv2.erode() and cv2.dilate() to reduce noise and smooth out the image, helping in obtaining clearer contours. Contours are then found using cv2.findContours(), from which the largest contour is selected if it meets a minimum area criterion .

The program utilizes threading capabilities through RLock and Timer classes from the threading module. This enables simultaneous execution of multiple operations, such as processing image data while controlling the robotic arm, improving overall efficiency and responsiveness of the program. Threading ensures that tasks are not delayed by sequential processing, which is critical for real-time applications in robotics .

Inverse kinematics is crucial in the program's gripping control process as it calculates the target position for the robotic arm in 3D space, allowing for precise manipulation of the arm to grip the target. The ik_transform function is used to convert position data obtained from image processing into joint movements required to reach and grip the target. It includes parameters for position on the x, y, and z axes, as well as angle adjustments for precise movement .

The program uses several Python modules to enhance its functionality and enable interaction with the robotic system. For instance, the sys module provides access to system-related functions, OpenCV (cv2) is used for image processing, and rospy facilitates communication with ROS. NumPy supports numerical array and matrix operations crucial for data handling. Additionally, modules like armpi_pro provide specialized functionalities such as APRIL tag processing and PID control crucial for the robotic arm's operational accuracy .

The function setPitchRanges within the ik_transform is crucial for defining the orientation and precise positioning of the robotic arm during the gripping control process. Its parameters include target positions on the x, y, and z axes, derived from image data, and predefined angle limits for motions. The first parameter, representing adjustments along the y-axis, aligns the arm's pitch to the block's current location. Subsequent parameters, like angles of -180, refine the arm's approach to ensure proper alignment and grip on the block .

The main functions imported from the OpenCV library include inRange(), erode(), dilate(), findContours(), and minAreaRect(). inRange() is used for color-based binarization, erode() and dilate() refine the image by reducing noise, findContours() detects image contours, and minAreaRect() calculates the minimum enclosing circle for detected contours. These functions collectively enable robust image processing, allowing accurate detection and isolation of target objects by the robotic arm .

The integration with ROS (Robot Operating System) supports the program's functionality and interaction capabilities by facilitating communication between various system components and external devices. Modules like rospy are used to subscribe and publish messages, enabling real-time data exchange and feedback mechanisms essential for control tasks. This seamless interaction supports complex operations such as image recognition and servo control, enabling the robotic arm to perform coordinated tasks effectively .

The source suggests backing up the initial program before making modifications to prevent errors or malfunctions. Direct editing of source code files is prohibited, as improper changes could lead to irreparable robot malfunctions .

The program ensures that contours are of significant size by setting a minimum area threshold. Only those contours that exceed this threshold are considered representative of the target. This approach filters out smaller, irrelevant shapes that may result from noise or minor obstructions in the visual field .

You might also like