Help with Pyserial and LM629 (motion controller)

This is the place for queries that don't fit in any of the other categories.

Help with Pyserial and LM629 (motion controller)

Postby koutinho » Mon Apr 08, 2013 8:21 pm

Hello All!

First of all, let'me apologize for my bad English. I'm Portuguese ;)

I'm new to python and a relatively inexperient programmer, and now, i need to make a program in python that can control a autonumus robot by vision (it's the final work to have a master degree in electrical engeneering) :o

Vision is not the problem, control the robot it is. The robot as two serial interfaces, sonares and motores. I need to retrieve information from sonares (this work well with pyserial) and give instructions to the motores based on that.

The problem is that with motors i can't communicate well. I try to send the comand code but anything happens. I have in doubt what is the real good form of sending the information and pyserial as a short documentation.

My big uncertainity is that motor controller expects data in hexadecimal format and pyserial only work with chart and string...


I try the comunication with this code:

Code: Select all
serie_motores = serial.Serial(1, 115200, bytesize=serial.EIGHTBITS, timeout=0, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE)
serie_motores.port = '/dev/ttyUSB0'
serie_motores.open()
def send_comand (cmd,motor):
    if motor==1:
        mensagem=[]
       
        mensagem.append(chr(0x41))
        mensagem.append(chr(cmd))
       
        mensagem=''.join(mensagem)
        print("Mensagem Comando 1", mensagem)
         
    elif motor==2:
        mensagem=[]
       
        mensagem.append(chr(0xC1))
        mensagem.append(chr(cmd))
       
        mensagem=''.join(mensagem)
        serie_motores.writelines(mensagem)
        a=serie_motores.read()
        print("Mensagem Comando 2", mensagem)

    else:
        print ("Erro ao enviar comando para os motores")

def send_data (data,motor):
    dimensao=len(data)
    data_dimensao=dimensao & 0x07
    if motor==1:
        mensagem=[]
        dados_0=0x60 | data_dimensao
       
        mensagem.append(chr(dados_0))

        for d in (0,data_dimensao-1):
            mensagem.append(chr(data[d]))
        mensagem=''.join(mensagem)
        serie_motores.writelines(mensagem)
        a=serie_motores.read()
        print("Mensagem Comando 2", mensagem)

    elif motor==2:
        mensagem=[]
        dados_0=0xE0 | data_dimensao
       
        mensagem.append(chr(dados_0))
       
       
        for d in (0,data_dimensao-1):
            mensagem.append(chr(data[d]))
        mensagem=''.join(mensagem)
        serie_motores.writelines(mensagem)
        a=serie_motores.read()
        print("Mensagem Comando 2", mensagem)

    else:
        print ("Erro ao enviar data para os motores")


and the controller is this:

http://www.ti.com/lit/ds/symlink/lm629.pdf


Anyone have a idea of what i maybe made wrong?

In advance, thank you all.

Regards,

César Coutinho
koutinho
 
Posts: 2
Joined: Mon Apr 08, 2013 7:22 pm

Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], Mekire, micseydel, silas247 and 3 guests