RoboClaw 2x15A, Python3, Windows: Unable to read version

General discussion of using Roboclaw motor controllers
Post Reply
simons
Posts: 11
Joined: Thu Nov 08, 2018 2:46 am

RoboClaw 2x15A, Python3, Windows: Unable to read version

Post by simons » Thu Jan 10, 2019 2:36 am

Hello,

I have written a program in Python3 in which I want to include a motor control with a RoboClaw2x15A.
Currently I am working on Windows10, but maybe I will swap to a Raspberry Pi in the future.

The Python Lib for Raspberry Pi is written for Python2, so I got the same _port-error as in the thread.
http://forums.basicmicro.com/viewtopic.php?f=2&t=542
Thus I did the changes mentioned from "robof" in forum and had no error anymore.

I checked the connection with

Code: Select all

a = rc.Open
if a ==1:
	print("okay")
else:
	print("not okay")
and it is working.

But trying to get data from the roboclaw does not really work.
Executing

Code: Select all

version = rc.ReadVersion(address)
if version[0]==False:
	print("GETVERSION Failed")
else:
	print( repr(version[1]))
does give me only the "GETVERSION Failed" output.

I also tried to read the encoder-value and measured the response time for the "rc.ReadEncM1(address)" -function and that is always a little bit more than 3seconds.


Do you have a python3 library available for further testing? Or may you help me with my communiction problem?

Thanks
simons

EDIT:
I changed the adress value from "0x80" to "80" before I tested all of these, because otherwise I got the error

Code: Select all

File "C:\Users\Simon\Desktop\testbed\GUI\roboclaw.py", line 717, in ReadVersion
    str+=data[0]
TypeError: must be str, not int
Tested everything in python2 and that is working.
So the problem must be at the conversion of the address, so it can be used in python3

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

Re: RoboClaw 2x15A, Python3, Windows: Unable to read version

Post by Basicmicro Support » Thu Jan 10, 2019 11:02 am

80 is not the same as 0x80. 0x80 = 128 is a valid address, 80 is not a valid address. Changing the address in the python code to 80 will definitely prevent thbe Roboclaw from communicating.

The str+=data[0] has nothing to do with the address value itself. It's just the fact that if you change the address to an invalid address you will never read any data back so data is empty and never reaches the line with the error.

Python3 is doing something different obviously. the _port.read command returns a byte array IIRC and str is initialised as a str( = ""). Apparently Python3 wont convert from one to the other correctly without doing something else where Python2 does it just fine.

simons
Posts: 11
Joined: Thu Nov 08, 2018 2:46 am

Re: RoboClaw 2x15A, Python3, Windows: Unable to read version

Post by simons » Sun Jan 13, 2019 12:35 pm

Thanks for the fast response.

I completely understand the fact, that I need to work with 0x80 as the address.

Can you tell me the changes I will need to do in the roboclaw.py to get it working with python3? I think that it should be possible with just a few changes, right?

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

Re: RoboClaw 2x15A, Python3, Windows: Unable to read version

Post by Basicmicro Support » Mon Jan 14, 2019 9:20 am

I have never tried converting to Python3 but a customer did send us a copy of a conversion they did. We havent had a chance to confirm it is fully functionaly yet but you can email support@basicmicro.com to get a copy of it.

Post Reply