Sending serial commands to a Kangaroo motion controller with pyserial

Viewed 55

Hi everybody, I need help with following problem please:

I try to drive a Dimension Engineering Kangaroo/Sabertooth motor controller from a Python script using pyserial.

Everything works so far except that the motor output stops after some time and the USB/serial connection becomes 'unresponsive'. The faster the rate at which the serial commands are sent, the quicker this happens.

This is how I initialize the serial connection:

# open serial port
Saber = serial.Serial("COM1", 19200, timeout=1, write_timeout=0)

# starting the motor
Saber.write("1,start\r".encode("gbk"))

Then the position commands are sent using a loop:

while True:
    pos = 2000  # just an example, the script calculates a new required position every iteration
    command = "1,p" + str(pos) + "s500\r"
    Saber.write(command.encode("gbk"))
    time.sleep(.1)  # the lower this break, the faster the device becomes unresponsive...?

After the device stops, I have to disconnect it / power it down, to be able to open a serial connection again.

Could it be that some sort of buffer gets filled and 'locks' the port? I have tried to free the read/write buffers using:

Saber.reset_input_buffer()
Saber.reset_output_buffer()

But that does not solve the problem :/ Any help is greatly apprechiated! Thanks!

0 Answers
Related