Serial Communications problem using Linux Kernel 4.10 and 4.12

General discussion of using Roboclaw motor controllers
gdoisy
Posts: 33
Joined: Tue Oct 18, 2016 7:53 am

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by gdoisy » Wed Aug 30, 2017 1:35 am

Same issue when using python3

gdoisy
Posts: 33
Joined: Tue Oct 18, 2016 7:53 am

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by gdoisy » Wed Aug 30, 2017 3:05 am

Same issue when using ubuntu 17.04 (kernel 4.10 by default)

User avatar
Basicmicro Support
Posts: 1274
Joined: Thu Feb 26, 2015 9:45 pm

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by Basicmicro Support » Wed Aug 30, 2017 9:48 am

All problems are on 4.10 kernels then?

The next step is to add print statements to the ReadVersion python function to see where it is failing. Something like this(note you will need to correct the :

Code: Select all

	def ReadVersion(self,address):
		trys=self._trystimeout
		while 1:
			print "Read Version start"
			self._port.flushInput()
			self._sendcommand(address,self.Cmd.GETVERSION)
			str = ""
			passed = True
			for i in range(0,48):
				data = self._port.read(1)
				print "Length Read:",
				print len(data)
				if len(data):
					val = ord(data)
					self.crc_update(val)
					if(val==0):
						print "Bad CRC Calc"
						break
					str+=data[0]
				else:
					passed = False
					break
			if passed:
				print "Read CRC"
				crc = self._readchecksumword()
				if crc[0]:
					if self._crc&0xFFFF==crc[1]&0xFFFF:
						print "Valid"
						return (1,str)
					else:
						print "Delay before retry"
						time.sleep(0.01)
			trys-=1
			if trys==0:
				break
		return (0,0)

gdoisy
Posts: 33
Joined: Tue Oct 18, 2016 7:53 am

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by gdoisy » Thu Aug 31, 2017 3:04 am

All problems are from kernel 4.10 (tested with 4.12, same issues).

I don't have the issue with the roboclaw_readversion.py example (cycles are too slow i guess), but with roboclaw_read.py (fails in less than 2 minutes).
I traced the blocking point to the function "def _sendcommand(self,address,command):" and the line "self._port.write(chr(command))"

User avatar
Basicmicro Support
Posts: 1274
Joined: Thu Feb 26, 2015 9:45 pm

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by Basicmicro Support » Thu Aug 31, 2017 9:20 am

Are you using USB or asyncronous serial?

If the latter the problem is completely in the Linux Kernal. Roboclaw cant block the master from sending data so if it is freezing up the problem has to be in the Linux driver.

If you are using USB its a bit more complex. Let me know how you are connected.

Add a delay to the loop. If that fixes the problem, reduce the delay until the problem comes back. Let me know the results.

gdoisy
Posts: 33
Joined: Tue Oct 18, 2016 7:53 am

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by gdoisy » Mon Sep 04, 2017 3:52 am

I am connected to the board directly to the usb port.

As you suspected a timing issue, I inserted a delay not every loop, but between every read of encoder or speed (i.e. in practice every _sendcommand call) as the I am using roboclaw_read.py which performs 4 reads in a row. So far, with a delay of:
-0.0001: blocks after 30569 cycles (1 trial)
-0.001: blocks after 16825 cycles (1 trial)
-0.01: did not blocked so far (15 minutes, but i will let it run longer)
EDIT: Failed with 0.01 delay after ~40 min

So it may well be that we have to respect a delay between 2 calls to a function which communicate with the board. What is strange is that this need appears with a kernel update.

gdoisy
Posts: 33
Joined: Tue Oct 18, 2016 7:53 am

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by gdoisy » Tue Sep 05, 2017 1:46 am

Failed also with 0.1 delay.
When I will have more time I will check in the library where to add delay between self._port.write(chr(command)) calls. And test.

User avatar
Basicmicro Support
Posts: 1274
Joined: Thu Feb 26, 2015 9:45 pm

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by Basicmicro Support » Tue Sep 05, 2017 9:13 am

Try closing and reopening the serial port after X number of cycles. Does that prevent the problem?

This could be a problem with ACM USB support in 4.10 or it could be some problem in pyserial with 4.10+ as well.

robof
Posts: 36
Joined: Tue Jun 27, 2017 11:21 pm

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by robof » Tue Sep 05, 2017 3:02 pm

I can confirm that closing/re-opening the connection after any number of cycles does not prevent the problem.

I put some debug statements in and have found that the python library is stopping on here, if that helps any

Code: Select all

def _sendcommand(self, address, command):
    ....
    self._port.write(bytes([command]))

robof
Posts: 36
Joined: Tue Jun 27, 2017 11:21 pm

Re: Losing communication with Roboclaw,TTL serial and Raspberry PI

Post by robof » Wed Sep 06, 2017 1:08 am

I'm not sure what the pyserial library is doing behind the scenes, but I wonder if this issue was tested in c++ on the 4.10 kernel if it would have any different result? If that worked, then the c++ library could be wrapped and called from Python with the existing python library. This may be exactly what pyserial is doing, so this may not help, but I just thought it was worth considering.

Post Reply