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

Automatically Set Speed in multiple places in curve following program

#1
Hello, 

I am currently working on a curve following project in RoboDK and the curve was imported from SolidWorks. 

The curve contains more than 1,000 points and I want to set the multiple speeds (and accelerations) at certain different segments of the curve. 
I could manually set the speed by going to the certain points and right click and insert the 'Set Speed' command. 
However, this process takes very long time and not very user friendly. 
I am wondering, is there a way by using python script to insert the 'set speed' command to certain points automatically? Like there is a for-loop to insert the 'Set Speed' and 'Set acceleration' values into 50, 100, 150, 200 ..... points respectively?

   

Thank you, 

Ken Tang
#2
Yes, you can. You can add a new python program and write a script to iterate over every element in the program and insert setspeed instructions every 50 elements. You would need to write something like the snippet I have attached below.


Code:
RDK=Robolink()
prog = RDK.Item('Top_fwd', ITEM_TYPE_PROGRAM) #Open the right program by name
# First, iteratively look for the speed instruction (INS_SPEED)
SpeedChangePoint = 50 # Change speed every 50 instructions for example
i = 1
#Adding two new instructions will put the index off by two every time
offset = 0
while (i+offset)< prog.InstructionCount():
   #ins_type, = prog.Instruction(i)
   ins_nom, ins_type, move_type, isjointtarget, pose, joints = prog.Instruction(i)
   if ( (i % SpeedChangePoint) == 0): #Every SpeedChangePoint instructions:
       # Select the previous instruction (make sure we don't have a -1 index)
       prog.InstructionSelect(i+offset)
       prog.setSpeed(1000,-1,500,-1) #Add the set speed instruction
       offset = offset + 1 #Increase offset from original index by two because two instructions were added
   i = i + 1 #Increment index
Collapse



If you simply want to change the value of per-existing setspeed instructions, then the code below should be along the lines of what you want.


In order to run this code you will need the latest version of robodk as InstructionDelete was only added recently.
You can get the latest version from https://robodk.com/download

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('Select a program', 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)
       
       # 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(75)
  




Users browsing this thread:
1 Guest(s)