python method from matlab object
Here is the problem I have,
I have a python class, which contain properties that are memebers of specific class, typically to rotate a motor.
The class is defined as below, it uses the pytrinamic for the PD42-1370 motors: https://github.com/analogdevicesinc/PyTrinamic
I have made a wrapper class of the example provided for the Pytrinamic: https://github.com/analogdevicesinc/PyTrinamic/blob/master/examples/modules/TMCM1370/TMCL/rotate_demo.py
"""
pd42_1370.py wrapper to connect to the PD42-X-1370 stepper motor
"""
import pytrinamic
from pytrinamic.connections import ConnectionManager
from pytrinamic.connections import UsbTmclInterface
from pytrinamic.modules import TMCM1370
class PD42_1370():
def __init__(self,com_port,baudrate):
self.com_port = com_port
self.baudrate = baudrate
options = "–interface serial_tmcl –port "+ str(self.com_port)+ " –data_rate "+str(self.baudrate)
self.connection_manager = ConnectionManager(options)
self.interface = self.connection_manager.connect()
print("connected")
self.module = TMCM1370(self.interface)
print("module added")
self.motor = self.module.motors[0]
def disconnect(self):
self.connection_manager.disconnect()
print("disconnected")
def rotateRight(self,speed):
self.motor.rotate(speed)
my MATLAB code is:
py.importlib.import_module(‘pd42_1370’)
ax = py.pd42_1370.PD42_1370(‘COM5’,9600)
ax.rotateRight(int32(10000000))
ax.disconnect()
It is working really fine. But instead of sending the command:
ax.rotateRight(int32(10000000))
I would like to write it:
ax.motor.rotate(int32(100000000))
this later throw back an error:
Unrecognized method, property, or field ‘rotate’ for class ‘py.pytrinamic.modules.TMCM1370._MotorTypeA’.
I cannot figure out what is wrong.
If this could be sorted, then it would help by using direct calls to python, rather than keeping developping the wrapper.Here is the problem I have,
I have a python class, which contain properties that are memebers of specific class, typically to rotate a motor.
The class is defined as below, it uses the pytrinamic for the PD42-1370 motors: https://github.com/analogdevicesinc/PyTrinamic
I have made a wrapper class of the example provided for the Pytrinamic: https://github.com/analogdevicesinc/PyTrinamic/blob/master/examples/modules/TMCM1370/TMCL/rotate_demo.py
"""
pd42_1370.py wrapper to connect to the PD42-X-1370 stepper motor
"""
import pytrinamic
from pytrinamic.connections import ConnectionManager
from pytrinamic.connections import UsbTmclInterface
from pytrinamic.modules import TMCM1370
class PD42_1370():
def __init__(self,com_port,baudrate):
self.com_port = com_port
self.baudrate = baudrate
options = "–interface serial_tmcl –port "+ str(self.com_port)+ " –data_rate "+str(self.baudrate)
self.connection_manager = ConnectionManager(options)
self.interface = self.connection_manager.connect()
print("connected")
self.module = TMCM1370(self.interface)
print("module added")
self.motor = self.module.motors[0]
def disconnect(self):
self.connection_manager.disconnect()
print("disconnected")
def rotateRight(self,speed):
self.motor.rotate(speed)
my MATLAB code is:
py.importlib.import_module(‘pd42_1370’)
ax = py.pd42_1370.PD42_1370(‘COM5’,9600)
ax.rotateRight(int32(10000000))
ax.disconnect()
It is working really fine. But instead of sending the command:
ax.rotateRight(int32(10000000))
I would like to write it:
ax.motor.rotate(int32(100000000))
this later throw back an error:
Unrecognized method, property, or field ‘rotate’ for class ‘py.pytrinamic.modules.TMCM1370._MotorTypeA’.
I cannot figure out what is wrong.
If this could be sorted, then it would help by using direct calls to python, rather than keeping developping the wrapper. Here is the problem I have,
I have a python class, which contain properties that are memebers of specific class, typically to rotate a motor.
The class is defined as below, it uses the pytrinamic for the PD42-1370 motors: https://github.com/analogdevicesinc/PyTrinamic
I have made a wrapper class of the example provided for the Pytrinamic: https://github.com/analogdevicesinc/PyTrinamic/blob/master/examples/modules/TMCM1370/TMCL/rotate_demo.py
"""
pd42_1370.py wrapper to connect to the PD42-X-1370 stepper motor
"""
import pytrinamic
from pytrinamic.connections import ConnectionManager
from pytrinamic.connections import UsbTmclInterface
from pytrinamic.modules import TMCM1370
class PD42_1370():
def __init__(self,com_port,baudrate):
self.com_port = com_port
self.baudrate = baudrate
options = "–interface serial_tmcl –port "+ str(self.com_port)+ " –data_rate "+str(self.baudrate)
self.connection_manager = ConnectionManager(options)
self.interface = self.connection_manager.connect()
print("connected")
self.module = TMCM1370(self.interface)
print("module added")
self.motor = self.module.motors[0]
def disconnect(self):
self.connection_manager.disconnect()
print("disconnected")
def rotateRight(self,speed):
self.motor.rotate(speed)
my MATLAB code is:
py.importlib.import_module(‘pd42_1370’)
ax = py.pd42_1370.PD42_1370(‘COM5’,9600)
ax.rotateRight(int32(10000000))
ax.disconnect()
It is working really fine. But instead of sending the command:
ax.rotateRight(int32(10000000))
I would like to write it:
ax.motor.rotate(int32(100000000))
this later throw back an error:
Unrecognized method, property, or field ‘rotate’ for class ‘py.pytrinamic.modules.TMCM1370._MotorTypeA’.
I cannot figure out what is wrong.
If this could be sorted, then it would help by using direct calls to python, rather than keeping developping the wrapper. python, trinamic, class MATLAB Answers — New Questions