You are here

Setup FOC automaticly without vesc tool ihm

1 post / 0 new
NATUITION
NATUITION's picture
Offline
Last seen: 1 week 16 hours ago
VESC Free
Joined: 2019-09-27 20:56
Posts: 8
Setup FOC automaticly without vesc tool ihm

Hello,

I try to setup motors FOC without using the GUI. The aim is to configure the vesc and the motor automatically with a python script. I would like to know if there is a way to do this configuration without the GUI. I search into vesctool and pyvesc source (https://github.com/LiamBindle/PyVESC/tree/master), and that's what I got:

 

class DetectApplyFOC(metaclass=VESCMessage):

    id = VedderCmd.COMM_DETECT_APPLY_ALL_FOC

    fields = [

        ('detect_can', 'i'),

        ('max_power_loss', 'f'),

        ('min_current_in', 'f'),

        ('max_current_in', 'f'),

        ('openloop_rpm', 'f'),

        ('sl_erpm', 'f')

    ]

    

serial_port = '/dev/ttyACM0'

 

serial = serial.Serial(port=serial_port, baudrate=115200)

 

 

my_msg = DetectApplyFOC(0, 120, -25, 60, 700, 4000)

serial.write(pyvesc.encode(my_msg))

while True:

    time.sleep(0.2)

    serial.write(pyvesc.encode(Alive))

    if(serial.in_waiting > 0):

        break

 

in_buf = b''

while serial.in_waiting > 0:

    in_buf += serial.read(serial.in_waiting)

    

if len(in_buf) == 0:

    print("exit here")

    exit()

 

response, consumed = pyvesc.decode(in_buf)

 

if consumed == 0:

    exit()

 

print("Received response: ", response)

print("Consumed: ", consumed)

    

 

I create a class that contain the message and then I send it to the vesc using serial port and I wait for the response of vesc to print it. Something seems to happen in the motor, it makes the same noise that when it starts a setup motor FOC but it doesn't spin, it just vibrates. I get this error message :

Traceback (most recent call last):

  File "/home/natuition/Documents/STAGE2024Melvin/configuration_deployer/vesc/script.py", line 158, in <module>

    response, consumed = pyvesc.decode(in_buf)

  File "/home/natuition/.local/lib/python3.10/site-packages/pyvesc/protocol/interface.py", line 18, in decode

    return pyvesc.protocol.base.VESCMessage.unpack(msg_payload), consumed

  File "/home/natuition/.local/lib/python3.10/site-packages/pyvesc/protocol/base.py", line 85, in unpack

    data = list(struct.unpack_from(VESCMessage._endian_fmt + msg_type._fmt_fields, msg_bytes, 1))

struct.error: unpack_from requires a buffer of at least 25 bytes for unpacking 24 bytes at offset 1 (actual buffer size is 3)

 

If someone wan't to join me please write to : v.lambert@natuition.com