Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

python code is not working

#1
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

from robodk.robolink import *
from robodk import robolink, robomath
import subprocess

# Connect to RoboDK
RDK = robolink.Robolink()


def Approaching_Pick():
    Robot_Home_Pos()
    Replace_Objects()
    Pick_Approach()


    def Robot_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)


    def Replace_Objects():
    # Replace objects

    # Subprogram Pick_Approach
     def Pick_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
    def Rail_Pos_1():
        popup("Move axes to: this post only supports 6 joints","Message",False,False,blocking=False)


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

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

Approaching_Pick()


Attached Files
.rdk   1_Meter-Station_With_Objects_Only.rdk (Size: 6.68 MB / Downloads: 137)
#2
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.
  




Users browsing this thread:
1 Guest(s)