odyaka341 / nxt-python

Automatically exported from code.google.com/p/nxt-python
GNU General Public License v3.0
0 stars 0 forks source link

adding the nxt 2.0 rgb color sensor to sensors.py #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have attached a patch that provides the methods for the new lego NXT
color sensor. I haven't had time to add the calibration function yet but I
hope to do that in a couple days. 

this is the description included in the class header

# this is a class for the lego NXT 2.0 RGB color sensor
# not to be confused with the hitechnic color sensor
# the color sensor can run in two modes:
# a light sensor which returns the reflected light from the lamp that is
# currently on (red, green, blue, off/ambient) on a scale of 1-1023
# a color sensor that returns a 1-6 decimal value corresponding to
# (black, blue, green, yellow, red, white) unfortunately the RGB values
# are not sent over the wire

# TODO: calibration 

#note: if you create a new object everytime you make a call the light 
# will flash on an off because each time the object is created the light
# color is set to  none

Original issue reported on code.google.com by meldu...@gmail.com on 7 Jun 2010 at 2:57

Attachments:

GoogleCodeExporter commented 9 years ago
This works by connecting the NXT 2.0 sensor to a NXT original brick? This 
project
currently doesn't support NXT 2.0, so I don't think this patch should be 
included in
NXT-Python.

However, we may expand the project to include support for NXT 2.0 sometime in 
the
future, in which case this patch will probably be used as the basis for color 
sensor
2.0 support. Thank you for submitting this code; while it is currently not of 
much
use to us, it will remain under consideration.

Original comment by marcus@wanners.net on 7 Jun 2010 at 1:04

GoogleCodeExporter commented 9 years ago
we've been using everything on an NXT 2.0 brick and it works great. I'm not 
sure what
the distinction is, if you know I'd like to know.

Original comment by meldu...@gmail.com on 7 Jun 2010 at 6:16

GoogleCodeExporter commented 9 years ago
Oh, I had heard that they had a different interface...someone was having 
problems with a NXT 2.0 brick and nxt-python, so I thought they were different.

This is an interesting thing to note, you are sure that everything works with a 
2.0 brick?

Original comment by marcus@wanners.net on 8 Jun 2010 at 2:09

GoogleCodeExporter commented 9 years ago
Currently.. We have an NXT 2.0 system.. I have run with the USB and bluetooth 
interface. I have streamed data with all the servos/sensors (touch, ultrasonic, 
and color). My coworker, Tully even patched back the problem we found with 
pulling the I2C too quickly. As far as I can tell everything works. I am going 
to try out the gyro and accel today. I'll tell you the results, but I have 
confidence that everything will work just fine. 

We are using nxt-python as the interface layer for nxt_ros.. you can checkout 
our code at 
http://code.google.com/p/foote-ros-pkg/source/browse/#svn/trunk/nxt/trunk

Original comment by meldu...@gmail.com on 8 Jun 2010 at 10:47

GoogleCodeExporter commented 9 years ago
The I2C problem should be fixed in v1.1.2.

Unfortunately, until we have a committed developer who has a 2.0 brick and is 
willing to debug stuff with it, I am not willing to support 2.0 explicitly.. If 
it works, all well and good; otherwise, there is not much I can do.

As for the sensor, does it work if connected to a NXT 1.0 brick?

Original comment by marcus@wanners.net on 9 Jun 2010 at 3:15

GoogleCodeExporter commented 9 years ago
I don't have a NXT 1.0 brick, I'll try and get my hands an NXT brick 1.0. I'm 
guessing it will work, since I am just using the analog interface that is 
already being used with the NXT 1.0. 

Original comment by meldu...@gmail.com on 9 Jun 2010 at 3:23

GoogleCodeExporter commented 9 years ago
Alrighty- I got a NXT 1.0 brick. This sensor will work with the NXT brick as 
long as the firmware is upgraded to 1.28 then this code can be used with an NXT 
1.0 brick no problem.

Original comment by meldu...@gmail.com on 15 Jun 2010 at 7:22

GoogleCodeExporter commented 9 years ago
The bricks from NXT 1.0, NXT 2.0 and the NXT Education set are identical. There 
are no hardware changes. The firmware versions 1.0* (latest is 1.05) came with 
NXT 1.0 and NXT Education.

NXT 2.0 came with a new firmware version (1.28). The current version is 1.29. 
The direct commands protocol (which is used by NXT-Python and other remote 
control programming languages) is 100% compatible to the old 1.0* branch!

The 2.0 firmware generation (1.2*) added floating point support for various 
on-brick languages, some bugfixes, data-logging support, performance 
improvements, and support for the NXT 2.0 color sensor.

Since there is no hardware difference between bricks, it doesn't make sense to 
talk about NXT 1.0 or 2.0 bricks.

The NXT 2.0 color sensor can be used as light sensor. It's fully backward 
compatible, so if you (and your program) assume it's an old NXT 1.0 light 
sensor, it will work like that.

For more details, discussions and questions see the NXTasy forums: 
http://forums.nxtasy.org/

Original comment by linus.at...@gmx.de on 22 Jun 2010 at 11:03

GoogleCodeExporter commented 9 years ago
Ok, so I can take a v1.05 NXT 1.0 brick, connect this sensor to it, run this 
code, and have the sensor behave as expected?

Original comment by marcus@wanners.net on 23 Jun 2010 at 1:08

GoogleCodeExporter commented 9 years ago
Sorry I wasn't precise on this:
The Color NXT 2.0 sensor needs at least Firmware 1.28. But yes, you can use 
your "1.0 NXT Brick", since it's identical to the 2.0 brick.

You can find Firmware 1.28 here: 
http://www.legoengineering.com/library/doc_details/250-nxt-firmware-v128.html

Firmware 1.29 is available on the LEGO NXT Homepage.

1.28 (or 1.29) is so much better than 1.05 that there is no reason to still use 
1.05.

One last thing: I'm not very up2date on the NXT 2.0 color sensor topic, but 
I've not yet seen a solution to retrieve values from it that is as easy as 
yours. I always thought you had to use the I/O maps (internal firmware 
registers) to do so. It's good news to see the great "easy" solution by 
melducky above. If it does behave exactly as expected, I cannot tell...

Original comment by linus.at...@gmx.de on 23 Jun 2010 at 2:43

GoogleCodeExporter commented 9 years ago
I'm still wary of this because of the fact that I can't test it and it still 
needs to be ported to the v2 sensor interface at some point, but I will plan on 
trying to get it out by v2.

Original comment by marcus@wanners.net on 23 Jun 2010 at 3:26

GoogleCodeExporter commented 9 years ago
This sensor is this one, correct?
http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NCO1038

If not, I would like to see the product page for it so that I can classify it 
correctly in the sensor module.

Original comment by marcus@wanners.net on 24 Jun 2010 at 8:09

GoogleCodeExporter commented 9 years ago
The part looks like this http://www.peeron.com/inv/parts/64892. It comes with 
the NXT 2.0 kit, it is an official Lego part not made by hitech something I 
tried to make clear in the comments of the code. But I can't find a product 
page for it any where.

Original comment by meldu...@gmail.com on 24 Jun 2010 at 9:05

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Added in r132.

Original comment by marcus@wanners.net on 24 Jun 2010 at 9:18

GoogleCodeExporter commented 9 years ago
If you can grab the latest v2 SVN and test that with the sensor for me so I 
know that the ported code works correctly, I would be very happy!

In case you can't do SVN, I'll try to have a beta up in the next few days for 
testing purposes, so you can use that instead.

Original comment by marcus@wanners.net on 25 Jun 2010 at 8:43

GoogleCodeExporter commented 9 years ago
Yes I can this weekend.. 

Original comment by meldu...@gmail.com on 25 Jun 2010 at 8:47

GoogleCodeExporter commented 9 years ago
How did it go?

Original comment by marcus@wanners.net on 2 Jul 2010 at 10:51

GoogleCodeExporter commented 9 years ago
sorry .. I forgot to do this over the weekend.. I run my test script and I get 
this error 

 File "/usr/local/lib/python2.6/dist-packages/nxt/sensor/generic.py", line 122, in __init__
    super(Light, self).__init__(brick, port)
TypeError: super(type, obj): obj must be an instance or subtype of type

I'll see if I can figure it out If I don't hear from you

Original comment by meldu...@gmail.com on 3 Jul 2010 at 12:14

GoogleCodeExporter commented 9 years ago
Oops, that was because of my carelessness. To fix it, just change line 122 of 
nxt/sensor/generic.py from

super(Light, self).__init__(brick, port)

to

super(Color20, self).__init__(brick, port)

Or update to the latest v2 svn. After that, test again and see if it's broken 
anywhere else. Thanks!

Original comment by marcus@wanners.net on 3 Jul 2010 at 1:48

GoogleCodeExporter commented 9 years ago
everything works except that you forgot to return the color value in the 
get_color call

    def get_color(self):
        self.get_reflected_light(Type.COLORFULL)
+       raw_reading = self.get_input_values()
+       return raw_reading.scaled_value

Original comment by meldu...@gmail.com on 6 Jul 2010 at 5:35

GoogleCodeExporter commented 9 years ago
Fixed in r144. Also, the result of a get_sensor_info() call would be very 
helpful. Thanks!

Original comment by marcus@wanners.net on 7 Jul 2010 at 1:15

GoogleCodeExporter commented 9 years ago

Original comment by marcus@wanners.net on 20 Aug 2010 at 2:00