Addressing the points via number variable


#1

I have Points table with 351 different positions stored in the robot (InitialPose - P350). I’d like to use MovJ and MovP commands to move the robot among these positions. I have a holding register in PLC where requested number of position is stored (1 - 350). I want to concatenate this number with “P” to create a pointer to a motion point in the Points table (e.g. P1).

I’m trying to do it via Lua script, see here:

local PositionNumber_Raw = GetHoldRegs(ID, 1, 1, “U16”)
local PositionNumber = math.floor(PositionNumber_Raw[1])
local RequestedPosition = “P” … PositionNumber (which creates string “P1”)

–Move the robot to requested position
MovJ(RequestedPosition)
Sync()

In this case I get the error message “No input parameters forr MovJ instruction”.

If I use something like this:

if PositionNumber == 1 then
MovJ(P1)
Sync()
end

…it works perfectly.

Where do I do the mistake? Where’s the difference between “P1” and this P1? How can I covert string “P1” to motion point pointer P1? It’s quite clear repeating the if - then - sequence for each of these 351 positions makes the code long and confusing.

Thanks for help.


#2

As usually, I’m going to reply to myself…
The robot positions in Points table are considered global valuables, therefore are accessible with the help of _G parameter. Below is the code that can access any position in the Points table.

–get the requested position from PLC
local PositionNumber_Raw = GetHoldRegs(ID, 1, 1, “U16”)

–Convert the position to a pointer for the Points table
local PositionNumber = math.floor(PositionNumber_Raw[1])
local RequestedPosition = _G[“P” … PositionNumber]

–Move the robot to requested position
MovJ(RequestedPosition)
Sync()

This works perfectly.

Of course, there is nothing about it in the MG400 docu, one must search in the Net for answers.


#3

:smile:very good Thank you for your reply