ev3 API used to control NXT and Ev3 at the same time

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

Moderators: roger, gloomyandy, skoehler

clemens
Novice
Posts: 26
Joined: Mon Mar 02, 2015 8:15 am

ev3 API used to control NXT and Ev3 at the same time

Postby clemens » Mon Mar 02, 2015 8:18 am

Folks -
I am moving my codebase from supporting an nxt brick (with lejos 0.9.1 API) to support also the new ev3 brick. The new API makes me a little clueless – if I start from brickfinder.discover – I get BrickInfo objects – but where to go from there?

In the old world (lejos 0.9.1 API for NXT) I used

final NXTConnectionManager connManager = new NXTConnectionManager();
NXTInfo [] robots = connManager.search();
NXTInfo robotInfo = robots [0];

NXTConnector connector = new NXTConnector ();
boolean isConnected = connector.connectTo(robotInfo, 1);

if (!isConnected) throw new Exception (“Could not connect to NXT ” + robotInfo.name);

nxtCommand = new NXTCommand(connector.getNXTComm()); and then I initialized the sensors with it ...

But how does this work now with brickinfo?!

thanks

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

Re: ev3 API used to control NXT and Ev3 at the same time

Postby gloomyandy » Mon Mar 02, 2015 9:02 am

Please don't use the leJOS development section of the forum to ask questions about the existing API. I have moved your thread to a more appropriate place.

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

Re: ev3 API used to control NXT and Ev3 at the same time

Postby gloomyandy » Mon Mar 02, 2015 9:17 am

So what is it that you do not understand? You have seen the code posted on the leJOS news blog that uses the BrickFinder and RemoteEV3 classes. If you are trying to connect to an NXT there is a similar RemoteNXT class that can be used to access the NXT resources. What is it that you are struggling with? What is it you are actually trying to do? Are you trying to control an EV3, an NXT, both? Where are you trying to control them from, a PC, an EV3?

clemens
Novice
Posts: 26
Joined: Mon Mar 02, 2015 8:15 am

Re: ev3 API used to control NXT and Ev3 at the same time

Postby clemens » Mon Mar 02, 2015 9:46 am

gloomyandy wrote:Are you trying to control an EV3, an NXT, both? Where are you trying to control them from, a PC, an EV3?


So here is what I want to do:

a) discover all ev3 and NXT bricks around via Bluetooth (from a PC / Server from a bpm / acm type of engine (to build an IoT pilot) - which was published in http://futstrat.com/books/ThrivingOnAdaptability.php recently)
b) connect to them, and work with them, e.g. run around etc

Today - with NXT lejos API - this is extremly easy, as noted in the first post above. With the changes to the API - unfortunately there does NOT seem to be a single entrypoint - but rather two routes (and a disconnect from brickfinder.discover).

Preferrably I would like to see a single API - that supports both NXT and EV3 - something along the lines of

a) BrickFinder.discover : BrickInfo (including a type enum rather than strings)
b) BrickConnectionFactory.connect (BrickInfo) : Brick
c) Brick.getPort(...) : Port
d) BrickConnectionFactory.connect (<T>, Port) : <T>
e) Brick.close ()

dont get me wrong - no offense etc, just a bunch of thoughts.

Cheers

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

Re: ev3 API used to control NXT and Ev3 at the same time

Postby gloomyandy » Mon Mar 02, 2015 10:48 am

Hi,
the current support for remote NXT access from the EV3 source base is pretty limited and has not had much work on it. You are probably talking to the wrong developer about this sort of thing. Personally I'm not a fan of remote control type applications and so this side of the project does not hold much interest for me (the notion of "daisy chaining" seems like a waste of an EV3). Not all of the leJOS developers share my views on this! Having said that I would not be in favour of attempting to try and hide the many differences between the EV3 and NXT via an API like the one you are suggesting. That approach tends to lead to a dumbing down of the more capable device and limits future development (we had a lot of issues with this on the NXT, the remote API often forcing compromises on the local structure and capabilities).

So for instance with the EV3 we have been experimenting with using higher levels in the motor and sensor stacks as the remoting point (above the port level), these APIs are not really available on the NXT (since it uses a LEGO compatible remote protocol). If we needed to keep things compatible we could not use these interfaces (we could emulate them but there would be a significant performance difference).

Having said that some of the other leJOS developers may want to take things in this direction, or you could do so yourself. All of the leJOS source code is available for you to use and modify. If we like the results then we may incorporate it in the standard release. Remember it is easy to add your own remote protocols, just create a server program that supports whatever mechanism you want to use and set it to be the default program. That way whenever the EV3/NXT starts your server will be running and is available for you to talk to. If you do this you can decide what level of abstraction to export from the device, how much intelligence to run locally on the EV3/NXT, to me this is a far better solution than trying to shoe horn things to use some sort of generic protocol that has been defined for some other purpose. The final two parts of the series of articles on EV3 to EV3 operations will cover some of this ground.

Right I'll get off my soap box now...

clemens
Novice
Posts: 26
Joined: Mon Mar 02, 2015 8:15 am

Re: ev3 API used to control NXT and Ev3 at the same time

Postby clemens » Mon Mar 02, 2015 1:16 pm

gloomyandy wrote:of attempting to try and hide the many differences between the EV3 and NXT via an API like the one you are suggesting. That approach tends to lead to a dumbing down of the more capable device and limits future development (we had a lot of issues with this on the NXT, the remote API often forcing compromises on the local structure and capabilities).

So for instance with the EV3 we have been experimenting with using higher levels in the motor and sensor stacks as the remoting point (above the port level), these APIs are not really available on the NXT (since it uses a LEGO compatible remote protocol). If we needed to keep things compatible we could not use these interfaces (we could emulate them but there would be a significant performance difference).


I hear you - true. Yet if specifics are needed a developer can go and cast to the implementation, done. :-D

If I have some time - I'll try to make this work and contribute it back,... :shock:

But back to the original question:
how do I get from brickInfo to
a) a connected NXT and
b) a connected ev3

Cheers

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

Re: ev3 API used to control NXT and Ev3 at the same time

Postby gloomyandy » Mon Mar 02, 2015 2:40 pm

Well the code for the EV3 is sitting there in the article:
BrickInfo [] ev3s = BrickFinder.discover();
brick = new RemoteEV3(ev3s[0].getIPAddress())
This will connect to the first EV3 found. If there is more than one I'm sure you can work it out. Note that if want to talk to an EV3 over Bluetooth from a PC you must establish a PAN connection to it first. If you want to talk to multiple EV3s then you need a post 0.9.0 version of leJOS and you need to join all of the EV3s into the PAN.

For the NXT something like:
BrickInfo [] nxts = BrickFinder.discoverNXT();
brick = new RemoteNXT(nxts[0].getIPAddress(), new BTConnector())
will work I think. I've never used that code so have no real idea. As I've already said though the code for talking to an NXT is very limited and has not been used very much. This is especially true if you are trying to run this code on a PC. I don't think this code will work at all in that situation. You may need to use the existing NXT PC side API if you want to talk to an NXT from a PC.

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

Re: ev3 API used to control NXT and Ev3 at the same time

Postby gloomyandy » Mon Mar 02, 2015 2:48 pm

So out of interest have you actually used the current API to connect to and control multiple NXTs?

clemens
Novice
Posts: 26
Joined: Mon Mar 02, 2015 8:15 am

Re: ev3 API used to control NXT and Ev3 at the same time

Postby clemens » Mon Mar 02, 2015 4:46 pm

gloomyandy wrote:So out of interest have you actually used the current API to connect to and control multiple NXTs?


yup, after changing the code a little :-) (and removing all the singleton stuff from the implementation, and change it to nxtCommand / ports as parameters :D).

NXTConnector connector = new NXTConnector ();
boolean isConnected = connector.connectTo(robotInfo, 1);

if (!isConnected) throw new Exception ("Could not connect to NXT " + robotInfo.name);

nxtCommand = new NXTCommand(connector.getNXTComm());

leftMotor = new RemoteMotor(nxtCommand, 1);
rightMotor = new RemoteMotor(nxtCommand, 2);

colorSensor = new ColorSensor(new SensorPort(3, robot.getNxtCommand()));

-- the only thing that is slightly yak is the whole arbitrator stuff :-) other than that - it works like a charm, and I have an ontology backing all the knowledge of the robots, so if you plug in new ones, they just do what they others already learned :-)

Cheers


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 2 guests