AttributeError: 'Roboclaw' object has no attribute '_port'

General discussion of using Roboclaw motor controllers
Post Reply
Tristan_Thompson
Posts: 6
Joined: Mon Jan 27, 2020 6:47 am

AttributeError: 'Roboclaw' object has no attribute '_port'

Post by Tristan_Thompson » Mon Jan 27, 2020 6:52 am

Having trouble running anything as a result of this error, i have provided the code i am running, it is based off the complete example from

https://resources.basicmicro.com/using- ... 3MKynbgdec

Code: Select all

# Complete example of using the RoboClaw library
#import the relevant code from the RoboClaw library

from roboclaw_3 import Roboclaw

# address of the RoboClaw as set in Motion Studio

address = 128

# Creating the RoboClaw object, serial port and baudrate passed

roboclaw = Roboclaw("COM4",115200)
#roboclaw = RoboClaw(“/dev/ttyS0”, 38400)

# Starting communication with the RoboClaw hardware

roboclaw.Open()

# Start motor 1 in the forward direction at half speed

roboclaw.ForwardM1(address, 120)
when i run the code i get the following response

Code: Select all

Traceback (most recent call last):
  File "C:\Users\trist_000\Documents\-Warwick\Year 4\ES410 - Warwick Mobile Robotics\Motor control\roboclaw_python\roboclaw_python\TEST1_BasicExample1.py", line 21, in <module>
    roboclaw.ForwardM1(address, 120)
  File "C:\Users\trist_000\Documents\-Warwick\Year 4\ES410 - Warwick Mobile Robotics\Motor control\roboclaw_python\roboclaw_python\roboclaw_3.py", line 654, in ForwardM1
    return self._write1(address,self.Cmd.M1FORWARD,val)
  File "C:\Users\trist_000\Documents\-Warwick\Year 4\ES410 - Warwick Mobile Robotics\Motor control\roboclaw_python\roboclaw_python\roboclaw_3.py", line 317, in _write1
    self._sendcommand(address,cmd)
  File "C:\Users\trist_000\Documents\-Warwick\Year 4\ES410 - Warwick Mobile Robotics\Motor control\roboclaw_python\roboclaw_python\roboclaw_3.py", line 129, in _sendcommand
    self._port.write(address.to_bytes(1, 'big'))
AttributeError: 'Roboclaw' object has no attribute '_port'
any clues?

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

Re: AttributeError: 'Roboclaw' object has no attribute '_port'

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

The error is indicating the specified comport could not be opened. Make sure you have a COM4 and nothing else already has taken control of it. Check the return status of the roboclaw.Open() function. If it returns 0 the specified port could not be opened.

Tristan_Thompson
Posts: 6
Joined: Mon Jan 27, 2020 6:47 am

Re: AttributeError: 'Roboclaw' object has no attribute '_port'

Post by Tristan_Thompson » Tue Jan 28, 2020 6:08 am

Thanks will give it a try!

Tristan_Thompson
Posts: 6
Joined: Mon Jan 27, 2020 6:47 am

Re: AttributeError: 'Roboclaw' object has no attribute '_port'

Post by Tristan_Thompson » Tue Jan 28, 2020 8:23 am

I have tested the setup i am using and the drive unit is showing in COM4 and is being recognised in COM4 by basic motion studio, when i return roboclaw.Open() it is returning a 0 and the same error message shown above comes up, how should i proceed?

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

Re: AttributeError: 'Roboclaw' object has no attribute '_port'

Post by Basicmicro Support » Tue Jan 28, 2020 10:39 am

Close Motion Studio. While Motion Studio is open it can prevent your python script from accessing the comport. Even though Motion Studio doesnt ask for exclusive access it can still prevent you from opening the comport. Alternatively you could try to open the comport several times in your python script.

When Motion Studio is open and connected to the Roboclaw it is constantly communicating. But even when Motion Studio is NOT connected to the Roboclaw it is periodically querying the Roboclaws on the system to keep the Device List updated. This happens at a much lower rate but could interfere with connected to the Roboclaw with your python script.

Tristan_Thompson
Posts: 6
Joined: Mon Jan 27, 2020 6:47 am

Re: AttributeError: 'Roboclaw' object has no attribute '_port'

Post by Tristan_Thompson » Tue Jan 28, 2020 1:30 pm

Hi I will test opening the comport multiple times tomorrow and let you know the results,

As for having motion studio open i tried it with it open and connected to the driver, open and disconnected from the driver and with motion studio closed entirely and i am still being presented with the same error, i will check to ensure i have not made any spelling mistakes but i havent touched the code in the roboclaw_3.py library i am using so it shouldnt be an issue.

Tristan_Thompson
Posts: 6
Joined: Mon Jan 27, 2020 6:47 am

Re: AttributeError: 'Roboclaw' object has no attribute '_port'

Post by Tristan_Thompson » Wed Jan 29, 2020 7:52 am

Hi,

The libraries and examples are working perfectly in Ubuntu so I'm just going to switch to using Ubuntu (it was going to happen eventually anyway, was just hoping to get some basic tests running in windows)

Thanks for all your help!

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

Re: AttributeError: 'Roboclaw' object has no attribute '_port'

Post by Basicmicro Support » Wed Jan 29, 2020 10:15 am

Let me know if you want to work on Windows in the future. One difference between Linux and Windows is Windows requires a cutomer vitual comport driver inf to be installed for the Roboclaw(available in the download section of the site). Linux understands a virtual comport is a virtual comport and installs the driver automatically. Windows is apparently not that smart. :)

Tristan_Thompson
Posts: 6
Joined: Mon Jan 27, 2020 6:47 am

Re: AttributeError: 'Roboclaw' object has no attribute '_port'

Post by Tristan_Thompson » Fri Jan 31, 2020 2:23 am

There is one more thing I'd like to ask, I'm planning on using two drive units in order to be able to independently control four motors and I'm a bit unsure on how to differentiate the two drivers from one another when using linux, in windows it seems simpler as you are defining the comport you are connecting the specific drive unit to but in linux I'm a bit confused as to how to ensure that the script does not confuse one driver for the other. My best guess is to give each driver a different address e.g 0x80 and 0x81 but I feel as though that could be wrong?

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

Re: AttributeError: 'Roboclaw' object has no attribute '_port'

Post by Basicmicro Support » Tue Feb 04, 2020 10:13 am

In Linux the virtual comports will be /dev/ttyACM0 and /dev/ttyACM1 for USB virtual comports IIRC.

Post Reply