[Python] EPOS4: VcsGetPositionIs and VcsGetVelocityIs always return 0 when called from...

Discussão em 'Python' iniciado por Stack, Junho 6, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to read position and velocity values from 4 Maxon EPOS4 50/5 motor controllers using Python with pythonnet (.NET wrapper). I have them connected via Gateway (RS232 + CAN). While I can successfully initialize the controllers and move them to positions, I can't get the actual position/velocity readings to work. The methods always return 0 or throw errors about parameter types. Here the libraries I'm using: import time import os, sys import ctypes import clr from EposCmd.Net.VcsWrapper import Device I also have EposCmd.Net.dll and EposCmd64.dll in the same directory as the program. I'm using Python 3.13 in VS Code on Windows 10 and the poythonnet is the latest version

    Here's the relevant part of my code. It is the same for the velocity (Device.VcsGetVelocityIs):

    def read_current_positions(keyHandle, node_ids):
    positions = {}

    for node_id in node_ids:
    try:
    # Initialize variables
    positionIs = 0
    errorCode = 0

    # Get the current position using the .NET wrapper method
    result = Device.VcsGetPositionIs(
    keyHandle,
    node_id,
    positionIs,
    errorCode
    )

    if result:
    positions[node_id] = positionIs
    else:
    positions[node_id] = f"Error reading position (ErrorCode: {errorCode})"

    except Exception as e:
    positions[node_id] = f"Failed to read position: {str(e)}"

    return positions


    I've attempted several approaches to handle the reference parameters:

    1. Using basic variables (int) - Returns zeros
    2. Using ctypes:

    positionIs = ctypes.c_long(0)
    errorCode = ctypes.c_ulong(0)


    Error: "No method matches given arguments for Device.VcsGetPositionIs: (<class 'int'>, <class 'int'>, <class 'ctypes.c_long'>, <class 'ctypes.c_ulong'>)"

    1. Using System.Int32/UInt32 arrays:

    positionIs = System.Int32[]
    errorCode = System.UInt32[]


    Error: "No method matches given arguments for Device.VcsGetPositionIs: (<class 'int'>, <class 'int'>, <class 'System.Int32[]'>, <class 'System.UInt32[]'>)"

    1. Trying to use clr.Reference:

    positionIs = clr.Reference[int](0)


    Error: "module 'clr' has no attribute 'Reference'"

    Expected Behavior


    The VcsGetPositionIs method should return the actual position of the motor. According to the EPOS Command Library documentation, the method signature is:

    bool VcsGetPositionIs(int KeyHandle, int NodeId, ref int PositionIs, ref uint ErrorCode)


    How can I properly pass reference parameters to the .NET method using pythonnet? What's the correct way to handle 'ref' parameters when calling EPOS Command Library methods from Python?

    Thank you for all the help you can give me!

    Continue reading...

Compartilhe esta Página