torayeff / fanucpy

Python Interface for FANUC robots
Apache License 2.0
109 stars 29 forks source link

Need to access to Digital Ports #23

Closed sansoy closed 1 year ago

sansoy commented 1 year ago

Hi, I'm using Robotiq's Dual Adapter for two types of sanders and need to activate/deactivate both of them separately.

I'm trying to figure out how to instantiate two separate DO (not RDO), ie 101 & 104.

I noticed in robot.py the "setdo" command for the gripper so i created set/get methods for DO, ie

def get_do(self, do_num: int):
    """Get DO value.
    Args:
        do_num (int): DO number.
    Returns:
        do_value: DO value.
    """
    cmd = f"getdo:{do_num}"
    _, do_value = self.send_cmd(cmd)
    do_value = int(do_value)
    return do_value

def set_do(self, do_num: int, val: bool):
    """Sets DO value.
    Args:
        do_num (int): DO number.
        val (bool): Value.
    """
    if val:
        val = "true"
    else:
        val = "false"

    cmd = "setdo" + f":{self.ee_DO_num }:{val}"
    self.send_cmd(cmd)

However, when run it I get the following message "WRONG COMMAND setdo:104:true".

Any thoughts/help would be appreciated. Sabri

torayeff commented 1 year ago

@sansoy It should be relatively straightforward. You also need to add similar functions as shown in the following files: https://github.com/torayeff/fanucpy/blob/4fe61fcab11ed73aa0eb6daaca57c209ff741c0e/src/fanuc-driver/mappdk_cmd.kl#L442

and

https://github.com/torayeff/fanucpy/blob/4fe61fcab11ed73aa0eb6daaca57c209ff741c0e/src/fanuc-driver/mappdk_cmd.kl#L580

At some point, I might extend fanucpy with extra features, but unfortunately, I am a little busy now. However, the library should be relatively easy to extend. If you do implement the above functionalities, please submit a pull request.

sansoy commented 1 year ago

Hi Agajan, Thanks for the guidance. I'm new to KAREL so I have been spending time learning the program.

It looks like DOUT is the command i need to get/set values for digital pins, so I added the following to mappdk_cmd.kl

ROUTINE GET_DO(cmd: STRING): STRING

-- Function: Gets digital out. -- cmd string should follow the below format: -- 'getdo:n' -- n: a 3 digit number

-- Arguments: -- cmd [IN]: command string.

-- Return value: response string.

VAR do_num: INTEGER BEGIN -- Get DO number CNV_STR_INT(SUB_STR(cmd, 8, 3), do_num)

IF DOUT[do_num] = TRUE THEN
    DOUT[do_num] = TRUE
    resp = '0:1'
    RETURN(resp)
ENDIF

IF DOUT[do_num] = FALSE THEN
    DOUT[do_num] = FALSE
    resp = '0:0'
    RETURN(resp)
ENDIF

resp = '1:wrong-do-value'
RETURN(resp)

END GET_DO

ROUTINE SET_DO(cmd: STRING): STRING

-- Function: Sets digital out. -- cmd string should follow the below format: -- 'setdo:n:value' -- n: a triple digit number -- value: 'true' or 'false' (lowercase)

-- Arguments: -- cmd [IN]: command string.

-- Return value: response string.

VAR do_num: INTEGER do_val: STRING[8] BEGIN -- Get DO number CNV_STR_INT(SUB_STR(cmd, 8, 3), do_num)

-- Get DO value
do_val = SUB_STR(cmd, 12, STR_LEN(cmd) - 9)

IF do_val = 'true' THEN
    DOUT[do_num] = TRUE
    resp = '0:success'
    RETURN(resp)
ENDIF

IF do_val = 'false' THEN
    DOUT[do_num] = FALSE
    resp = '0:success'
    RETURN(resp)
ENDIF

resp = '1:wrong-do-value'
RETURN(resp)

END SET_DO

-- setdo: set Digital Output
IF SUB_STR(cmd, 1, 5) = 'setdo' THEN
    resp = SET_DO(cmd)
    RETURN(TRUE)
ENDIF

-- getdo: get Digital Output
IF SUB_STR(cmd, 1, 5) = 'getdo' THEN
    resp = GET_DO(cmd)
    RETURN(TRUE)
ENDIF

Now I'm unclear how to compile these changes. Is this source file used in the compilation of mappdk_server.pc?

Sabri

On Fri, May 19, 2023 at 3:58 PM Agajan Torayev @.***> wrote:

@sansoy https://github.com/sansoy It should be relatively straightforward. You also need to add similar functions as shown in the following files:

https://github.com/torayeff/fanucpy/blob/4fe61fcab11ed73aa0eb6daaca57c209ff741c0e/src/fanuc-driver/mappdk_cmd.kl#L442

and

https://github.com/torayeff/fanucpy/blob/4fe61fcab11ed73aa0eb6daaca57c209ff741c0e/src/fanuc-driver/mappdk_cmd.kl#L580

At some point, I might extend fanucpy with extra features, but unfortunately, I am a little busy now. However, the library should be relatively easy to extend. If you do implement the above functionalities, please submit a pull request.

— Reply to this email directly, view it on GitHub https://github.com/torayeff/fanucpy/issues/23#issuecomment-1555304047, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACV24M55XAXNAL2UJRUAWDXG7UHDANCNFSM6AAAAAAYIBT4UE . You are receiving this because you were mentioned.Message ID: @.***>

torayeff commented 1 year ago

@sansoy you only need to compile mappdk_server.kl file which will generate mappdk_server.pc file. And you can compile it using Roboguide. Let me know if you have any issues and I will try to compile on my side.

sansoy commented 1 year ago

thanks for quick reply!

Unfortunately my company didn't buy roboguide. Is there another compiler we can use? Sabri

On Tue, May 23, 2023 at 10:34 AM Agajan Torayev @.***> wrote:

@sansoy https://github.com/sansoy you only need to compile mappdk_server.kl file which will generate mappdk_server.pc file. And you can compile it using Roboguide. Let me know if you have any issues and I will try to compile on my side.

— Reply to this email directly, view it on GitHub https://github.com/torayeff/fanucpy/issues/23#issuecomment-1559793955, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACV24MLR633Z3IFR67Q6STXHTRINANCNFSM6AAAAAAYIBT4UE . You are receiving this because you were mentioned.Message ID: @.***>

torayeff commented 1 year ago

You only need the ktrans command from Roboguide. Maybe you can try a trial version of the Roboguide, and the ktrans command should be available then via Windows CMD. Otherwise I will try compiling later today when I reach my computer.

torayeff commented 1 year ago

@sansoy I have released a new version of fanucpy 0.1.12. Please update your package and replace the .pc files in your robot controller with the new versions. Now it can set/get DOUT value with a single integer (check the README.md).

gavanderhoorn commented 1 year ago

I wanted to wait until you solved this here, locally, but now that you have, I wanted to mention gavanderhoorn/comet_rpc.

Depending on which controller series you want to support, it could offer a nice(r) way to interact with IO on the Fanuc controller (it would certainly be faster: typical rtt for setting a DO is about 10 to 15 ms, Karel is probably much slower).

torayeff commented 1 year ago

@gavanderhoorn, thanks for this link. Yes, I noticed when testing setting/getting DOUT with KAREL is slower compared to other functions.

At some point (when I finalize my thesis), I want to optimize this library. When optimising the code, I will keep your suggestion (and this one https://github.com/torayeff/fanucpy/issues/15#issuecomment-1465696874) in mind.

sansoy commented 1 year ago

you rock! will install and test tomorrow.

On Tue, May 23, 2023 at 2:04 PM Agajan Torayev @.***> wrote:

@sansoy https://github.com/sansoy I have released a new version of fanucpy 0.1.12. Please update your package and replace the .pc files in your robot controller with the new versions. Now it can set/get DOUT value with a single integer (check the README.md).

— Reply to this email directly, view it on GitHub https://github.com/torayeff/fanucpy/issues/23#issuecomment-1560051674, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACV24LZXOKPBJX3WXPPMN3XHUJ4BANCNFSM6AAAAAAYIBT4UE . You are receiving this because you were mentioned.Message ID: @.***>