LiamBindle / PyVESC

PyVESC is an easy to use and robust Python implementation of the VESC - Open Source ESC communication protocol
https://pyvesc.readthedocs.io/en/latest/
Creative Commons Attribution 4.0 International
67 stars 52 forks source link

Setup motor foc #25

Open Vincentvlb opened 2 years ago

Vincentvlb commented 2 years ago

Hello, I would like to know if it is possible with your library to make a setup motor foc as in vesc tool. If possible, do you have an example? Thanks in advance, Vincent LAMBERT.

RKajay2001 commented 1 month ago

Hello, I would like to know if it is possible with your library to make a setup motor foc as in vesc tool. If possible, do you have an example? Thanks in advance, Vincent LAMBERT.

Hello Vincent, I'm also search for setup motor foc only. didn't you find any code for that if yes means kindly help me out.

Thanks in advance.

MelvinWarnet commented 1 month ago

Hello RKajay,

I'm an intern working with Vincent, and I've come back to the motor FOC setup with pyvesc as part of my internship project. Here's what I have so far:

class DetectApplyFOCMessage(metaclass=VESCMessage):
    id = COMM_DETECT_APPLY_ALL_FOC
    fields = [
        ('detect_can', 'i'),
        ('max_power_loss', 'd'),
        ('min_current_in', 'd'),
        ('max_current_in', 'd'),
        ('openloop_rpm', 'd'),
        ('sl_erpm', 'd')
    ]

serial_port = '/dev/ttyACM0'
serial = Serial(port=serial_port, baudrate=115200)
my_msg = DetectApplyFOCMessage(0, 60, -25, 60, 700, 4000)
serial.write(pyvesc.encode(my_msg))

With this setup, the motor makes some noises similar to those when using VESC Tool, but it doesn't really start spinning, and I don't know how to get feedback. The feedback I'm interested in is whether the hall sensors are detected or not.

I've also identified this frame that initiates the motor FOC setup, but again, I don't know how to get the feedback I need.

serial_port = '/dev/ttyACM0'
serial = Serial(port=serial_port, baudrate=115200)
frame = "02 16 3a 00 00 01 d4 c0 00 00 00 00 00 00 00 00 00 0a ae 60 00 3d 09 00 ac 46 03"
serial.write(bytearray.fromhex(frame))

If you have discovered anything new or have any additional insights, I would really appreciate your help!

RKajay2001 commented 1 month ago

I didn't work with COMM_DETECT_APPLY_ALL_FOC I worked with COMM_DETECT_MOTOR_FLUX_LINKAGE and COMM_MCCONF commands only. I need solution in MCCONF command. As I'm worked with pyvesc we can either set or get with one command we can't do both with the same command