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

Read speed from robot

#1
Hello!

My Setup: KRC4 controller, and Kuka KR16-2 robot.

I'm trying to read the speed (prog.speed_mms) from my robot, as I would like to change the speed from the TCP (Tool Center Point) when it is at the maximum speed, but keep the velocities when it's below 100 mm/s. Can anyone help me with this?
In my code, I'm attempting to modify the jointSpeeds when TCP Speed is above 100mm/s. Here's what I have so far:


Thank you in advance!
Stefan


Code:
# Example to iteratively look for the speed instruction (INS_SPEED) and update it to 75 mm/s.
from robolink import *

RDK=Robolink()
prog = RDK.ItemUserPick('Machining2', ITEM_TYPE_PROGRAM) #Open the right program by name

# Iterate over all instructions in the program
for i in range(prog.InstructionCount()):
ins_name, ins_type, *_ = prog.Instruction(i)

# Check if it is a "set speed" instruction
if ins_type == INS_TYPE_CHANGESPEED:
print("Updating instruction %i" % i)

if prog.speed_mms >= 100
# Delete the instruction
prog.InstructionDelete(i)

# Select the previous instruction (any new instructions will be added afterwards)
prog.InstructionSelect(max(0,i-1))

# Add the new speed instruction
prog.setSpeed(*,100)
#2
The code you shared looks good. Are you having any issues with it?

You should use -1 with setSpeed for the speeds you don't want to modify:
prog.setSpeed(*,100)

Also, it will be faster if you modify existing instructions using setParam:
//www.sinclairbody.com/doc/en/PythonAPI/exam...structions

Example:
Code:
while ins_id < ins_count:
# Get specific data related to an instruction
# This operation always retuns a dict (json)
instruction_dict = prog.setParam(ins_id)

# Print instruction data
#indented_values = json.dumps(instruction_dict, indent=4)
print("\n\nInstruction: " + str(ins_id))
print(instruction_dict)

# Note: The type is unique for each instruction and can't be changed.
# However, setting the Type value to -1 will delete the instruction (same as InstructionDelete())
if instruction_dict['Type'] == INS_TYPE_CHANGESPEED:
# Reduce speeds:
newvalues = {'Speed': 50}
if instruction_dict['Speed'] > 50:
new_speed = 0.8 * instruction_dict['Speed']
newvalues = {'Speed': new_speed}
print("Reducing speed to: %.3f" % new_speed)

# Update instruction data
prog.setParam(ins_id, newvalues)
# RoboDK may change the instruction name if you don't provide a new name
#3
Thank you very much for your help Albert!
The link you provided solved my issue.

Nevertheless, the -1 did not work.

It seems that the setParam instruction modifies a Json File, could you tell me where this file is located?
By modifying this Json file, are you able to correct the path of the robot? For example: move all Z +20mm?

Thank you in advance!




Users browsing this thread:
1 Guest(s)