bnjmnp / pysoem

Cython wrapper for the Simple Open EtherCAT Master Library
MIT License
96 stars 37 forks source link

DC SYNC and PDO Loop? #79

Closed tom9672 closed 1 year ago

tom9672 commented 2 years ago

I tried pp mode withouting using dc_sync, that fine. (tried pp works good with or without dc_sync. Don't know the usage of dc_sync) But now i'm trying you csp mode. it seems doesn't work without setting dc_sync.

    def setup(self):
        self._master.open(self._port)
        if not self._master.config_init() > 0:
            self._master.close()
            raise HandleError('no slave found')

        self.slave1 = self._master.slaves[0]
        self.slave1.config_func = self._device_config_func
        self._master.config_map()

        # **How to set the dc sync? Is it ok to only add this two lines?** 
        self._master.config_dc()
        self.slave1.dc_sync(1,1000000)  

        if self._master.state_check(pysoem.SAFEOP_STATE, 50000) != pysoem.SAFEOP_STATE:
            self._master.close()
            raise HandleError('not all slaves reached SAFEOP state')

        self._master.state = pysoem.OP_STATE

        self.check_thread = threading.Thread(target=self._check_thread)
        self.check_thread.start()
        self.proc_thread = threading.Thread(target=self._processdata_thread)
        self.proc_thread.start()

        # send one valid process data to make outputs in slaves happy
        self._master.send_processdata()
        self._master.receive_processdata(2000)

        self._master.write_state()
        self.all_slaves_reached_op_state = False

The test_csp() not works.

    def test_csp(self):
        output_data = OutputPdo()
        output_data.Mode_Operation = 8 # for csp mode
        for cmd in [15]:
            output_data.Control_Word = cmd
            self.slave1.output = bytes(output_data)
            time.sleep(0.02)
            time.sleep(1)

        aa = 100 
        while True:
            try:
                time.sleep(0.01)
                output_data.Target_Position_pp = aa
                self.slave1.output = bytes(output_data)
                aa += 100
            except KeyboardInterrupt:
                break
bnjmnp commented 2 years ago

Yes, for CSP mode DC synchronization might be required, it makes sens there. But it could be that on drives from another vendor DC synchronization might not be required. With Python/PySOEM exact DC synchronization is not possible, because we cannot achive realtime.

tom9672 commented 2 years ago

I'm trying to get the motor to run at variable velocity , and the positioning is precise when changing velocity. output I tried to use PP mode with Instantly update and PV mode. it can achieve continuous speed change without dropping zero. but the position is not very accurate, the reason: for example, I want change velocity from 100 to 200, while position is 10000. In pp Instantly update and PV, I have to check if the current position is at a range of target postion. I using current_position > 10000 or current_position in range(9900,11000), which make the position of changing velocity not precise.

For more precise positioning, I reduce the gap of pdo loop from 0.01 to 0.001. It does help the positioning to be more precise. But not enough...

PP mode with not immediately updated, the position of changing velocity is precise but it will make velocity ​​decelerates to zero before accelerating to target speed.

Is there a way to make the make the target position of changing velocity as precise as much. using another running mode of changing the program logic?

Thanks so much.

tom9672 commented 1 year ago

I changed a window PC to a raspberry pi on linux with rt-kernel and one cpu isolation. Now I can reduce PDO loop time gap, and not get incorrect wkc.

I continue to reduce the time sleep of PDO loop and position monitor loop. While I set the time sleep of this two loop to 0.00000001 and smaller, each adjacent position monitoring feedback value point has more and more the same value, that means the PDO loop can’t get the current position at such small time sleep gap, right?

At this situation, I run the motor at 3000rpm, the biggest position gap is around 200 to 300(10000=1round). This is not good enough…

So, it seems means, at free run mode with PP or PV mode, even the PDO loop is quick, but maybe some other reasons, still unable to monitor the real time position feedback.

tom9672 commented 1 year ago

Find the reason, cause the device I’m using support the smallest PDO time gap is 250 μs.