NXC classes

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

NXC classes

Post by mattallen37 »

Is it reasonably likely that NXC will support classes in the not-so-distant future?

Class support could be a huge time and resource saver.

I guess the answer is probably no, because otherwise it would likely already support them.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC classes

Post by mightor »

If you're looking for an OOPL, you might want to check out Lejos. A language where OO is an afterthought will end up feeling like an ugly kludge, like Perl's OO implementation.

- 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)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC classes

Post by mattallen37 »

In the past I have considered leJOS, but for now I want to stick with C type languages. I feel like I am fairly versed in NXC, as it's the primary language I used for learning programming concepts, and I would like to be able to learn more about classes in a familiar setting. So far I have only used classes in C++ for Arduino libraries, and I really love them.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC classes

Post by mightor »

Lejos is not that scary :) It has a very rich collection of classes, I think you'll like it.

- 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)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC classes

Post by afanofosc »

I think Matt would like leJOS too. The only drawback being that you have to switch to a firmware that does not support NXT-G, if you want to keep using that language for some reason.

In any case, I have no plans for trying to add support for classes to NXC.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC classes

Post by mattallen37 »

Thanks both of you.

I'm not concerned in the least with putting leJOS FW on one of my NXTs ;)

Okay, that's fine.

I'll look into trying out leJOS.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
tcwan
Posts: 186
Joined: 30 Sep 2010, 07:39

Re: NXC classes

Post by tcwan »

mattallen37 wrote:In the past I have considered leJOS, but for now I want to stick with C type languages. I feel like I am fairly versed in NXC, as it's the primary language I used for learning programming concepts, and I would like to be able to learn more about classes in a familiar setting. So far I have only used classes in C++ for Arduino libraries, and I really love them.
Well, you don't actually have to run Java. There is also nxt-OSEK which you can program in C++ http://lejos-osek.sourceforge.net/
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: NXC classes

Post by pepijndevos »

Or Mirah, which is more like Ruby than C, I guess, but anyway, runs like a charm on Lejos.
-- Pepijn
http://studl.es Mindstorms Building Instructions
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC classes

Post by spillerrec »

mightor wrote:If you're looking for an OOPL, you might want to check out Lejos. A language where OO is an afterthought will end up feeling like an ugly kludge, like Perl's OO implementation.
I do like the C++ syntax though and I think OO would be a nice addition to NXC. I did make some deeper considerations on how to make OO work on the NBC level and I think it would feasible to have basic OO support in NXC. (I wrote a post with my thoughts on my blog back then.)

One of the reason I think OO would work well with NXC is because of the underlying firmware. Many of the basic functions is implemented by the use of structs so an OO interface to those makes much sense. For example LineOut could be implemented like this:

Code: Select all

class Line{ //This class is the DrawLineType struct type
	public:
		char Result;
		LocationType StartLoc;
		LocationType EndLoc;
		unsigned long Options;

		Line( LocationType start, LocationType end ){
			StartLoc = start;
			EndLoc = end;
		}
		
		Line( int x1, int y1, int x2, int y2 ){
			StartLoc.Set( x1, y1 );
			EndLoc.Set( x2, y2 );
		}
		
		void draw(){
			SysDrawLine( this ); //ASM here, just can't remember it from the top of my head...
		}
		
	private:
		static Line temp;
		static mutex tempmutex;
	public:
		static char draw( int x1, int y1, int x2, int y2, Options = DRAW_OPT_NORMAL ){
			Acquire( tempmutex );
			temp.StartLoc.Set( x1, y1 );
			temp.EndLoc.Set( x2, y2 );
			temp.Options = Options;
			temp.draw();
			return l.Result; //This would need to be done in ASM so Release is actually executed
			Release( tempmutex );
		}
		
		static char draw( LocationType start, LocationType end, Options = DRAW_OPT_NORMAL ){
			Acquire( tempmutex );
			temp.StartLoc = start;
			temp.EndLoc = end;
			temp.Options = Options;
			temp.draw();
			return l.Result; //Same note as above
			Release( tempmutex );
		}
};
Taking the notes in account, this is pretty much the same way as it works in NXC right now just in OO style. The only difference is that this is inline functions where the NXC headers uses macro functions. (Sadly, the NXC compiler didn't do a good job with inline functions last time I checked...)
You could make some pretty neat API improvements imo.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC classes

Post by mightor »

pepijndevos wrote:Or Mirah, which is more like Ruby than C, I guess, but anyway, runs like a charm on Lejos.
I had a quick peek at Mirah but I am not seeing the advantages of running that on a JVM vs Java. What can I do with Mirah that Lejos won't let me? How would you use it combination with Lejos' classes or is that not an option and would one have to redevelop all of those?

- 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)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest