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();
}
}
}