Controlling Motors via Python

1,022 views
Skip to first unread message

Alex Munoz

unread,
Feb 20, 2014, 12:55:44 AM2/20/14
to velmex-...@googlegroups.com
I've been looking for documentation on using Python to speak to the VXM motors but I've come up fruitless. I understand that I need to use pyserial to communicate with my port, however, I'm not sure how a command to the machine would look in that context. I'm very new to using both pyserial and VXM. I run Ubuntu 13.04.

Sorry if this is too broad of a question.

Cliff

unread,
Feb 20, 2014, 9:16:07 AM2/20/14
to velmex-...@googlegroups.com, steame...@gmail.com
Unfortunately I know next to nothing in python but a quick google search I found this page
http://stackoverflow.com/questions/676172/full-examples-of-using-pyserial-package

On that page I saw this example that may work (I modified what is sent to use VXM commands)

 #!/usr/bin/python

    import serial, time

    #initialization and open the port

    #possible timeout values:

    #    1. None: wait forever, block call

    #    2. 0: non-blocking mode, return immediately

    #    3. x, x is bigger than 0, float allowed, timeout block call

    ser = serial.Serial()

    #ser.port = "/dev/ttyUSB0"

    ser.port = "/dev/ttyUSB7"

    #ser.port = "/dev/ttyS2"

    ser.baudrate = 9600

    ser.bytesize = serial.EIGHTBITS #number of bits per bytes

    ser.parity = serial.PARITY_NONE #set parity check: no parity

    ser.stopbits = serial.STOPBITS_ONE #number of stop bits

    #ser.timeout = None          #block read

    ser.timeout = 1            #non-block read

    #ser.timeout = 2              #timeout block read

    ser.xonxoff = False     #disable software flow control

    ser.rtscts = False     #disable hardware (RTS/CTS) flow control

    ser.dsrdtr = False       #disable hardware (DSR/DTR) flow control

    ser.writeTimeout = 2     #timeout for write

try:

    ser.open()

except Exception, e:

    print "error open serial port: " + str(e)

    exit()

if ser.isOpen():

    try:

    ser.flushInput() #flush input buffer, discarding all its contents

    ser.flushOutput()#flush output buffer, aborting current output

                 #and discard all that is in buffer

    #write data

    ser.write("F,C,I1M400,R")

    print("F,C,I1M400,R")

    time.sleep(0.5)  #give the serial port sometime to receive the data

    numOfLines = 0

    while True:

        response = ser.readline()

        print("read data: " + response)

        numOfLines = numOfLines + 1

        if (numOfLines >= 5):

            break

    ser.close()

    except Exception, e1:

    print "error communicating...: " + str(e1)

else:

    print "cannot open serial port "


On 2/20/2014 12:55 AM, Alex Munoz wrote:
I've been looking for documentation on using Python to speak to the VXM motors but I've come up fruitless. I understand that I need to use pyserial to communicate with my port, however, I'm not sure how a command to the machine would look in that context. I'm very new to using both pyserial and VXM. I run Ubuntu 13.04.

Sorry if this is too broad of a question.
--
You received this message because you are subscribed to the Google Groups "Velmex Controls" group.
To unsubscribe from this group and stop receiving emails from it, send an email to velmex-contro...@googlegroups.com.
To post to this group, send email to velmex-...@googlegroups.com.
Visit this group at http://groups.google.com/group/velmex-controls.
For more options, visit https://groups.google.com/groups/opt_out.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Colin Reese

unread,
Feb 20, 2014, 9:25:12 AM2/20/14
to velmex-...@googlegroups.com, velmex-...@googlegroups.com, steame...@gmail.com
Looks pretty good. Probably want to change print statements to print('print text') to make them python 3 compliant. 

Alex Munoz

unread,
Feb 20, 2014, 11:11:52 AM2/20/14
to velmex-...@googlegroups.com, steame...@gmail.com, cl...@velmex.com
This is exactly what I needed to get going. I had seen this page but I was confused about implementing VXM commands within it. Thank you for putting the time in to help me out. I'll probably be back when I have a real problem :)

pjaiswal....@gmail.com

unread,
Apr 18, 2017, 7:28:58 PM4/18/17
to Velmex Controls, steame...@gmail.com, cl...@velmex.com
Hello Just a follow up, we still need to install cosmos software even if we communicate via python right ?
I am using windows installed anaconda (python 2.7) I was trying the above mentioned code, but found out that although write and read goes smoothly without errors etc my traversing system did not move! Maybe because i did not have cosmos installed ?


Best Regards
Prateek

Velmex Support

unread,
Apr 19, 2017, 10:33:40 AM4/19/17
to pjaiswal....@gmail.com, Velmex Controls, steame...@gmail.com
Prateek,
Just to clarify. 
COSMOS is a "Stand-Alone" program only and not a driver for the VXM (IE: Its main use is for configuring the control and testing code development and movement of the system. It is NOT meant to be of use with another programming language)

Depending upon the problem of "Not moving" means.

1.) Not moving (no sound) could be the following symptoms:
A.) Code is not actually communicating (Wrong Port, Port already taken, wrong Baud Rate or other parameters)
B.) VXM is misconfigured (limit settings incorrect)

2.) Axis moves for about 1/2 second, and then just makes a "Growling sound"
A.) VXM is misconfigured (motor settings incorrect)
B.) Too high of a load
C.) Acceleration or speed set too high

3.) Does the motor move if VXM just turned on and press the jog buttons on the front panel (without communicating with computer)????



pjaiswal....@gmail.com

unread,
Apr 19, 2017, 12:26:33 PM4/19/17
to Velmex Controls, pjaiswal....@gmail.com, steame...@gmail.com, sup...@velmex.com

Hello Thanks for the reply. I actually made it work, I am not sure what was causing the problem, I updated the driver and it started working. Thanks a lot again.

Best Regards Prateek
Reply all
Reply to author
Forward
0 new messages