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

Real-time KUKA Robot Control Method Using RoboDK

#1
Hello, thank you for always helping me.
I would like to know how I can use RoboDK to give movement commands to KUKA robots in real time.
As far as I know, there is a way to execute the 'Move' command in RoboDK in the same way as clicking the 'Move Joints' button through the C3 bridge communication that I planted in RoboDK's kukabridge driver and KUKA robot controller.
But I want to keep the RoboDK's robot model moving in real time. For example, if RoboDK's robot model moves, the actual KUKA robot moves in the same way.
Then you get the same results as controlling a real KUKA robot in RoboDK.

I would really appreciate it if you could tell me how to achieve my goals.

The code below is an example that I have written to allow RoboDK and KUKA robots to move through command delivery in real time while communicating with each other:

Code:
import robodk.robomath
from robodk.robolink import *
from robodk.robomath import *
import time

linear_speed = 10
angular_speed = 180
joints_speed = 5
joints_accel = 40
is_stop = False


class rdk2kukaControl:
    def __init__(self):
        self.RDK = Robolink()
        self.robot = self.RDK.Item('KUKA KR 70 R2100')
        self.tool = self.robot.Tool()
        self.reference = self.RDK.Item('Baseline')
        self.tcp_obj = self.RDK.Item('tcp_obj')
        self.bbox = self.RDK.Item('bbox')
        self.current_joints = self.robot.SimulatorJoints()

        # bool
        self.is_collide = False
        self.within_bbox = True

        # Boundary limits
        self.min_x, self.max_x, self.min_y, self.max_y, self.min_z, self.max_z = [-90, 90, -90, 90, 10, 190]

        # Initial robot settings
        self.robot.setPoseFrame(self.reference)
        self.robot.setPoseTool(self.tool)
        self.robot.setSpeedJoints(joints_speed)

    def check_bbox(self):
        relative_pose = self.tcp_obj.PoseWrt(self.reference)
        kukaPose = Pose_2_KUKA(relative_pose)
        tcp_x, tcp_y, tcp_z = kukaPose[:3]

        if any([
            tcp_x < self.min_x, tcp_x > self.max_x,
            tcp_y < self.min_y, tcp_y > self.max_y,
            tcp_z < self.min_z, tcp_z > self.max_z
        ]):
            print("TCP out of range!!")
            self.within_bbox = False
            return True
        else:
            print("TCP within range.")
            self.within_bbox = True
            return False

    def collision_detection(self):
        if self.RDK.Collisions() > 0:
            print("Collided!!")
            self.is_collide = True
        else:
            print("is not Collided.")
            self.is_collide = False

    def order2kuka(self):
        start_time = time.time()
        joints = self.robot.SimulatorJoints()
        if self.current_joints != joints:
            print("Change joint values are: ", joints)
            self.robot.MoveJ(joints)
            print("Robot MoveJ")
            self.current_joints = joints

            # Execution time
            print(f"Execution time: {time.time() - start_time} seconds")
            time.sleep(0.004)

    def run(self):
        while True:

            if not self.is_collide and self.within_bbox:
                print("order2kuka")
                self.order2kuka()
            else:
                print("can't order2kuka!!")
                break

        print("rdk2kukaControl Program has ended.")


if __name__ == "__main__":
    kuka_controller = rdk2kukaControl()
    kuka_controller.run()
#2
To be able to run the commands on the real robot you should call Connect or change the so called Run Mode to run on the robot. You can find more information here:
https://robodk.com/doc/en/PythonAPI/exam...rogramming

More precisely, the following code will help you:
Code:
    # Connect to the robot using default IP
    success = robot.Connect()  # Try to connect once
    #success robot.ConnectSafe() # Try to connect multiple times
    status, status_msg = robot.ConnectedState()
    if status != ROBOTCOM_READY:
        # Stop if the connection did not succeed
        print(status_msg)
        raise Exception("Failed to connect: " + status_msg)

    # This will set to run the API programs on the robot and the simulator (online programming)
    RDK.setRunMode(RUNMODE_RUN_ROBOT)
    # Note: This is set automatically when we Connect() to the robot through the API
  




Users browsing this thread:
1 Guest(s)