Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides a method and a system for controlling a SCARA robot based on machine vision.
In order to solve the above problems, the present invention proposes a method for controlling a SCARA robot based on machine vision, the method comprising the steps of:
the robot controller collects a video data stream of an article to be processed based on a visual sensor;
the robot controller sends the video data stream to an upper computer;
the upper computer extracts key frame images of the video data stream based on a preset time interval, performs visual tracking processing on the key frame images, and generates mechanical arm motion planning information based on a visual tracking processing result;
the upper computer sends the mechanical arm motion planning information to the robot controller;
the robot controller generates a motion path and track instruction based on the mechanical arm motion planning information and sends the motion path and track instruction to the programmable logic controller;
and the programmable logic controller analyzes motion control instructions corresponding to the four joint servo drivers based on the motion path and the track instructions and sends the corresponding motion control instructions to the corresponding joint servo drivers.
The upper computer extracts key frame images from the video data stream based on a preset time interval, and the visual tracking processing of the key frame images comprises the following steps:
extracting a key frame image based on a preset time interval, then extracting an image block of a target area of the key frame image to serve as a target template, and carrying out relevant matching on the target template and all possible positions in the candidate image, wherein the position with the highest matching degree is the position of the target.
The extracting of the image block of the target area of the key frame image as the target template comprises:
extracting an interested area in the key frame image, and then carrying out contour extraction on an article to be processed in the interested area to obtain a standard contour of a target template, wherein the interested area is an area where image elements of the article to be processed change after work movement on the area where a target is initially located;
and extracting image blocks in the standard contour area based on the standard contour to form a target template.
The extracting of the region of interest in the key frame image and then the contour extraction of the region of interest to obtain the standard contour of the target template comprises:
acquiring a key frame image, and intercepting a rectangular region of interest by using a rectangular interception function; then enhancing the image of the region of interest; and finally, creating an image template under the target template through a template creating function to obtain a standard contour of the image template after binaryzation.
The step of creating the image template under the target template through the template creating function to obtain the standard contour after the binarization of the image template comprises the following steps:
searching the gray gradient of the image of the region of interest, processing the image of the region of interest by using a Sobel operator, and returning the pixel gray value in the X direction and the pixel gray value in the T direction;
searching local maximum values in the gradient direction by using a non-maximum value inhibition algorithm, inhibiting non-maximum value elements and refining edges;
and extracting and connecting edges by adopting a dual-threshold algorithm to obtain a standard outline of the image template.
The robot controller generates a motion path and track instruction based on the mechanical arm motion planning information, and the motion path and track instruction comprises the following steps:
the robot controller carries out track planning on the SCARA robot in a Cartesian space based on the mechanical arm motion planning information to obtain the corresponding relation between the Cartesian space track and joint angles, angular speeds and angular accelerations in each joint space;
performing dynamic modeling on the SCARA robot according to the SCARA robot model parameters and a dynamic analysis method to obtain a dynamic equation of the SCARA robot;
determining the output track state of the robot at each moment through a kinetic equation, outputting the parameter dimension of each joint space to obtain the vector representation of each moment, wherein the parameter dimension comprises joint angle position and joint angular velocity, and simultaneously giving out the vector representation of an expected track state unit on the basis of the vector dimension of the output track state unit;
generating a motion path and trajectory instruction based on the parameter dimensions and a vector representation of the desired trajectory state unit.
The motion control instructions corresponding to the four joint servo drivers are analyzed by the programmable logic controller based on the motion path and the track instructions, and the motion control instructions comprise:
the programmable logic controller analyzes the control parameters of each servo driver and then sends the control parameters to the corresponding servo driver according to the corresponding address relation of the servo driver.
Correspondingly, the invention also provides a control system of the SCARA robot, which comprises the following components:
the visual sensor is used for acquiring a video data stream of an article to be processed;
the robot controller is used for acquiring a video data stream of an article to be processed based on the visual sensor and sending the video data stream to the upper computer; generating a motion path and track instruction based on the mechanical arm motion planning information, and sending the motion path and track instruction to a programmable logic controller;
the upper computer is used for extracting key frame images from the video data stream based on a preset time interval, performing visual tracking processing on the key frame images and generating mechanical arm motion planning information based on a visual tracking processing result; sending the mechanical arm motion planning information to the robot controller;
and the programmable logic controller is used for analyzing motion control instructions corresponding to the four joint servo drivers based on the motion path and the track instructions and sending the corresponding motion control instructions to the corresponding joint servo drivers.
The upper computer extracts the key frame images based on a preset time interval, then uses image blocks of a target area of the key frame images as target templates, and carries out relevant matching on the target templates and all possible positions in the candidate images, wherein the position with the highest matching degree is the position where the target is located.
And the upper computer and the robot controller are communicated through a multi-point interface cable.
According to the SCARA robot control system, the video data stream is acquired by adopting the visual sensor, and the video data stream is uploaded to the upper computer to analyze and process the video image, so that the control system of the SCARA robot can extract the key frame image in combination with the video data stream, and can trigger the mechanical arm movement of the SCARA robot in combination with the key frame image to match the corresponding mechanical arm movement planning information, and the application combination of the video stream acquisition can be well suitable for the control link of the SCARA robot. The programmable logic controller is used for analyzing and distributing motion control instructions to the four joint servo drivers to control the production process of the SCARA robot, so that the reliability of the control of the tail end of the whole SCARA robot is higher.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Specifically, fig. 1 shows a schematic structural diagram of a control system of a SCARA robot in an embodiment of the present invention, where the control system includes: host computer, robot controller, programmable logic controller, visual sensor, first servo driver, second servo driver, third servo driver, fourth servo driver, first servo motor, second servo motor, third servo motor, fourth servo motor, first decoder, second decoder, third decoder and fourth decoder etc. wherein: the host computer can be a PC or the like, the host computer and the robot controller carry out data communication, the robot controller carries out data communication with the programmable logic controller, the robot controller carries out data communication with the vision sensor, the programmable logic controller carries out data communication with the first servo driver, the second servo driver, the third servo driver and the fourth servo driver, the first servo driver carries out data communication with the first servo motor and the first decoder, the second servo driver carries out data communication with the second servo motor and the second decoder, the third servo driver carries out data communication with the third servo motor and the third decoder, and the fourth servo driver carries out data communication with the fourth servo motor and the fourth decoder.
The vision sensor is arranged at a corresponding position of an application scene of the SCARA robot and can acquire a video data stream of an article to be processed, the vision sensor and the robot controller can communicate by adopting an RS485 communication protocol, the robot controller acquires the video data stream of the article to be processed based on the vision sensor, and the robot controller transmits the video data stream to an upper computer; the upper computer extracts key frame images from the video data stream based on a preset time interval, performs visual tracking processing on the key frame images, and generates mechanical arm motion planning information based on a visual tracking processing result; the upper computer sends the mechanical arm motion planning information to the robot controller; the robot controller generates a motion path and track instruction based on the mechanical arm motion planning information and sends the motion path and track instruction to the programmable logic controller; and the programmable logic controller analyzes motion control instructions corresponding to the four joint servo drivers based on the motion path and the track instructions and sends the corresponding motion control instructions to the corresponding joint servo drivers.
Specifically, after the upper computer acquires a video data stream, extracting a key frame image based on a preset time interval, taking an image block of a target area of the key frame image as a target template, performing relevant matching on the target template and all possible positions in candidate images, wherein the place with the highest matching degree is the position where the target is located, and the upper computer can match the current working state of the SCARA robot based on the visual tracking processing so as to match the next working state, thereby producing mechanical arm motion planning information based on the next working state. The time interval is measured in milliseconds, and the preset time interval is any value between 1ms and 100 ms.
The candidate images are stored in the upper computer, the candidate images are associated with historical working states of the SCARA robot, and a plurality of working images associated with the historical working states form a candidate image set to be stored in a storage space of the upper computer; the candidate images are related to simulation working states of the SCARA robot, working images related to the simulation working states form a candidate image set and are stored in a storage space of an upper computer, key frame images are extracted according to a time relation, the key frame images are subjected to a matching process in a mode of firstly extracting and firstly processing, namely, a first key frame image at a first moment is firstly subjected to related matching with the candidate images, a second key frame image at a second moment is then subjected to related matching with the candidate images, and mechanical arm motion planning information at different moments is generated according to the sequence of a time axis.
Fig. 2 shows a state change diagram of extracting image blocks of a target region of a key frame image as a target template in an embodiment of the present invention, where the left side is an original image, the middle is an image under ROI extraction, and the right side is a final target template, where extracting image blocks of the target region of the key frame image as the target template includes: extracting a region of interest (ROI) in the key frame image, and then extracting the outline of an article to be processed in the ROI to obtain a standard outline of a target template, wherein the ROI can be set based on a motion region of a robot on the article to be processed; and extracting image blocks in the standard contour area based on the standard contour to form a target template.
It should be noted that, here, extracting a region of interest in the key frame image, and then performing contour extraction on the region of interest to obtain a standard contour of the target template includes: acquiring a key frame image, and intercepting a rectangular region of interest by using a rectangular interception function; then enhancing the image of the region of interest; and finally, creating an image template under the target template through a template creating function to obtain a standard contour of the image template after binaryzation.
It should be noted that, here, creating an image template under a target template through a template creation function, and obtaining a standard contour after binarization of the image template includes: (1) and (3) searching the gray gradient of the image of the ROI, and processing the image by using a Sobel operator to return the pixel gray value in the X direction and the pixel gray value in the T direction. (2) Local maxima in the gradient direction are searched using a non-maximum suppression algorithm (NMS), non-maximum elements are suppressed, and edges can be refined. The non-maximum suppression algorithm tracks the left and right pixels in the edge direction, and if the gray value of the current pixel is smaller than the gray values of the left and right pixels, the gray value of the current pixel is suppressed. (3) And extracting and connecting edges by adopting a dual-threshold algorithm to obtain a standard outline of the image template. A small number of non-edge pixels may be included in the result after processing by the non-maxima suppression algorithm, so a cut-off is made by selecting a threshold. The dual-threshold selection and edge connection method assumes that one of two thresholds is a high threshold TH and the other is a low threshold TL, and then: for any edge pixel below TL, discard; for any edge pixel above TH, then hold; any edge pixel value between TL and TH, if edge-connectable one pixel is larger than TH and all pixels of the edge are larger than the minimum threshold TL, then retained, otherwise discarded; and storing the final edge image.
It should be noted that the upper computer and the robot controller can communicate with each other through a multi-point interface (MPI) cable, and the robot controller sends the mechanical arm movement planning information to the robot controller, and the robot controller generates a movement path and a trajectory instruction based on the mechanical arm movement planning information.
Specifically, the generating of the motion path and the trajectory instruction by the robot controller based on the mechanical arm motion planning information includes: and the robot controller performs track planning on the SCARA robot in a Cartesian space to obtain the corresponding relation between the Cartesian space track and joint angles, angular speeds and angular accelerations in each joint space. It should be noted that the motion path and trajectory instructions may enable the robot end effector to reach a set trajectory as much as possible. The trajectory of a robot is generally divided into a basic trajectory plan and an optimal trajectory plan. The basic trajectory planning is carried out in joint space and Cartesian coordinate space, and the kinematics and dynamics constraints of the robot must be considered during planning. For joint space trajectory planning, the planning object is the angle of each joint of the robot, the value generated by the function is the joint value, and the value generated by the Cartesian coordinate space trajectory planning function is the pose of the end hand of the robot hand. The Cartesian coordinate space trajectory is expressed in a common rectangular coordinate space and is very intuitive, but the Cartesian coordinate space trajectory has large calculation amount and can obtain the calculation accuracy of a similar joint space only by needing higher processing speed.
Specifically, the robot controller sends the motion path and the track instruction to the programmable logic controller, and the programmable logic controller analyzes the control parameter of each servo driver and then sends the control parameter to the corresponding servo driver according to the corresponding address relation of the servo driver. After receiving the motion path and track instructions, the programmable logic controller completes the control work of the advancing direction, calculates to obtain the rotating speed and the steering direction to be executed by the four servo motors, and controls different servo drivers to realize the control, so that the SCARA robot completes the corresponding operation process.
The control system of the SCARA robot adopts the visual sensor to collect the video data stream, the video data stream is uploaded to the upper computer to be analyzed and processed by the video image, the control system of the SCARA robot can extract the key frame image by combining the video data stream, the corresponding robot arm motion planning information can be matched by combining the key frame image, the mechanical arm motion of the SCARA robot is triggered, and the application combination of the video stream collection can be better applied to the control link of the SCARA robot. The programmable logic controller is used for analyzing and distributing motion control instructions to the four joint servo drivers to control the production process of the SCARA robot, so that the reliability of the control of the tail end of the whole SCARA robot is higher.
Fig. 3 shows a flow chart of a method for controlling a SCARA robot based on machine vision in an embodiment of the invention, the method comprising the steps of:
s21, acquiring a video data stream of the to-be-processed object based on the visual sensor by the robot controller;
s22, the robot controller sends the video data stream to an upper computer;
it should be noted that the vision sensor is arranged at a corresponding position of an application scene of the SCARA robot, and can acquire a video data stream of an article to be processed, the vision sensor and the robot controller can communicate with each other by adopting an RS485 communication protocol, the robot controller acquires the video data stream of the article to be processed based on the vision sensor, and the robot controller transmits the video data stream to an upper computer.
S23, the upper computer extracts key frame images from the video data stream based on a preset time interval, performs visual tracking processing on the key frame images, and generates mechanical arm motion planning information based on a visual tracking processing result;
after the upper computer obtains the video data stream, extracting key frame images based on a preset time interval, taking image blocks of a target area of the key frame images as a target template, carrying out relevant matching on the target template and all possible positions in candidate images, wherein the place with the highest matching degree is the position where the target is located, and the upper computer can match the current working state of the SCARA robot based on the visual tracking processing so as to match the next working state, thereby producing mechanical arm motion planning information based on the next working state. The time interval is measured in milliseconds, and the preset time interval is any value between 1ms and 100 ms.
It should be noted that, here, extracting the image block of the target area of the key frame image as the target template includes: extracting a region of interest (ROI) in the key frame image, and then carrying out contour extraction on an article to be processed in the ROI to obtain a standard contour of a target template, wherein the ROI is an area where image elements of the article to be processed change after work motion on the area where a target is initially located; and extracting image blocks in the standard contour area based on the standard contour to form a target template. The target area is extracted in an ROI mode, then the extraction processing of the image block of the area where the article to be processed is located is completed through contour extraction, and finally the corresponding target template is obtained.
It should be noted that, here, creating an image template under a target template through a template creation function, and obtaining a standard contour after binarization of the image template includes: (1) and (3) searching the gray gradient of the image of the ROI, and processing the image by using a Sobel operator to return the pixel gray value in the X direction and the pixel gray value in the T direction. (2) Local maxima in the gradient direction are searched using a non-maximum suppression algorithm (NMS), non-maximum elements are suppressed, and edges can be refined. The non-maximum suppression algorithm tracks the left and right pixels in the edge direction, and if the gray value of the current pixel is smaller than the gray values of the left and right pixels, the gray value of the current pixel is suppressed. (3) And extracting and connecting edges by adopting a dual-threshold algorithm to obtain a standard outline of the image template. A small number of non-edge pixels may be included in the result after processing by the non-maxima suppression algorithm, so a cut-off is made by selecting a threshold. The dual-threshold selection and edge connection method assumes that one of two thresholds is a high threshold TH and the other is a low threshold TL, and then: for any edge pixel below TL, discard; for any edge pixel above TH, then hold; any edge pixel value between TL and TH, if edge-connectable one pixel is larger than TH and all pixels of the edge are larger than the minimum threshold TL, then retained, otherwise discarded; and storing the final edge image.
It should be noted that, here, performing correlation matching on the target template and all possible positions in the candidate image includes: and performing a correlation matching process on the candidate image by adopting a BP neural network. The constant training of the neural network with a large number of data samples, which include both training inputs and desired outputs, is a prerequisite for the identification of different targets using the BP neural network. The training input data is often some feature quantity of the image, and the expected output can be set as the corresponding code number of the image.
Specifically, the BP neural network belongs to a multilayer forward type network, and signals thereof are propagated forward and errors are propagated backward. The standard BP neural network adopts a gradient descent method, and the weight of the network is reversely adjusted along the gradient of a performance function. The basic idea of training a feedforward network using the BP learning algorithm is: firstly, calculating an actual output value of input features in a training sample after the input features pass through a forward network through a forward process; then comparing the output value with the expected value to obtain an error signal, and adjusting the connection strength between each neuron from back to front according to the error signal; repeating the calculation of the forward process again to reduce the error, and comparing the new output value with the expected value to obtain a new error signal smaller than the original error signal; and then adjusting the connection strength between the neurons of the neural network layer from back to front according to a small error signal, wherein the forward process and the backward process are continuously carried out for multiple times until the error meets the requirement.
After the visual tracking processing of the key frame image is completed, a candidate image corresponding to the current key frame image can be obtained, the candidate image is associated with the current motion state of the SCARA robot and the next motion state of the SCARA robot, namely, the upper computer can match the current working state of the SCARA robot based on the visual tracking processing so as to match the working state required by the next step, and therefore mechanical arm motion planning information is produced based on the current working state and the next working state.
S24, the upper computer sends the mechanical arm motion planning information to the robot controller;
the upper computer and the robot controller can be communicated through a multi-point interface (MPI) cable, mechanical arm motion planning information is sent to the robot controller, and the robot controller generates motion path and track instructions based on the mechanical arm motion planning information.
S25, the robot controller generates a motion path and track instruction based on the mechanical arm motion planning information, and sends the motion path and track instruction to the programmable logic controller;
specifically, the generating of the motion path and the trajectory instruction by the robot controller based on the mechanical arm motion planning information includes: and the robot controller performs track planning on the SCARA robot in a Cartesian space to obtain the corresponding relation between the Cartesian space track and joint angles, angular speeds and angular accelerations in each joint space. It should be noted that the motion path and trajectory instructions may enable the robot end effector to reach a set trajectory as much as possible. The trajectory of a robot is generally divided into a basic trajectory plan and an optimal trajectory plan. The basic trajectory planning is carried out in joint space and Cartesian coordinate space, and the kinematics and dynamics constraints of the robot must be considered during planning. For joint space trajectory planning, the planning object is the angle of each joint of the robot, the value generated by the function is the joint value, and the value generated by the Cartesian coordinate space trajectory planning function is the pose of the end hand of the robot hand. The Cartesian coordinate space trajectory is expressed in a common rectangular coordinate space and is very intuitive, but the Cartesian coordinate space trajectory has large calculation amount and can obtain the calculation accuracy of a similar joint space only by needing higher processing speed.
Specifically, the robot controller performs track planning on the SCARA robot in a Cartesian space to obtain the corresponding relation between the Cartesian space track and joint angles, angular velocities and angular accelerations in each joint space; performing dynamic modeling on the SCARA robot according to the SCARA robot model parameters and a dynamic analysis method to obtain a dynamic equation of the SCARA robot; determining the output track state of the robot at each moment through a kinetic equation, outputting the parameter dimension of each joint space to obtain the vector representation of each moment, wherein the parameter dimension comprises joint angle position and joint angular velocity, and simultaneously giving out the vector representation of an expected track state unit on the basis of the vector dimension of the output track state unit; generating a motion path and trajectory instruction based on the parameter dimensions and a vector representation of the desired trajectory state unit.
Specifically, the motion trajectory of the tail end of the SCARA robot controlled by the improved quadratic iterative learning is adopted, so that the tracking error of the tail end is reduced, and the expected trajectory is accurately tracked.
And S26, the programmable logic controller analyzes motion control instructions corresponding to the four joint servo drivers based on the motion path and the track instructions, and sends the corresponding motion control instructions to the corresponding joint servo drivers.
Specifically, the robot controller sends the motion path and the track instruction to the programmable logic controller, and the programmable logic controller analyzes the control parameter of each servo driver and then sends the control parameter to the corresponding servo driver according to the corresponding address relation of the servo driver. After receiving the motion path and track instructions, the programmable logic controller completes the control work of the advancing direction, calculates to obtain the rotating speed and the steering direction to be executed by the four servo motors, and controls different servo drivers to realize the control, so that the SCARA robot completes the corresponding operation process.
According to the embodiment of the invention, the video data stream is acquired by adopting the visual sensor, and the video data stream is uploaded to the upper computer for analyzing and processing the video image, so that the control system of the SCARA robot can extract the key frame image by combining with the video data stream, and the mechanical arm motion planning information corresponding to the key frame image matching can be combined to trigger the mechanical arm motion of the SCARA robot, so that the application and combination of the video stream acquisition can be better suitable for the control link of the SCARA robot. The programmable logic controller is used for analyzing and distributing motion control instructions to the four joint servo drivers to control the production process of the SCARA robot, so that the reliability of the control of the tail end of the whole SCARA robot is higher.
The above embodiments of the present invention are described in detail, and the principle and the implementation of the present invention are described herein by using specific embodiments, and the description of the above embodiments is only used to help understanding the method of the present invention and the core idea thereof; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.