I have a robotic arm (uArm Swift Pro) and I am controlling it with Arduino.
The task of the arm is to pick little pieces of paper and put them to a specific place. The arm is controlled via x, y and z coordinates as well as F for the speed. A separate image detection software sends the x and y coordinates via USB serial print to Arduino. The arm itself is controlled via serial monitor of the Arduino.
I am working with delays between the separate positions the arm has to move and pick the piece of paper.
void loop() {
//Read serial input and extract the available data
if (Serial.available() > 0) {
rec = Serial.readStringUntil('\n');
int commaIndex = rec.indexOf(',');
int x_coord = rec.substring(0, commaIndex).toInt();
int y_coord = rec.substring(commaIndex + 1).toInt();
// Robot picks the piece
int y = (x_coord - 1378) * 0.10256 - 20;
int x = (y_coord - 1010) * 0.10256 + 190;
delay(500);
Serial.print("G0 X"); Serial.print(x); Serial.print(" Y"); Serial.print(y); Serial.print(" Z30"); Serial.println(" F15000"); // move to detected piece
delay(3000);
Serial.print("G0 X"); Serial.print(x); Serial.print(" Y"); Serial.print(y); Serial.print(" Z-6"); Serial.println(" F15000"); // move down to detected piece
Serial.println("#n M2231 V1\n"); // turn on pump
delay(1000);
Serial.print("G0 X"); Serial.print(x); Serial.print(" Y"); Serial.print(y); Serial.print(" Z30"); Serial.println(" F15000"); // move up
delay(1000);
Serial.println("G0 X130 Y-330 Z10 F15000"); // move to drop off position
delay(3250);
Serial.println("#n M2231 V0\n"); // turn off pump
Serial.println("G0 X130 Y-200 Z10 F15000"); //move to wait position
delay(2500);
// After robot picked the piece, it sends the command to pc
Serial.println("detect"); // restart process
}
My problem is that depending on where the arm has to go the time he needs to get there is different. In order to not let the software collapse, I have to set the highest delay which may occur for the piece that is most far away from the arm. As a result of that the arm is wasting time while picking pieces that are close to the arm.
My question is, if there is any kind of a flexible delay available for my problem. I had the idea to create sectors of the picking area and depending on what coordinates the Arduino receives it would have different delays. This means that every sector has its own delay. But I am certain that there will be smoother and easier ways to eliminate the waiting time of the arm while its picking a piece which lays close to the arm.
Thanks in advance for any help and advice! Please let me know if further details are required.
I haven't looked into the product in great detail...
If it is a robot that sends a G-code via UART and controls it, there is almost certainly feedback from the robot, right?
I think that the data in it contains the current coordinates or flag with in operation.
Instead of waiting for a fixed delay, you should check to see if the robot has moving and wait it.
It looks like you are using G code. If that is so then when each movement is completed you should get an OK sent back from your device so you know it is safe to send another set of move instructions.
As you only posted a small portion of your code is is hard to say where this is being picked up. But basically you should get feedback when any move is completed, you should not have to put in delays that cover the movement time.
The documentation shows the use of the Serial monitor for normal input and output. Type in a G-code command and the internal Arduino sends back a long sequence of messages documenting each step in executing the G-code command. There does not seem to be any particular response that says the G-code command is complete.
The OP seems to be using another Arduino in place of the Serial monitor and has to ignore all the text coming from the internal Arduino, and send the next G-code command. Hence, the need for variable delays to ignore the machine responses.
Not a particularly useful machine. The web site even states as much as the machine was designed and sold as a learning tool!
Paul
Probably, can use M2122, or compare the coordinates receive at the intervals set by M2120 with the destination.
I looked at everything I could find using "uArm Swift Pro" in a Google search. If there are other significant documents you have, why not give them in the first post?
Paul
I understand that I can enable/disable a report function to tell if the robot arm has stopped with "#n M2122 V1\n".
From what I understand this would be exactly what I need.
Could anyone help me how to get this information after I enabled it and how would the code look like?
roccckkky:
I understand that I can enable/disable a report function to tell if the robot arm has stopped with "#n M2122 V1\n".
From what I understand this would be exactly what I need.
Could anyone help me how to get this information after I enabled it.
Just read the serial port your machine is connected to. Print it out and see what it looks like.
and how would the code look like?
It would wait in a while loop until the information that marks the end of the movement is received on the serial port.