RoboDK Forum
python code is not working- Printable Version

+- RoboDK Forum (//www.sinclairbody.com/forum)
+-- Forum: RoboDK (EN) (//www.sinclairbody.com/forum/Forum-RoboDK-EN)
+--- Forum: RoboDK API (//www.sinclairbody.com/forum/Forum-RoboDK-API)
+--- Thread: python code is not working (/Thread-python-code-is-not-working)



python code is not working-MohammedKhadeer-02-14-2023

Hello, I have developed a program through an interface(not coding) in Robodk for Ur16e Robot . Stimulation and on a Real robot it is running perfectly. To make an HMI i have developed a web application in java(SpringBoot) and which robodk i have generate the code Rightclick>>generate code option.
But this is not working, i just want to run the sample code, not the whole code from.RDK station..

java code :

package com.HCL.HclProgram.Controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
//import subprocess


@ controller
@RequestMapping("/Robot")
public class RobotController {

@GetMapping("/Pick_Approach")
// @RequestMapping("/Pick_Approach")
@ResponseBody
public String runRobotProgram() {
StringBuilder output = new StringBuilder();
try {
ProcessBuilder processBuilder = new ProcessBuilder("python", "F:/HCLProgram/HclProgram/src/testing.py");
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
//System.out.println(line);
output.append(line).append("\n");
}

int exitCode = process.waitFor();
output.append("Exit code: " + exitCode).append("\n");
} catch (IOException | InterruptedException e) {
output.append("Error: " + e.getMessage()).append("\n");
}
return output.toString();
}


/* try {
Process process = Runtime.getRuntime().exec("python F:/HCLProgram/HclProgram/src/test.py");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return "pick";
} */
}



python code:
test.py

fromrobodk.robolinkimport*
fromrobodkimportrobolink,robomath
importsubprocess

# Connect to RoboDK
RDK=robolink.Robolink()


defApproaching_Pick():
Robot_Home_Pos()
Replace_Objects()
Pick_Approach()


defRobot_Home_Pos():
ref_frame= p[0.000000,0.000000,0.000000,0.000000,0.000000,0.000000]
set_tcp (p (0.000000,0.000000,0.120000,0.000000,0.000000,0.000000])
movej([0.000000, -1.570796, -1.570796,0.000000,1.570796,0.000000],accel_radss,speed_rads,0,0)


defReplace_Objects():
# Replace objects

# Subprogram Pick_Approach
defPick_Approach():
movej([0.000000, -1.570796, -1.570796,0.000000,1.570796,0.000000],accel_radss,speed_rads,0,0)# end trace
Rail_Pos_1()
movel([0.000000, -1.570796, -1.570796,1.570796,1.570796, -0.000000],accel_mss,speed_ms,0,0)
movel([-1.570796, -1.570796, -1.570796,1.570796,1.570796,0.042164],accel_mss,speed_ms,0,0)
movel([-3.141593, -1.570622, -1.570796,1.570796,1.570796, -0.000000],accel_mss,speed_ms,0,0)# end trace
Rail_Pos_0()
Open_Gripper()

# Subprogram Rail_Pos_1
defRail_Pos_1():
popup("Move axes to: this post only supports 6 joints","Message",False,False,blocking=False)


# Subprogram Rail_Pos_0
defRail_Pos_0():
popup("Move axes to: this post only supports 6 joints","Message",False,False,blocking=False)

# Subprogram Open_Gripper
defOpen_Gripper():
popup("Move axes to: this post only supports 6 joints","Message",False,False,blocking=False)

Approaching_Pick()



RE: python code is not working-MohammedKhadeer-02-16-2023

I have found a way to do it. Actually, before i was doing it in the wrong way...When i have already created a robot program in Robodk why do i have to call it again right .my bad i was generating the python code from the interface and calling it, which is wrong. Once, we have already created a code in robodk interface then we just need to call the name of that program in a python code. That's it.