Code is running but the robotic arm did not move

Hi everyone,
I need help here. Im sorry too noob at here. Initially I can operate my robotic arm by using processing software.
The robotic arm can’t be executed in my current laptop but it works on my previous laptop by using same script and processing. When I start the code, the code is running but the robotic arm wasnt. It is strange, because it works on my previous laptop. And I have tried any other laptops, the same problem happens, it doesnt work too. I was thinking it might be based on proxy setting (referring the other forum), I tried and failed. I have tried many possibilities and looked up at forum to solve this problem. But none of these can help my problem. I do hope someone can help of this matter. Here is my code and thank you in advance.

import processing.serial.; //sending and receiving data using the serial communication protocol.
import controlP5.
; //type of GUI
float x; //position of robotic arm
float y;
float z;
float refx;
float refy;
float refz;
float relx;
float rely;
float relz;
ControlP5 cp5;
Serial myPort;
Serial myPort2;

void setup()
{
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 115200);
myPort2 = new Serial(this, “COM3”, 9600);
myPort.clear();
myPort2.clear();
size(800,480); // Set the window size of the interface
noStroke(); // No margins
cp5 = new ControlP5(this); // Define “cp5” to the usage of ControlP5 library
PFont pfont = createFont(“Arial Bold”,20, true); //PFont create a font to use with Processing
ControlFont font = new ControlFont(pfont, 30); // ControlFont is a container for a PFont that can be used to customize the font of a label
cp5.setColorActive(0xffff0000); //red

// Create new buttons

cp5.addSlider(“X”)
.setPosition(30, 30)
.setSize(200, 15)
.setRange(100,300)
.setValue(216.14)
.setScrollSensitivity(0.01)
.setSliderMode(Slider.FLEXIBLE)
.setColorCaptionLabel(0) //black
.setColorValueLabel(0) //black
;
cp5.addSlider(“Y”)
.setPosition(30, 55)
.setSize(200, 15)
.setRange(-180,180)
.setValue(12.06)
.setScrollSensitivity(0.01)
.setSliderMode(Slider.FLEXIBLE)
.setColorCaptionLabel(0)
.setColorValueLabel(0)
;
cp5.addSlider(“Z”)
.setPosition(30, 80)
.setSize(200, 15)
.setRange(-20,150)
.setValue(30)
.setScrollSensitivity(0.01)
.setSliderMode(Slider.FLEXIBLE)
.setColorCaptionLabel(0)
.setColorValueLabel(0)
;
cp5.addButton(“set position”)
.setPosition(30, 105)
.setSize(90,50)
;

cp5.addButton(“set origin”)
.setPosition(140, 105)
.setSize(90,50)
;

cp5.addButton(“start”)
.setPosition(30, 170)
.setSize(200,50)
;

cp5.addButton(“gas on”)
.setPosition(400,105)
.setSize(90,50)
;

cp5.addButton(“gas off”)
.setPosition(500,105)
.setSize(90,50)
;

cp5.getController(“gas on”) //unknown
.getCaptionLabel()
.setFont(font)
.toUpperCase(false) //Converts all of the characters in the string to uppercase. For example, “abc” will convert to “ABC”.
.setSize(14)
;

cp5.getController(“gas off”)
.getCaptionLabel()
.setFont(font)
.toUpperCase(false)
.setSize(14)
;

cp5.getController(“start”)
.getCaptionLabel()
.setFont(font)
.toUpperCase(false)
.setSize(14)
;
cp5.getController(“set position”)
.getCaptionLabel()
.setFont(font)
.toUpperCase(false)
.setSize(14)
;

cp5.getController(“set origin”)
.getCaptionLabel()
.setFont(font)
.toUpperCase(false)
.setSize(14)
;

cp5.getController(“X”)
.getValueLabel()
.align(ControlP5.RIGHT_OUTSIDE, ControlP5.CENTER)
.setPaddingX(10)
.setFont(font)
.setSize(18)
;
cp5.getController(“X”)
.getCaptionLabel()
.align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER)
.setPaddingX(10)
.setFont(font)
.setSize(18)
;
cp5.getController(“Y”)
.getValueLabel()
.align(ControlP5.RIGHT_OUTSIDE, ControlP5.CENTER)
.setPaddingX(10)
.setFont(font)
.setSize(18)
;
cp5.getController(“Y”)
.getCaptionLabel()
.align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER)
.setPaddingX(10)
.setFont(font)
.setSize(18)
;
cp5.getController(“Z”)
.getValueLabel()
.align(ControlP5.RIGHT_OUTSIDE, ControlP5.CENTER)
.setPaddingX(10)
.setFont(font)
.setSize(18)
;
cp5.getController(“Z”)
.getCaptionLabel()
.align(ControlP5.LEFT_OUTSIDE, ControlP5.CENTER)
.setPaddingX(10)
.setFont(font)
.setSize(18)
;
smooth();
}

void draw(){
background(255);
}

public void go(){
String setpoint = “G0” + “X” + Float.toString(x) + “Y” + Float.toString(y) + “Z” + Float.toString(z) + “F100 \n”;
println(“set arm 1 to”,setpoint);
myPort.write(setpoint);
}

public void relgo(float relx,float rely,float relz){
String relmove = “G2204” + “X” + Float.toString(relx) + “Y” + Float.toString(rely) + “Z” + Float.toString(relz) + “F100 \n”;
println(“relgo”,relmove);
myPort.write(relmove);
}

void controlEvent(ControlEvent theEvent) {
if(theEvent.isController()) {
print("control event from : “+theEvent.getController().getName());
println(”, value : "+theEvent.getController().getValue());

if(theEvent.getController().getName()==“gas on”){
myPort2.write(“1”);
}
if(theEvent.getController().getName()==“gas off”){
myPort2.write(“2”);
}

if(theEvent.getController().getName()==“set position”) {
x=cp5.getController(“X”).getValue();
y=cp5.getController(“Y”).getValue();
z=cp5.getController(“Z”).getValue();
myPort.write(“M2400 S0 \n”);
go();
}

if(theEvent.getController().getName()==“set origin”) {
refx=cp5.getController(“X”).getValue();
refy=cp5.getController(“Y”).getValue();
refz=cp5.getController(“Z”).getValue();
println(“Origin”,“X”,refx,“Y”,refy,“Z”,refz);
}

if(theEvent.getController().getName()==“start”) {
//initial position
x=refx-80.5;
y=refy+67.5;
z=refz+55;
go();
delay(2000);
myPort2.write(“3”);
myPort2.write(“4”);

// first grid
myPort2.write(“1”);
relgo(10,0,0);
delay(20000);

myPort2.write(“2”); //valve close
relgo(0,0,-55);
delay(20000);

relgo(0,0,55);
delay(5);

for (int k = 0; k <7; k=k+1){
//row 1
for (int j = 0; j < 14; j=j+1){
myPort2.write(“1”);
relgo(10,0,0);
delay(20000);

myPort2.write(“2”); //valve close
relgo(0,0,-55);
delay(20000);

relgo(0,0,55);
delay(5);
}

//row 2
print(“change to row 2”);
myPort2.write(“1”);
relgo(0,-10,0);
delay(20000);

myPort2.write(“2”);
relgo(0,0,-55);
delay(20000);

relgo(0,0,55);
delay(5);

for (int i = 0; i < 14; i = i+1) {
myPort2.write(“1”);
relgo(-10,0,0);
delay(20000);

myPort2.write(“2”);
relgo(0,0,-55);
delay(20000);

relgo(0,0,55);
delay(5);
}
print(“change to row 3”);
myPort2.write(“1”);
relgo(0,-10,0);
delay(20000);

myPort2.write(“2”);
relgo(0,0,-55);
delay(20000);

relgo(0,0,55);
delay(5);
}
//row 15
for (int j = 0; j < 14; j=j+1){
myPort2.write(“1”);
relgo(10,0,0);
delay(20000);

myPort2.write(“2”); //valve close
relgo(0,0,-55);
delay(20000);

relgo(0,0,55);
delay(5);
}

myPort2.write(“5”);
myPort.clear();
myPort2.clear();
}
}
}

Hi @jingchi Welcome to the forum. You’ve set quite a hard challenge because (speaking personally) I don’t have your robot arm, or any of your laptops.

The program connects to 2 serial ports, on lines 19 and 20. Does the robot arm plug in to the laptop with one usb connection? Is this a windows laptop? (I’ll assume yes) Version?. Run device manager, expand the “Ports (COM & LPT)” section. Now plug and unplug the robot arm while watching what ports get created. Note the names.

I’m guessing that the names in the program are not the correct ones for the robot.

Do you know why there are 2 channels, at different baud rates?

portName = Serial.list()[0]; - I’ve never liked that code, I know it’s in an example, but it’s unpredictable because you don’t know which port the PC is going to list first. Suggest change line 19 to same format as 20, explicitly stating the name of the port.

Does the robot have transmit and receive lights on the comms? This help would confirm correct connection.

Do you have the comms spec for the robot? In a manual?

1 Like

Hi @RichardDL the first port on line 19 is connect with “uArm swift robotic arm” and the second port on line 20 is “arduino uno”.The robotic arm port is com port 5 and arduino port is com port 3.And my new computer is win11 but i try others’ computer with win10 is still not working.
After i press start buttom in processing program,it have appear the Graphical User Interface.But when i press start buttom in the GUI the robotic arm cant’t move.In others’ computer,robotic arm can move but it can’t move with some computer.I think maybe i miss the driver between uArm swift and processing. By the way,when i press start buttom in the GUI,the arduino can work the function properly so i didn’t think there are the problem between processing and arduino software.
Thank you very much.

@jingchi, Alright, a few more facts about the system, good. You need to be 200% sure of the com names for the robot and Ard. I think you should do the Device Manager action I said to be really sure.

Another confusion is that some devices change com port number with different USB sockets. A genuine Arduino will keep the same name, but the cheap Chinese ones don’t. Try robot and Ard in different usb sockets.

As I said, I think it’s better to use explicit com port names. Show yourself what the Serial.list finds with this (in another sketch). [0] is the first one.

import processing.serial.*;
println(Serial.list());

(See how that code example is formatted. You could format your first post like that. Edit, select the code, click the </> symbol.)