object has no attribute 'set_input_mode'

66 views
Skip to first unread message

Mike S

unread,
Nov 18, 2013, 8:37:10 PM11/18/13
to nxt-p...@googlegroups.com
I am using a Raspberry Pi with nxt-python-2.2.2 to control a small robot I have built. I have been able to use the test_sensor.py program successfully, but when I try to use the HiTechnic motor controller I get the following error.


pi@raspberrypi ~/nxt-python-2.2.2/examples $ sudo python htmotor1.py
Traceback (most recent call last):
  File "htmotor1.py", line 7, in <module>
    v = nxt.sensor.hitechnic.MotorCon(b, PORT_1).get_battery_voltage()
  File "/usr/local/lib/python2.7/dist-packages/nxt/sensor/hitechnic.py", line 54 3, in __init__
    super(MotorCon, self).__init__(brick, port, check_compatible)
  File "/usr/local/lib/python2.7/dist-packages/nxt/sensor/digital.py", line 65,  in __init__
    self.set_input_mode(Type.LOW_SPEED_9V, Mode.RAW)
  File "/usr/local/lib/python2.7/dist-packages/nxt/sensor/common.py", line 67, i n set_input_mode
    self.brick.set_input_mode(self.port, type_, mode)
AttributeError: 'function' object has no attribute 'set_input_mode'


I am new to python and don't really know how to fix this problem. The code I wrote is below.


#!/usr/bin/env python

import nxt.locator
from nxt.sensor import *

b = nxt.locator.find_one_brick
v = nxt.sensor.hitechnic.MotorCon(b, PORT_1).get_battery_voltage()

print v


Please let me know if there is a mistake in my code that is causing the problem. I will be happy to help test any solutions if you need. Thanks.

Marcus Wanner

unread,
Nov 19, 2013, 8:43:03 AM11/19/13
to nxt-p...@googlegroups.com
On Mon, Nov 18, 2013 at 05:37:10PM -0800, Mike S wrote:
> self.brick.set_input_mode(self.port, type_, mode)
> AttributeError: 'function' object has no attribute 'set_input_mode'
>
>
> b = nxt.locator.find_one_brick

Yes, you need to actually call the function:

b = nxt.locator.find_one_brick()

That should fix it. Good luck!

--
Marcus Wanner

signature.asc

Mike S

unread,
Nov 19, 2013, 4:36:32 PM11/19/13
to nxt-p...@googlegroups.com
I have added the parentheses and that solved the first error, but now there is another:

pi@raspberrypi ~/nxt-python-2.2.2/examples $ sudo python htmotor1.py
Traceback (most recent call last):
  File "htmotor1.py", line 7, in <module>
    v = nxt.sensor.hitechnic.MotorCon(b, PORT_1).get_battery_voltage()
  File "/usr/local/lib/python2.7/dist-packages/nxt/sensor/hitechnic.py", line 607, in get_battery_voltage
    high, low = self.read_value('bateryvoltage')[0]
  File "/usr/local/lib/python2.7/dist-packages/nxt/sensor/digital.py", line 136, in read_value
    address, fmt = self.I2C_ADDRESS[name]
KeyError: 'bateryvoltage'

I see that the get_battery_voltage method requires a parameter of 'self'. What is self? Do I need to give it a value?

Marcus Wanner

unread,
Nov 20, 2013, 8:55:55 AM11/20/13
to nxt-p...@googlegroups.com
On Tue, Nov 19, 2013 at 01:36:32PM -0800, Mike S wrote:
> line 607, in get_battery_voltage
> high, low = self.read_value('bateryvoltage')[0]
> File "/usr/local/lib/python2.7/dist-packages/nxt/sensor/digital.py", line
> 136, in read_value
> address, fmt = self.I2C_ADDRESS[name]
> KeyError: 'bateryvoltage'

Looks like you've encountered some untested code. Due to hardware
limitations, some of our 3rd party sensor code has never actually been
run, so thank you for helping out! Change line 607 of
nxt/sensor/hitechnic.py to read 'batteryvoltage' instead of
'bateryvoltage' and things should work. Let me know if you find any
other bugs with that sensor's class. Thanks!

--
Marcus Wanner
signature.asc

Mike S

unread,
Nov 20, 2013, 5:17:36 PM11/20/13
to nxt-p...@googlegroups.com
I fixed the hitechnic.py file. Just as a note to anyone trying to do this; you must fix it in the nxt-python-2.2.2/nxt/sensor directory before installing it, or you will have to fix it in the /usr/local/lib/python2.7/dist-packages/nxt/sensor/ after installing it.

I now have the following error:

  File "htmotor1.py", line 7, in <module>
    v = nxt.sensor.hitechnic.MotorCon(b, PORT_1).get_battery_voltage()
  File "/usr/local/lib/python2.7/dist-packages/nxt/sensor/hitechnic.py", line 607, in get_battery_voltage
    high, low = self.read_value('batteryvoltage')[0]
TypeError: 'int' object is not iterable


From reading the digital.py file, it seems to me that the string 'batteryvoltage' is not in the self.I2C_ADDRESS dictionary as directed by the read_value method.

Mike S

unread,
Nov 21, 2013, 6:30:34 PM11/21/13
to nxt-p...@googlegroups.com
I believe I have fixed the problem. Line 607 (high, low = self_readvalue('batteryvoltage')[0]) needs to be changed to the following:

data  = self.read_value('batteryvoltage')
high = data[0]
low = data[1]

It seems that there is a problem saving the two variables with the index of [0]. This solution may not be the best way to solve the problem, but it works.
Reply all
Reply to author
Forward
0 new messages