LeJos: all robot classes and methods in 1?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

LeJos: all robot classes and methods in 1?

Post by HaWe »

hi,
is it possible to bring all LeJos robot classes and methods together in 1 Super_Class to access all LeJos robotic features (like motors, sensors, COMM, threads, subsumption, navigation,...) by 1 robotic class?
Will it be possible to use them by a procedural programming style like by NXC, Pascal, and Basic? Without need to use OOP stuff (new / public /static / private / class / extends...)?
like

Code: Select all

motor(1, 70); //port 1, 70%/forward
motor(2, -70); //port 1, -70% /reverse
setsensor (2, Touch); // Touch sensor port 2
value=Sensor(2);

(as I only have 1 robot I dont need stuff like myRobot.motor...)
- Java unleashed ! -
physics-matt
Posts: 76
Joined: 29 Sep 2010, 06:57

Re: LeJos: all robot classes and methods in 1?

Post by physics-matt »

Can't you do this by defining one uber-class which has an instance of all the other classes?

However, you will never be able to get rid of the OO syntax: in Java, everything is a class and all functions are methods of those classes.

Matt
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: LeJos: all robot classes and methods in 1?

Post by HaWe »

physics-matt: :roll:
Can't you do this by defining one uber-class which has an instance of all the other classes?
I don't know, I was the one who asked that question... :?
However, you will never be able to get rid of the OO syntax: in Java, everything is a class and all functions are methods of those classes.
maybe if using #defines?
as I don't know anything about the issues of my TO question, here again:
doc-helmut wrote:hi,
is it possible to bring all LeJos robot classes and methods together in 1 Super_Class to access all LeJos robotic features (like motors, sensors, COMM, threads, subsumption, navigation,...) by 1 robotic class?
Will it be possible to use them by a procedural programming style like by NXC, Pascal, and Basic? Without need to use OOP stuff (new / public /static / private / class / extends...)?
like

Code: Select all

motor(1, 70); //port 1, 70%/forward
motor(2, -70); //port 1, -70% /reverse
setsensor (2, Touch); // Touch sensor port 2
value=Sensor(2);

(as I only have 1 robot I dont need stuff like myRobot.motor...)
- Java unleashed ! -
Last edited by HaWe on 28 Oct 2010, 20:15, edited 1 time in total.
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: LeJos: all robot classes and methods in 1?

Post by gloomyandy »

Java does not have #define... (though you could use some other sort of pre-processor).

You could as you and Matt suggested put them all in one big class (called say c), but normally you would then have to access the methods via c.methodName(....) . You could then pre-process your programs to remove the "c.", but then you would still have to deal with all of the other features of Java that you probably don't like (such as new, exception handling, etc.). You would also have to have a huge number of methods in that class, which I'm sure would result in name clashes (one of the things that Java helps you avoid). The last time I checked there were getting on for 400 classes in the leJOS class library each one has constants and methods, many of which deliberately (this is OO) share the same names.... I guess you could do some more pre-processing and add a class name based pre-fix to each method name, but it all starts to get out of hand...

So in theory yes you could do it, but I'm not sure it makes any sense to... If you want to use the leJOS classes you probably have to get to grips with Java (or at least an OO language of some sort, that shares a similar programming model)...
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: LeJos: all robot classes and methods in 1?

Post by HaWe »

to my experience, everybody got his own cognitive limitations. One may find his limitations in organic chemistry, another one in quantum mechanics, another one in number theory.
To me it's object oriented programming. :cry:
I'd like to use LeJos, but without objects.
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: LeJos: all robot classes and methods in 1?

Post by gloomyandy »

Yes I can understand that. Unfortunately the leJOS classes are designed assuming an OO model (as are the generic Java classes), trying to use them in another way would mean using them in ways probably not envisaged in the original design. Things that should be simple will be hard... Also I suspect that trying to get any help would also be difficult, you would be asking a group of people who have chosen to use Java probably because that fits the way they think, to try and look at the same thing from a very different perspective, never an easy thing to do (interesting though it may well be)...

You can write Java in a very C like way. I often do this to prototype code in Java before moving it into the leJOS firmware (I wrote the leJOS BitBlt screen update routines this way). It is also pretty easy to convert C code to Java (the Kalman filter I used in my segway project came from the open source autopilot project and was originally in C), but converting OO Java code that uses the full set of features provided by the language into C is a lot more difficult...
physics-matt
Posts: 76
Joined: 29 Sep 2010, 06:57

Re: LeJos: all robot classes and methods in 1?

Post by physics-matt »

doc-helmut wrote:
Can't you do this by defining one uber-class which has an instance of all the other classes?
I don't know, I was the one who asked that question... :?
Sorry, I was using a very English idiom there. It means "I think it is possible to define an uber-class".

Why don't you give it a try?
doc-helmut wrote: I'd like to use LeJos, but without objects.
The problem is that object orientation is absolutely core to the language. Trying to use Java without objects would be like trying to use C without functions (actually, it would probably be even harder as you wouldn't be able to run programs EDIT: Then again, you couldn't write your main function in C either, so I guess both languages would be similarly crippled)

Why do you want to use LeJos then? Is it for the firmware? I couldn't fail to spot it supports recursion...

Matt
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: LeJos: all robot classes and methods in 1?

Post by HaWe »

physics-matt: :roll: (could you please put me on to your ignore list?)
gloomyandy:
I have 1 robot to control, not a pack or horde of robots which bequeath their propeties and facilities like motor(1, 70) to each other.
So it must be possible to access 1 robot' s motor by motor(1, 70) even if it's programmed in Java.
It's nothing more or less than cut down the classes and methods of all robotic packs down to 1 simple (but universal) instance.

Will it not be possible for a Lejos developer to cut all the objects and methods down to simple functions and procedures?

edit: or write a ANSI C-parser that uses the LeJos firmware?
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: LeJos: all robot classes and methods in 1?

Post by mightor »

Doc,

Stop trying to make all the other languages be something they're not. If you want ANSI C, use nxtOSEK, NXOS or Trampoline. If you don't want to use those, use what's given to you and be happy with it. You wouldn't use a screwdriver to hammer in a nail, would you?

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: LeJos: all robot classes and methods in 1?

Post by gloomyandy »

doc-helmut wrote: So it must be possible to access 1 robot' s motor by motor(1, 70) even if it's programmed in Java.
It's nothing more or less than cut down the classes and methods of all robotic packs down to 1 simple (but universal) instance.
Well you can already do something not that far from that with...
Motor.A.forward() or Motor.A.rotate(70)... Which is a little more verbose but arguably easier to understand. But the problem is that if you want to use these commands you will eventually want to use arrays and other structured types (such as classes), which means you will have to deal with the OO nature of Java.
Will it not be possible for a Lejos developer to cut all the objects and methods down to simple functions and procedures?
Yes I'm sure it is possible. But the problem is who would want to do it? All of the leJOS developers are probably leJOS developers because they like Java, and OO. They are unlikely to be interested in removing the objects etc...
edit: or write a ANSI C-parser that uses the LeJos firmware?
There are many alternate languages that target the JVM (and so use Java byte code, and in theory could generate code that runs on the leJOS firmware). The problem is that most of them are even more OO than Java... However there are few ansi c implementations see:
http://en.wikipedia.org/wiki/Java_Virtu ... _compilers
But you will still then have the problem of how to use a set of classes/libraries, that have been written assuming an OO model and language from a language that does not support OO...
Locked

Who is online

Users browsing this forum: No registered users and 1 guest