RemoteNXT and ColorSensor

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

RemoteNXT and ColorSensor

Postby tamasu » Tue Sep 10, 2013 6:23 pm

Hi,

I tried to initialize the ColorDetector through remotenxt however it seems that a remote port cannot be defined.

For instance I tried the following piece of code
pc = new RemoteNXT("NXT2",RS485.getConnector());
ColorDetector cd = new ColorSensor(pc.S2);

but it seems that the this is not valid as I am having "The constructor ColorSensor(RemoteSensorPort) is undefined". Is this because the colorDetector is not supported remotely? Strange however because the light sensor is!

Thanks
tamasu
New User
 
Posts: 23
Joined: Sun Nov 25, 2012 12:14 am

Re: RemoteNXT and ColorSensor

Postby gloomyandy » Tue Sep 10, 2013 8:21 pm

Hi,
There are a few problems hiding away here.... Firstly if your program was on a PC this would appear to work. I say appear to work because in fact you wouldn't get all of the data (like raw RGB values), but you would get simple color readings and other single value items. The problem here is that leJOS uses LCP to implement remote operations. But (in leJOS at least) there is not an LCP operation to do the equivalent of readRawValues that is return multiple values from a remote port. Guess what the color sensor needs this to be able to read the RGB and background values. I have a feeling that LCP can handle this but without going and digging through the Lego code I'm not sure.

Anyway so why does it sort of work on a PC but not on an NXT? The basic answer is the the person that implemented the color sensor code forgot about this use case. That person would be me and I didn't totally forget I just hate the entire LCP thing and it was bad enough getting the PC side of things working.

But this is not helping you. What to do about it. You have a couple of options.
1. Fix the problem (or get someone else to fix it). To fix this you would basically need to extend one of the interfaces supported by RemoteSensorPort to add the missing multi byte read methods, or possibly add a new interface that included this capability and then change the type of port needed by the color sensor class to be this new interface. You would also need to add code to the RemoteSensorPort class to implement the new interface (and make it fail).
2. Work around the problem. If all you need is a way to read colors remotely (or use the color sensor as alight sensor) you could write your own Color Sensor class that does just that without needing all of the multi byte stuff, this can then use one of the interfaces supported by RemoteSensorPort and you are good to go.

Interestingly I'm probably about to tackle this very problem on the EV3. You can tell that I'm not keen on fixing it by the fact that I've left it a long way down my to do list. I'm still not sure how I'm going to fix it at the moment.

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: RemoteNXT and ColorSensor

Postby tamasu » Tue Sep 10, 2013 8:32 pm

The easy way was to swap the connections.. that is connecting those sensors that cannot be handled through remotenxt. This was only possible because sonar sensors support remote ports.

It seems that I am finding a good number of limitations with lejos / NXT (refer to my previous forum queries).

I even noticed that the mindsensors multiplexer is as well not support through remote ports. I think complex stuff!

Thanks once again
tamasu
New User
 
Posts: 23
Joined: Sun Nov 25, 2012 12:14 am

Re: RemoteNXT and ColorSensor

Postby gloomyandy » Tue Sep 10, 2013 8:49 pm

Since I'm on my soap box let me tell you why I dislike LCP so much and try and encourage you not to use it...

Although on the face of it, this seems a very nice interface to use it is in my eyes fundamentally flawed. The basic problem is that it puts the remote requests at the wrong level. You will almost always be better writing your own code for both sides of the communications channel. Yes this may seem like more work to begin with in that you will need to define your own protocol (not hard) and you will have to have code on more than one nxt (again not hard). But the big advantage is that you can have the code in the right place. So for instance say you have code that is using a sensor to check for say a coloured line on the floor. If you use the RemoteNXT interface you will have code on the master that will generate thousands of remote requests probably at least one every few mS to get a good response time, if your motors are also remote, or if you have other remote sensors they will also be doing similar high rates of requests. If you have your own code then all of the detection logic can run on the remote system and when (and if) it ever detects the line it sends a single message to say so. Guess which of the above approaches puts the least amount of strain on what in pretty much all systems is the weak link (and particularly so in the case of Bluetooth on the NXT)?

Right off my soap box now. Good luck with your project....

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: RemoteNXT and ColorSensor

Postby tamasu » Wed Sep 11, 2013 9:02 pm

Its really buggy. I define 3 remote UltrasonicSensor and recursively I acquiring the reading of one of them. I set a tone of 1ms and noticed that whenever the primary nxt asks the secondary nxt for the sensor details it takes long. In fact I think the space between the first sound tick and the second one would be around 300ms or so.

The most worrying bit is that after less than a minute, the connection gets disconnected as the reading from the sonar would be 255. Then noticed that the loop took 1sec or so to display the 255ms.

Now I am running out of options but to start using BT agagin. I carried out a test and although it is painfully slow it never disconnected.

Inside the same loop I have a ColorSensor. Noticed that altough I switched on the floodlight to white, the sensor is flashing for each and every reading. I thought that floodlight would be switched on only once and just obtain the reading afterwards. Should I include the statement to switch on the floodlight within the loop?

Thanks once again
tamasu
New User
 
Posts: 23
Joined: Sun Nov 25, 2012 12:14 am

Re: RemoteNXT and ColorSensor

Postby gloomyandy » Wed Sep 11, 2013 9:11 pm

There is no white LED in color sensor there is just one LED it switches between red/blue/green when you issue a read. It only seems to be on all of time if you issues reads fast enough to make it look that way.

The code may be buggy because no one else has tried to do what you are doing. If you want to use it, make it better, you have all of the source, if you fix a problem let us know. I don't have the time at the moment to reproduce what you are doing. I know the RS432 code worked fine for what I used it for. The code is not that complex take a look at it, add debug into it, work out why it is not working.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff