Code Monkey home page Code Monkey logo

Comments (9)

bnjmnp avatar bnjmnp commented on August 16, 2024 1

Hi @bolp70 ,

I'm not 100% sure what you like to do. But if you want to select 0x1A00 and 0x1A01 in 0x1C13 you need to do it this way:

map_1c13_bytes = struct.pack('BxHH', 1, 0x1A00, 0x1A01)
slave.sdo_write(0x1c13, 0, map_1c13_bytes, True)

It is just one write to 0x1c13. Note it is now 'BxHH' instead of 'BxH'.

I don't know how your ESI looks but from your input you could do something like this (for the InputPdo):

class InputPdo(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        # PDO_0 0x1A00
        ('Position_actual_value_DUMMY', ctypes.c_int32),
        ('digital_input', ctypes.c_uint32),
        ('statusword_DUMMY', ctypes.c_uint16),

        # PDO_0 0x1A01
         ('Position_actual_value', ctypes.c_int32),
         ('velocity_actual_consigne', ctypes.c_int32),
         ('couple_actual_consigne', ctypes.c_int16),
         ('statusword', ctypes.c_uint16),

    ]

Problem here is that you have names twice, but you could give each a unique name like I did above (notice the statusword_DUMMY).

Second option would be nested "Structures".

class InputPdo0x1A00(ctypes.Structure)
    _pack_ = 1
    _fields_ = [
        # PDO_0 0x1A00
        ('Position_actual_value', ctypes.c_int32),
        ('digital_input', ctypes.c_uint32),
        ('statusword', ctypes.c_uint16),
    ]

class InputPdo0x1A01(ctypes.Structure)
    _pack_ = 1
    _fields_ = [
        # PDO_0 0x1A01
         ('Position_actual_value', ctypes.c_int32),
         ('velocity_actual_consigne', ctypes.c_int32),
         ('couple_actual_consigne', ctypes.c_int16),
         ('statusword', ctypes.c_uint16),
    ]

class InputPdo(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ('pdo_0', InputPdo0x1A00),
        ('pdo_1', InputPdo0x1A01),
    ]

And access the elements like this:

input = InputPdo.from_buffer_copy(slave.input)
print(input.pdo_0.Position_actual_value)
print(input.pdo_1.velocity_actual_consigne)

But I did not test this.

from pysoem.

bnjmnp avatar bnjmnp commented on August 16, 2024

Hi @bolp70,

take a look at issue #30, I guess reading through this will get you a bit further.
The TMCM-1617 and TMCM-3213 discussed there also implement the CiA 402 device profile.

from pysoem.

bolp70 avatar bolp70 commented on August 16, 2024

from pysoem.

bnjmnp avatar bnjmnp commented on August 16, 2024

Sorry I didn't get you attachment. You can attach files if you answer directly on GitHub (at issue #33).

The TMCM-1617 from my example has only RxPD1 and TxPD1, so the PDO selection object 0x1C12 and 0x1C13 is fixed (to 0x1600 and 0x1A00).

It seems that you can select other PDO configurations, thus you can write for example 0x1601 into subindex 1 of object 0x1C12.
In one of the examples you can see how to do this for a Beckhoff device:

def el3002_setup(self, slave_pos):

There I set 0x1C12 to 0. With that I don't have any RxPDO as I don't want to send any commands to the device in this example.

Note: It is really the best to update 0x1C12/0x1C13 in these setup-functions.

In your code you could try something like this:

        map_1c12_bytes = struct.pack('BxH', 1, 0x1601)
        slave.sdo_write(0x1c12, 0, map_1c12_bytes, True)
        
        map_1c13_bytes = struct.pack('BxH', 1, 0x1A01)
        slave.sdo_write(0x1c13, 0, map_1c13_bytes, True)

These SDO-writes update subindex 0 and subindex 1 at the same time.

from pysoem.

bnjmnp avatar bnjmnp commented on August 16, 2024

Hi @bolp70,

were you able to solve this?

from pysoem.

bolp70 avatar bolp70 commented on August 16, 2024

from pysoem.

bolp70 avatar bolp70 commented on August 16, 2024

hi bnjmnp I tried with your code, it works.
As you can see I am using PDO RTx 2.
It seems to me that we can use several PDOs at the same time?

map_1c13_bytes = struct.pack('BxH', 1, 0x1A00)
slave.sdo_write(0x1c13, 0, map_1c13_bytes, True)
to
map_1c13_bytes = struct.pack('BxH', 1, 0x1A01)
slave.sdo_write(0x1c13, 1, map_1c13_bytes, True)

if i do this, how does it work for class InputPdo and class OutputPdo ?

class InputPdo(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        # PDO_0 0x1A00
        #('Position_actual_value', ctypes.c_int32),
        #('digital_input', ctypes.c_uint32),
        #('statusword', ctypes.c_uint16),

        # PDO_0 0x1A01
         ('Position_actual_value', ctypes.c_int32),
         ('velocity_actual_consigne', ctypes.c_int32),
         ('couple_actual_consigne', ctypes.c_int16),
         ('statusword', ctypes.c_uint16),

    ]

class OutputPdo(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        # PDO_0 0x1600
        #('Axe_target_position', ctypes.c_int32),
        #('digital_output', ctypes.c_uint32),
        #('controlword', ctypes.c_uint16),

        # PDO_0 0x1601
         ('Axe_target_velocity', ctypes.c_int32),
         ('controlword', ctypes.c_uint16),

    ]

def convert_input_data(data):
    return InputPdo.from_buffer_copy(data)

class BasicExample:

    ZERRO_DRIVER_ID = 0x5a65726f #id du fabricant 
    axes = 0x00029252 #id des moteur 
    EL1259_PRODUCT_CODE = 0x04eb3052



    def __init__(self, ifname):
        self._ifname = "enp3s0"
        self._pd_thread_stop_event = threading.Event()
        self._ch_thread_stop_event = threading.Event()
        self._actual_wkc = 0
        self._master = pysoem.Master()
        self._master.in_op = False
        self._master.do_check_state = False
        SlaveSet = namedtuple('SlaveSet', 'name product_code config_func')
        self._expected_slave_layout = {0: SlaveSet('Axe1', self.axes, self.axes_setup),
                                       1: SlaveSet('Axe2', self.axes, self.axes_setup),
                                       2: SlaveSet('Axe3', self.axes, self.axes_setup),
                                       3: SlaveSet('Axe4', self.axes, self.axes_setup),
                                       4: SlaveSet('Axe5', self.axes, self.axes_setup),
                                       5: SlaveSet('Axe6', self.axes, self.axes_setup)}
                                       #2: SlaveSet('EL1259', self.EL1259_PRODUCT_CODE, self.axes_setup)

    def axes_setup(self, slave_pos):
        slave = self._master.slaves[slave_pos]
       
        map_1c12_bytes = struct.pack('BxH', 1, 0x1601)
        slave.sdo_write(0x1c12, 0, map_1c12_bytes, True)

        map_1c13_bytes = struct.pack('BxH', 1, 0x1A01)
        slave.sdo_write(0x1c13, 0, map_1c13_bytes, True)

thank you for your help

from pysoem.

bnjmnp avatar bnjmnp commented on August 16, 2024

Hi @bolp70,
did you had any success with the project you were working on here? I would be happy to hear.

from pysoem.

bnjmnp avatar bnjmnp commented on August 16, 2024

Closed due to inactivity of the OP.

from pysoem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.