artificial horizon with the nxt

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

artificial horizon with the nxt

Postby DerSani » Fri Nov 13, 2009 11:14 pm

Hello everyone,

I will try to make a artificial horizon, with a compass sensor and a acceleration sensor.

The horizon and the compass will be displayed on the NXT, so I am going to write some graphical classes for the NXT.

I plan to load the up, so maybe someone can add it to the project.

I start the project next week.

Greetings

DerSani
DerSani
New User
 
Posts: 10
Joined: Mon Nov 02, 2009 8:21 am
Location: Germany

Postby gloomyandy » Sat Nov 14, 2009 8:10 am

Hi,
I'm not sure what graphical classes you need but leJOS already has a number of graphical methods (bitBllt, line/circle drawing, retangles, filled rects etc.), which you may want to use as the basis for whatever you do (particularly bitBlt which is pretty efficient at getting things on screen)...

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

Postby DerSani » Wed Nov 18, 2009 10:09 am

Oh, that's a good hint.

I looked at the API, but I didn't find anything. I think I do this not accurate enough.

Thanks a lot, I will have a second look into the docs. :wink:

DerSani
DerSani
New User
 
Posts: 10
Joined: Mon Nov 02, 2009 8:21 am
Location: Germany

Postby gloomyandy » Wed Nov 18, 2009 11:55 am

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

Postby DerSani » Sun Jan 10, 2010 9:29 pm

thx for the classes Andy, but I have new problem.

How I can draw polygons, I think about to manage that with the Image, first I write the stuff into an Image and than on the LCD.

The last step is no prob.

I tried to make an Image, but I don't know how to set the bits right.

Have anyone a hint or a link?

Thanks a lot

Sani
DerSani
New User
 
Posts: 10
Joined: Mon Nov 02, 2009 8:21 am
Location: Germany

Postby gloomyandy » Sun Jan 10, 2010 10:34 pm

Is there a reason why you can't just draw directly to the screen? The graphics class contains line drawing functions that you can use. I guess there are no easy ways to draw a filled polygon if that is what you are trying to do. I've just made some fairly major changes to the graphics functions (to among other things allow them to be used to draw to Images), but these changes are currently only available in the dev snapshot.

The actual Image format matches the layout used for the NXT LCD screen and is not very easy to use. You could write to it directly. A description of the layout is given in this link...
http://lejos.svn.sourceforge.net/viewvc ... iew=markup

However it is actually easier (and faster) to use the bitBlt function to draw a single pixel sized rectangle (the new code implements the drawing functions this way)....

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

Postby DerSani » Sun Jan 17, 2010 8:47 pm

Hello,

sorry for my late posting , I had a bad flu.

Ok, I am not the fittest in this stuff, I only want to rotate an rectangle, how can I do this with the method?

My problem is, that I don't really understand the bitBlt-function.

Can you give me a short example for a given rectangle, please?

Greetz

Marcel
DerSani
New User
 
Posts: 10
Joined: Mon Nov 02, 2009 8:21 am
Location: Germany

Postby DerSani » Sun Jan 17, 2010 11:40 pm

I have found a way but I set every pixel, is there a easier way?

Code: Select all
public static final void paintHorizont(int angleH, int angleV) {
      
      angleH = makeClearAngles(angleH);
      angleV = makeClearAngles(angleV);
      
      double cos = Math.cos(angleV);
      double sin = Math.sin(angleV);
      int yPoint = 32;
      
      if (angleV % 90 != 0) {
         cos /= 10;
         sin /= 10;
      }
      
      if(angleH <= 270) {
         yPoint = 32 - (int) (angleH * 0.35);
      } else {
         yPoint = 160 - (int) (angleH * 0.35);
      }

      for (int x = 0; x <= LCD.SCREEN_WIDTH; x++) {
         for (int y = 0; y <= LCD.SCREEN_HEIGHT; y++) {
            int mapX = -49 + x;
            int mapY = -(yPoint) + y;
            int testY = (int) (mapX * sin + mapY * cos);
            if (testY >= 0 && testY < 64) {
               LCD.setPixel(1, x, y);
            }

         }
      }
   }


Greetz
DerSani
DerSani
New User
 
Posts: 10
Joined: Mon Nov 02, 2009 8:21 am
Location: Germany

Postby gloomyandy » Mon Jan 18, 2010 12:26 am

Hi,
You will probably have to do something like that. You can use bitBlt to set a single pixel and do the clipping for you by using...


LCD.bitBlt(display, LCD.SCREEN_WIDTH, LCD.SCREEN_HEIGHT, 0, 0, display, LCD.SCREEN_WIDTH, LCD.SCREEN_HEIGHT, x, y, 1, 1, LCD.ROP_SET);

where display is the return value from LCD.getDisplay()

instead of...

if (testY >= 0 && testY < 64) {
LCD.setPixel(1, x, y);

This will set pixels to black, if you want to set them to white use ROP_CLEAR.

The native method is a little faster than accessing the display as an array (which is what the setPixel code uses)...

I have improved the leJOS graphics classes quite a bit (you can now use them with images, we have multiple fonts, load images from files etc.). But these are only available in the developer builds at the moment. You can see the code here...

http://lejos.svn.sourceforge.net/viewvc ... ion/lcdui/

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

Postby DerSani » Thu Feb 25, 2010 12:53 am

Hi,

thanks for your help gloomyandy, it works! I have namend you in the Credits, as a little tribute :) .

Greetz

Marcel
DerSani
New User
 
Posts: 10
Joined: Mon Nov 02, 2009 8:21 am
Location: Germany


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff