Failure using lejos code to communicate with robotc firmware

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

Moderators: 99jonathan, roger, imaqine

Failure using lejos code to communicate with robotc firmware

Postby positron96 » Sat Jul 27, 2013 9:21 am

Hello there.
I am using lejos RemoteNXT class to communicate with remote NXT that is flashed into RobotC firmware, which happens to implement LCP as most other firmwares do. Mostly the commnunication works nice, but disconnecting code makes host hang indefinetely.

Research shows that the cause of this is lejos.nxt.remote.NXTCommand.disconnect() method:
Code: Select all
public void disconnect() throws IOException {
      byte[] request = { SYSTEM_COMMAND_REPLY, NXJ_DISCONNECT };
      nxtComm.sendRequest(request, 3); // Tell NXT to disconnect
      
      // like boot(), this should probably mark this NXTCommand as closed
      this.open = false;
   }


It seems that RobotC firmware does not understand NXJ_DISCONNECT command (it should not actually), and does not respond to it. That makes nxtComm.sendRequest wait indefinetely for the reply.

I believe lejos should work correctly with any firmware conforming to Lego Communication Protocol even if it does not understand lejos-specific commands (haven't read details of LCP on what to do with unknown commands and whose fault is this case), so I propose a solution.

As I see, the response of the slave to this command is never used anywhere on the host, so we can replace SYSTEM_COMMAND_REPLY with SYSTEM_COMMAND_NOREPLY and modify sendRequest code to not wait for respone. Something like this:
Code: Select all
   public void disconnect() throws IOException {
      byte[] request = { SYSTEM_COMMAND_NOREPLY, NXJ_DISCONNECT };
      nxtComm.sendRequest(request, 3); // Tell NXT to disconnect
      
      // like boot(), this should probably mark this NXTCommand as closed
      this.open = false;

and somewhere in sendRequest(byte[] message, int replyLen):
Code: Select all
      if((message[0] & 0x80) == 0x80)
         // it was a no-reply command
         return new byte[0];
positron96
New User
 
Posts: 21
Joined: Fri Jun 29, 2012 11:55 am

Re: Failure using lejos code to communicate with robotc firm

Postby gloomyandy » Sat Jul 27, 2013 7:30 pm

Hi,
thanks for the comments and the code.

We have not made much effort to support LCP in recent times and particularly when using non leJOS firmware. Is there a reason you are trying to use the RobotC firmware with leJOS rather than simply flashing the NXT with leJOS?

In general I think that supporting LCP is arguably one of the big mistakes we made in the NXT version of leJOS. It has caused us to twist the way we have implemented many of the classes to enable them to operate via LCP and has probably resulted in a less than optimum NXT implementation. LCP is a pretty poor remote protocol. Using remote control often gives poor results and although in principle it means you can write large complex programs that run on the PC I think that that if you need to do this then it makes far more sense to factor your application such that the real time elements run on the NXT and use a custom protocol to communicate with the PC side of things. There were good reasons to support this initially as early versions of leJOS were pretty limited, but as time has moved on supporting remote operation has been more of problem and has received less and less attention.

To answer some of your other questions posted on the developer list (but probably of more general interest). Development of the NXT version of leJOS has slowed down a lot at the moment. I think most of the developers are looking forward to the EV3 and probably consider that the current version for the NXT is reasonably complete (if still a little rough around the edges). There are some pretty substantial features in the developer snapshot that have not received much testing (notably remote debug capabilities), but other than that most things seem pretty stable.

All of the above is just my view on things...

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

Re: Failure using lejos code to communicate with robotc firm

Postby positron96 » Sun Jul 28, 2013 3:00 pm

Hello.

I do not need RobotC specifically, but we'll soon have an event where I'll need to control several NXTs, and they could be of any firmware as I have no access to them to reflash. So I am testing my code to work with any guest firmware.
Actually I think LCP has a big advantage over a custom-made protocol: it is a defined standard that will work on every NXT and from any device programmed to use it: android devices, mobile phones, whatever. I think it's very good that lejos supports it, otherwise a lot of remote control programs (pretty much all of them) would not work with lejos.

Side question:
Lejos has remote debug??? Like in jdwp support?? Where can I read about it and test it? Right now remote debug is RobotC killer feature that makes it unique.
positron96
New User
 
Posts: 21
Joined: Fri Jun 29, 2012 11:55 am

Re: Failure using lejos code to communicate with robotc firm

Postby gloomyandy » Sun Jul 28, 2013 6:46 pm

The latest snapshot has remote debug using jdwp. You can use it with the latest version of eclipse plug in. It has not been tested that much and only operates via a Bluetooth connection.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3964
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Failure using lejos code to communicate with robotc firm

Postby positron96 » Mon Jul 29, 2013 9:01 am

Will the latest version of Eclipse plugin from repository work (It's 0.9.0.201202141552)? If no, how do I install the required version?
positron96
New User
 
Posts: 21
Joined: Fri Jun 29, 2012 11:55 am

Re: Failure using lejos code to communicate with robotc firm

Postby skoehler » Mon Jul 29, 2013 11:46 am

I think this might be my mistake. We currently don't have a proper detection whether the NXT is running Lego, leJOS, or some other firmware.
I was planning to add that, but it was delayed. Also, I don't have a copy of RobotC and thus couldn't test it. What other firmware's exist and implement LCP?

The problem is that Lego's firmware doesn't reply with an error to unknown system commands - it simply treats an unknown system command as one of the standard system commands (not sure which).
It seems RobotC is even worse: it doesn't send any response at all!

Unknown direct commands however were acknowledged with an error reply by the Lego firmware, if I remember correctly. I was planning on using such a command to detect whether the robot is running Lego or leJOS. If RobotC doesn't send an error then that wouldn't work either. Do you have any idea, how the RobotC tool can detect whether the robot is running RobotC or not? Maybe that could be extended to a mechanism used by leJOS.

positron96 wrote:Actually I think LCP has a big advantage over a custom-made protocol: it is a defined standard that will work on every NXT and from any device programmed to use it: android devices, mobile phones, whatever.


LCP is a questionable protocol as far as its design is concerned. It is fairly limited, and you should call yourself lucky if it actually fits your needs. Also, we don't really have a good or even full documentation of LCP. The Lego firmware supports many more commands then leJOS does. As far as I remember, when I last tried to use the Lego software with a brick running leJOS, it failed because of some commands listed nowhere in the documentation.
skoehler
leJOS Team Member
 
Posts: 1405
Joined: Thu Oct 30, 2008 4:54 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 3 guests

more stuff