Go to Post Dave Lavery, Lou Rosanio and Karthik are all Woodie Flowers winners this year. So mentors it seems like if ya want the WFA it might be a good idea to put on a kilt :) - Kyle [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 06-11-2010, 18:05
RoboMaster's Avatar
RoboMaster RoboMaster is offline
Alum, former programmer&co-captain
FRC #2472 (The Centurions)
Team Role: Mentor
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Minnesota, Twin Cities
Posts: 268
RoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant future
Computer playing Bejeweled Blitz project

As started in this thread, I'm actually working on this project. I have chosen Facebook's Bejeweled Blitz*, like was first suggested.

I've worked on it a bunch so far and have made a main program with the different parts sketched out. I only have the computational part right now, but it finds matches and knows where to move what gem where. It looks at an array of numeric values, which be converted to from the screen.It doesn't find "gap" matches yet, where there's two gems in a row with a gap in the middle that you can fill in with a third. It only looks for a row of 2 that it can complete. It does this by looking at a theoretical position to move the current gem being tested. Then it looks around that gem to see if there's one match with the original. If so, it looks further in the same direction to see if there's a second match. It counts that as a full match and passes that on the the rest of the program.

Now I need to code up how it will interact with the computer. It was suggested to interact with the Windows API to control the mouse and click in the right spots to move the gems. The Library Call node will do this for you. I looked into it though, and configuring it is beyond me since I don't know a lot about API commands. Does someone have an example or tutorial on how to use them with LabVIEW? I've Googled it and looked at NI's Dev Zone, but a lot of things expect you to know about Windows API.

Also, anyone have any suggestions for looking at the screen and getting the colors of certain pixels? I know you could do a screen capture somehow and then save the file and analyze it, but I think that might slow and/or a round-about way of doing it. Again, this might take some API work.

Thanks for your help! I've attached the VI's in case you're interested. You can run them and they'll work, I've put in the test screen shot into the array. Sorry that there's not a ton of documentation yet.


*An 8x8 playing "board" that has gems you must switch to make 3 in a row or more. Then these gems disappear and more drop from the top, Connect 4 style.
Attached Thumbnails
Click image for larger version

Name:	Test_Shot_1.jpg
Views:	20
Size:	33.4 KB
ID:	9396  
Attached Files
File Type: vi Main.vi (11.2 KB, 15 views)
File Type: vi Move.vi (15.6 KB, 13 views)
File Type: vi M_L1 match test (SubVI).vi (7.8 KB, 15 views)
__________________
My engineering blog: noeticbrainwaves.blogspot.com

I'm not slacking, my code's compiling
...and I'm using LabVIEW
Reply With Quote
  #2   Spotlight this post!  
Unread 07-11-2010, 01:57
biojae's Avatar
biojae biojae is offline
Likes Omni drives :)
AKA: Justin Stocking
FTC #5011 (BOT SQUAD) && FTC#72(Garage bots)&& FRC#0399 (Eagle Robotics)
Team Role: College Student
 
Join Date: Oct 2008
Rookie Year: 2008
Location: Lancaster
Posts: 276
biojae is a jewel in the roughbiojae is a jewel in the roughbiojae is a jewel in the rough
Re: Computer playing Bejeweled Blitz project

MSDN is your friend

http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx


This function allows you to move the mouse:
Code:
BOOL WINAPI SetCursorPos(
  __in  int X,
  __in  int Y
);
it is in the file: User32.dll
X and Y are absolute coordinates on the screen
with 0,0 being the upper left corner of the screen

It returns a boolean value.

It is a similar call to get the cursor's position
Code:
BOOL WINAPI GetCursorPos(
  __out  LPPOINT lpPoint
)

typedef struct {
  LONG x;
  LONG y;
} POINT;
I do not know how to use the labview library call node, but this should help.
__________________
FTC Team 72 - No site
FRC Team 399 - http://www.team399.org
2010 Rockwell Collins Innovation in Control Award - (Use of the CAN bus, among other reasons) Phoenix, Arizona!
Reply With Quote
  #3   Spotlight this post!  
Unread 07-11-2010, 09:33
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Computer playing Bejeweled Blitz project

The clf (Call Library Function) node needs the name and/or path to the library and the function call info to be configured. I believe the example or tutorial retrieves the computer name, and would work fine as a template for your usage. If you are calling the function more than once, it is a good idea to make a subVI wrapper, since the configuration and appearance other ways get annoying.
It is possible to use GDI calls to get the window handle for other apps, and to use bitable to copy a portion of their window into your own, and then to implement GetPixel() or something similar. Possible, but certainly easy. Using a camera to capture the screen will likely have issues with aliasing, lighting, and calibration. Not a cakewalk, but good practice if you want to use the camera on the robot.

Greg McKaskle
Reply With Quote
  #4   Spotlight this post!  
Unread 07-11-2010, 17:29
RoboMaster's Avatar
RoboMaster RoboMaster is offline
Alum, former programmer&co-captain
FRC #2472 (The Centurions)
Team Role: Mentor
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Minnesota, Twin Cities
Posts: 268
RoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant future
Re: Computer playing Bejeweled Blitz project

Wow, that helps a whole bunch more, thanks! That function is one of what I'm looking for. I even poked around, found user32.dll, configured the node, and it worked! Screenshots of configuration attached. It certainly helped to know a little bit about C-like functions for the parameters tab.
I looked at msdn before but couldn't find anything...thanks for the link. I looked at the other cursor functions but there wasn't one to click the mouse/cursor, so maybe the user will have to do that quickly when prompted to.

Thanks Greg for the tip about the GDI and GetPixel calls, I'll look them up on msdn. Yes, I've looked at that example you were talking about and some other ones too, but they were still a little over my head.


So let me get this straight for my sake and anyone else's who might look at this and not know--the Call Library Function Node basically calls/uses a function in a library that you specify. A .dll file is a compressed library with many functions that can be used universally with many systems/programs. And user32.dll is a library that has many/all of the Windows API functions, which can be used by other programs to interact with windows. Aren't they written in a unique programming language that is very similar to C/Java/most text-based languages?

EDIT: well now that I think about it, of course there wouldn't really be a function to "click" the mouse; you're the one that's clicking it and the software is sensing that. But maybe if there was a function to send a universal "click signal" to all of Windows, or all the programs waiting for a click, or the general windows mouse driver, etc.
Attached Thumbnails
Click image for larger version

Name:	Configuration_Call_Library_Function.png
Views:	19
Size:	41.1 KB
ID:	9406  Click image for larger version

Name:	2_Configure_Call_Library_Function.png
Views:	14
Size:	39.6 KB
ID:	9407  
__________________
My engineering blog: noeticbrainwaves.blogspot.com

I'm not slacking, my code's compiling
...and I'm using LabVIEW

Last edited by RoboMaster : 07-11-2010 at 18:23.
Reply With Quote
  #5   Spotlight this post!  
Unread 07-11-2010, 23:36
Fletch1373's Avatar
Fletch1373 Fletch1373 is offline
Registered User
AKA: Fletch
FRC #3181 (Panthers)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Rochester, NY
Posts: 251
Fletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud of
Re: Computer playing Bejeweled Blitz project

Quote:
Originally Posted by RoboMaster View Post
I looked at msdn before but couldn't find anything...thanks for the link. I looked at the other cursor functions but there wasn't one to click the mouse/cursor, so maybe the user will have to do that quickly when prompted to.
There actually is a function listed on MSDN, called 'mouse_event()'


Note that this function has been superseded(and included by me for reference purposes). You should be using the second function I found, called 'SendInput()'

Both are housed in 'User32.dll' so you're fine there.


I'm not much of a LabView guy, so I'm not sure how easy it would be to implement either of these API calls, but I hope I could help either way.
__________________
Student:
<04: FRC0213> <05-08: FRC1373>
Mentor:
<09-10: FRC0809> <11-12: FRC3555> <12-14: FRC0073> <15-??: FRC3181>
Volunteer:
<FTAA> <CSA> <Defense Coordinator> <Scorekeeper> <Robot Inspector> <Official Scorer>
2016 Tour:
CTWAT [DefCoord] > Pittsburgh[Mentor/DefCoord] > TVR[FTAA] > FLR[CSA] > NE DCMP[CSA] > CMP[CSA]
Reply With Quote
  #6   Spotlight this post!  
Unread 08-11-2010, 19:28
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Computer playing Bejeweled Blitz project

Quote:
So let me get this straight for my sake and anyone else's who might look at this and not know--the Call Library Function Node basically calls/uses a function in a library that you specify. A .dll file is a compressed library with many functions that can be used universally with many systems/programs. And user32.dll is a library that has many/all of the Windows API functions, which can be used by other programs to interact with windows. Aren't they written in a unique programming language that is very similar to C/Java/most text-based languages?
You seem to have it pretty straight. Libraries are a general concept found on most operating systems. They are a collection of functions that do useful things, and are hopefully documented and grouped according to their functionality. What are they written in? It depends. On the original Mac and Lisa, they were in Pascal and some assembly. C was the language developed for developing unix, and not surprisingly, most of the libraries for linux are still written in C. I believe the NeXT was built around Objective C, BeOS may have had some amount of C++. There were OSes built around Lisp, and of course before C, most OSes were written in Assembly or even lower level.

In reality, the language the functions are written in isn't important, but the calling conventions are. Notice the dialog for clf asks you the calling conventions? That is because Windows actually has several conventions. These conventions specify how a calling function passes parameters to the called function and retrieves results. This is done differently on different computer architectures and on different OSes.

Given the information you gave LV about the parameters, it takes the wire information and pushes the parameters onto the stack according to the stdcall conventions, executes the call instruction with the address to your function in the library, then retrieves the results and does any stack or register cleanup as specified by the convention. As long as the conventions are followed, any language can reuse code from any other. To flip roles, you can build a DLL from LV so that it can be called from any program capable of calling into a Windows library.

Greg McKaskle
Reply With Quote
  #7   Spotlight this post!  
Unread 08-11-2010, 21:07
biojae's Avatar
biojae biojae is offline
Likes Omni drives :)
AKA: Justin Stocking
FTC #5011 (BOT SQUAD) && FTC#72(Garage bots)&& FRC#0399 (Eagle Robotics)
Team Role: College Student
 
Join Date: Oct 2008
Rookie Year: 2008
Location: Lancaster
Posts: 276
biojae is a jewel in the roughbiojae is a jewel in the roughbiojae is a jewel in the rough
Re: Computer playing Bejeweled Blitz project

Quote:
Originally Posted by Greg McKaskle View Post
To flip roles, you can build a DLL from LV so that it can be called from any program capable of calling into a Windows library.
e
Would an application that uses such a dll require the labview runtime engine to run?
__________________
FTC Team 72 - No site
FRC Team 399 - http://www.team399.org
2010 Rockwell Collins Innovation in Control Award - (Use of the CAN bus, among other reasons) Phoenix, Arizona!

Last edited by biojae : 09-11-2010 at 00:09.
Reply With Quote
  #8   Spotlight this post!  
Unread 09-11-2010, 08:01
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Computer playing Bejeweled Blitz project

Yes it would. Technically, we could statically build in all the things it would need for execution and make each one stand-alone, but it isn't that big a request. It would also help if the datadlow scheduling engine were already on the OS.

Greg McKaskle
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Computer Science or Computer Engineering? KRibordy College & University Education 14 09-10-2009 01:56
saving project as a new project windell747 NI LabVIEW 3 01-02-2009 04:41
Music Playing Problem on Computer John Gutmann Chit-Chat 9 31-07-2007 17:04
pic: Kaizen Blitz Presents... The Blitz Box 2006 Ian Curtis Robot Showcase 0 24-02-2006 16:47
The Blitz is a GO!! Erin Rapacki Off-Season Events 6 06-06-2003 19:31


All times are GMT -5. The time now is 10:12.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi