python 3 library typos

General discussion of using Roboclaw motor controllers
Post Reply
Posts: 1
Joined: Sat Jan 25, 2020 9:00 pm

python 3 library typos

Post by daderaide » Sat Jan 25, 2020 9:17 pm

I'm new to python and having trouble getting any of the python 3 examples to run because I am encountering several typos in the library. I just downloaded everything in the last 3 days, so unless there has been an update in that time, I have the latest versions of everything (motion studio, the library, roboclaw firmware).

So far, I have been able to correct 2 typos:

In the example from the wedsite, "from roboclaw_3 import RoboClaw"
but in the library the "C" is not capitalized - "Roboclaw" so i capitalized it.

Second was, "def __init__(self, comport, rate, timeout=0.01, retries=3):" uses "comport" but everywhere else in the code uses "_port" so i did a "find and replace" to change all of the "_port" to "comport"

So I fixed those but now I'm getting this error and I don't know how to fix it:

dade@jetson:~/Code$ python3
Traceback (most recent call last):
File "", line 5, in <module>
roboclaw.ForwardM1(address, 30)
File "/home/dade/Code/", line 654, in ForwardM1
return self._write1(address,self.Cmd.M1FORWARD,val)
File "/home/dade/Code/", line 317, in _write1
File "/home/dade/Code/", line 129, in _sendcommand
self.comport.write(address.to_bytes(1, 'big'))
AttributeError: 'str' object has no attribute 'write'

I can't see how "str" object is related to the other lines. I can't figure out that the problem is with it because i'm very new to python and just rtying to run the example.

It's pretty disappointing that this code is so sloppy. Did the developers even bother trying this out before publishing it? I have come across a lot of typos in the user manual as well. It would just take someone proofreading it to correct them. Anyway, Does anyone have any suggestions about this library? Thanks!

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

Re: python 3 library typos

Post by Basicmicro Support » Mon Jan 27, 2020 10:48 am

I'll need to know which example you used? I went through all the exmaples we include with the python library and I dont see that typo. If you are using examples in the manual, those are getting far out of date. We are removing them for the next release and all examples will only be included with the library itself from then on.

As for the second problem, comport is NOT the same as _port. the comport argument is just the comport NAME. It is used in the Open() function which opens that comport and creates a comport object which is _port. I recommend you start from scratch and re-download the library so no edits you made could cause you future headaches.

Note the examples are simplified with very little error handling. One thing you may want to do is check the return value from the Open() function. If it returns 0 then your comport could not be opened. This could be because it does not exist or because something else already has taken control of that port.

Basicmicro Tech
Posts: 13
Joined: Wed Feb 13, 2019 2:56 pm

Re: python 3 library typos

Post by Basicmicro Tech » Tue Jan 28, 2020 5:32 pm

This article: ... n-library/ had a typo in the import statement that you caught. The "c" is lower-case "from roboclaw import Roboclaw". Thanks for catching that.

Post Reply