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

Moving to poses and changing coordinate systems

#1
My lack of math skills is currently on display...

I have a CSV file that has XYZ values as well as three vectors (ijk of each).  The code snippet below will read the lines and create targets.  The targets look as expected - the AddTarget method takes care of the required coordinate system.  

However, I do NOT want a couple thousand targets so I need to create the MoveL instructions from the script without targets.  That means, I think, that I have to move the pose as read from the file to the reference frame myself.  My attempt has failed and the script is creating targets on the other side of the robot that apparently are not reachable.

How do I move the coordinates from the robot base (world CS) to the reference frame?

This is how to NOT do it: 
positionInFrame = matrix * framePose

Code:
<snip>

Frame = Robot.getLink(robolink.ITEM_TYPE_FRAME)
Tool = Robot.getLink(robolink.ITEM_TYPE_TOOL)
framePose = Frame.PoseAbs()


for n in range( len(AllLines) ):
    Line = AllLines[n]
    print(f'Line {n} --> {Line}')
    Pieces = Line.strip().split(',')

    try:
        x     = float( Pieces[0].strip() )
        y     = float( Pieces[1].strip() )
        z     = float( Pieces[2].strip() )

        V1i   = float( Pieces[3].strip() )
        V1j   = float( Pieces[4].strip() )
        V1k   = float( Pieces[5].strip() )

        V2i   = float( Pieces[6].strip() )
        V2j   = float( Pieces[7].strip() )
        V2k   = float( Pieces[8].strip() )

        V3i   = float( Pieces[9].strip() )
        V3j   = float( Pieces[10].strip() )
        V3k   = float( Pieces[11].strip() )

        # These targets are in the correct position
        matrix = robomath.Mat(rows=4, ncols=4)
        matrix = matrix.setPos([x,y,z])
        matrix = matrix.setVX([V2i, V2j, V2k])
        matrix = matrix.setVY([V3i, V3j, V3k])
        matrix = matrix.setVZ([V1i, V1j, V1k])
        newTarget = RDK.AddTarget(f'Index {n}', Frame, Robot)
        newTarget.setPose(matrix)

        # Convert from World CS to work object CS
        positionInFrame = matrix * framePose
        NewProgram.MoveL(positionInFrame)

    except Exception as Err:
        print(f'Error on line {n+1} of the CSV file:')
        print( str(Err) )
#2
There are two ways to add targets to programs, by using poses (1) and by using target items (2):
  1. Using poses: If you provide a pose (Mat object) to a program MoveJ or MoveL instruction, it will create a new target embedded with your program (not a link).
  2. Using target items: If you use AddTarget it will create a new target object. Once you have a target, you can pass it to the MoveL call to move to that target item. Adding a new target to your project may require you to use setParent right after to attach it to the right coordinate system (for example: newTarget.setParent(frame)  )
You are adding targets twice with the script you shared.

Therefore, I recommend you to change your script to the following:
Code:
Frame = Robot.getLink(robolink.ITEM_TYPE_FRAME)
Tool = Robot.getLink(robolink.ITEM_TYPE_TOOL)
framePose = Frame.PoseAbs()
# Create a new program:
NewProgram = RDK.AddProgram("MyNewProgram", Robot)
# Make sure your program sets the desired tool and frame
NewProgram.setPoseTool(Tool)
NewProgram.setPoseFrame(Frame)


for n in range( len(AllLines) ):
    Line = AllLines[n]
    print(f'Line {n} --> {Line}')
    Pieces = Line.strip().split(',')
    try:
        x     = float( Pieces[0].strip() )
        y     = float( Pieces[1].strip() )
        z     = float( Pieces[2].strip() )
        V1i   = float( Pieces[3].strip() )
        V1j   = float( Pieces[4].strip() )
        V1k   = float( Pieces[5].strip() )
        V2i   = float( Pieces[6].strip() )
        V2j   = float( Pieces[7].strip() )
        V2k   = float( Pieces[8].strip() )
        V3i   = float( Pieces[9].strip() )
        V3j   = float( Pieces[10].strip() )
        V3k   = float( Pieces[11].strip() )
        # These targets are in the correct position
        matrix = robomath.Mat(rows=4, ncols=4)
        matrix = matrix.setPos([x,y,z])
        matrix = matrix.setVX([V2i, V2j, V2k])
        matrix = matrix.setVY([V3i, V3j, V3k])
        matrix = matrix.setVZ([V1i, V1j, V1k])

        # Move to the new target pose (uses the last frame and tool that have been set)       
        NewProgram.MoveL( matrix )

    except Exception as Err:
        print(f'Error on line {n+1} of the CSV file:')
        print( str(Err) )
  




Users browsing this thread:
1 Guest(s)