• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 01:39
CET 07:39
KST 15:39
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Winners9Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win TL.net Map Contest #21: Winners RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8) StarCraft, SC2, HotS, WC3, Returning to Blizzcon!
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Path of Exile Stormgate/Frost Giant Megathread Should offensive tower rushing be viable in RTS games? Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1554 users

The Big Programming Thread - Page 128

Forum Index > General Forum
Post a Reply
Prev 1 126 127 128 129 130 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
Last Edited: 2012-03-16 14:49:34
March 16 2012 14:46 GMT
#2541
On March 16 2012 22:47 Manit0u wrote:

#include <iostream>
using namespace std;

void displayGraph(int map[6][6]);

int main()
{
int map[6][6] =
{
{1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1}
};

displayGraph(map);

system("PAUSE");

return 0;
}

void displayGraph(int map[6][6])
{
for (int x = 0; x < 7; x++)
{
for (int y = 0; y < 7; y++)
{
if (map[x][y] == 1)
{
cout << "#";
}
else if (map[x][y] == 0)
{
cout << " ";
}
}
}
return;
}


Cleared up the code (global variables are unnecessary here, used prototype for displayGraph function) and removed endlines. Experiment with it


tiny hint: When your array has 6 entries, they are numerated 0 through 5. So your for-loops should be conditioned to x<6, not x<7 ;P same for y obviously.

/edit: also, for robustness, you should add a ' else {cout << "?";} ', otherwise your formatting breaks when values other than 1 and 0 occur. And i believe, a line break should be written after the inner for-loop.
Gold isn't everything in life... you need wood, too!
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
Last Edited: 2012-03-16 16:34:51
March 16 2012 16:34 GMT
#2542
I didn't write that. I just cleared the formatting a bit.
And yeah, linebreak should be there.
Time is precious. Waste it wisely.
Millitron
Profile Blog Joined August 2010
United States2611 Posts
March 16 2012 20:07 GMT
#2543
Alright, so I'm writing a User Interface for a touch-screen on a robot. The user will tap on a map where they want the robot to go, and it'll go. We've already got the robot capable of going anywhere on the map, and finding its way around. My problem is, the program to control the robot's motion is in C++, but the UI is being written in Java. Due to the complexity of the robot's operating system, writing both in a single C++ program is pretty much out of the question. The touch-screen drivers and the motors' drivers can't talk to each other very easily, so the program would have access to one or the other, but not both.

What I'm wondering is, is it possible to start a C++ program and send it commands from within a Java program? How would I go about doing this?
Who called in the fleet?
b0lt
Profile Joined March 2009
United States790 Posts
March 16 2012 20:15 GMT
#2544
On March 17 2012 05:07 Millitron wrote:
Alright, so I'm writing a User Interface for a touch-screen on a robot. The user will tap on a map where they want the robot to go, and it'll go. We've already got the robot capable of going anywhere on the map, and finding its way around. My problem is, the program to control the robot's motion is in C++, but the UI is being written in Java. Due to the complexity of the robot's operating system, writing both in a single C++ program is pretty much out of the question. The touch-screen drivers and the motors' drivers can't talk to each other very easily, so the program would have access to one or the other, but not both.

What I'm wondering is, is it possible to start a C++ program and send it commands from within a Java program? How would I go about doing this?

This is precisely what Google's Protocol Buffers was designed for, you can define your messages and then instantiate them on either side, fill in the data, then just push it through a socket and deserialize on the other side.
delHospital
Profile Blog Joined December 2010
Poland261 Posts
March 16 2012 20:28 GMT
#2545
On March 17 2012 05:07 Millitron wrote:
What I'm wondering is, is it possible to start a C++ program and send it commands from within a Java program? How would I go about doing this?

There's something called JNI (but that doesn't start a separate process, it lets you call native code from within JVM). Alternatively, you can use regular IPC or some library like the one suggested by b0lt.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
March 16 2012 20:28 GMT
#2546
On March 17 2012 05:15 b0lt wrote:
Show nested quote +
On March 17 2012 05:07 Millitron wrote:
Alright, so I'm writing a User Interface for a touch-screen on a robot. The user will tap on a map where they want the robot to go, and it'll go. We've already got the robot capable of going anywhere on the map, and finding its way around. My problem is, the program to control the robot's motion is in C++, but the UI is being written in Java. Due to the complexity of the robot's operating system, writing both in a single C++ program is pretty much out of the question. The touch-screen drivers and the motors' drivers can't talk to each other very easily, so the program would have access to one or the other, but not both.

What I'm wondering is, is it possible to start a C++ program and send it commands from within a Java program? How would I go about doing this?

This is precisely what Google's Protocol Buffers was designed for, you can define your messages and then instantiate them on either side, fill in the data, then just push it through a socket and deserialize on the other side.


Also worth looking into Java Native functionality. You can have some C++ functions declared in a header file (implemented elsewhere, ofc) and you can use java to call these C++ functions. Also worth looking into static and dynamic libraries (.lib and .dll). Best of luck on your inter-language integration! There are a thousand ways to accomplish what you are looking to do, but you only need one, so if you think one is too hard, move on to the next!
Any sufficiently advanced technology is indistinguishable from magic
Millitron
Profile Blog Joined August 2010
United States2611 Posts
Last Edited: 2012-03-16 20:44:02
March 16 2012 20:42 GMT
#2547
On March 17 2012 05:15 b0lt wrote:
Show nested quote +
On March 17 2012 05:07 Millitron wrote:
Alright, so I'm writing a User Interface for a touch-screen on a robot. The user will tap on a map where they want the robot to go, and it'll go. We've already got the robot capable of going anywhere on the map, and finding its way around. My problem is, the program to control the robot's motion is in C++, but the UI is being written in Java. Due to the complexity of the robot's operating system, writing both in a single C++ program is pretty much out of the question. The touch-screen drivers and the motors' drivers can't talk to each other very easily, so the program would have access to one or the other, but not both.

What I'm wondering is, is it possible to start a C++ program and send it commands from within a Java program? How would I go about doing this?

This is precisely what Google's Protocol Buffers was designed for, you can define your messages and then instantiate them on either side, fill in the data, then just push it through a socket and deserialize on the other side.

This looks promising, but I still have a problem.

Is there a way to have only the Java program running until it gets input from the user, then have it start the C++ program and send it its necessary data? Because we'd like to include other functionality as well. For instance, the robot also has a little grabber arm it can move around. The grabber code is written in C++ too. We want the user to be able to access all the functionality from this one UI. Currently, you have to go through the file browser and manually start either the code for moving the robot itself, or the code for moving the arm. So if its possible, I'd like to not have all this stuff running at the same time, and instead only boot up the programs the user selects. The description of the Protocol Buffer makes it sound like I need both ends running at the same time.

On March 17 2012 05:28 RoyGBiv_13 wrote:
Show nested quote +
On March 17 2012 05:15 b0lt wrote:
On March 17 2012 05:07 Millitron wrote:
Alright, so I'm writing a User Interface for a touch-screen on a robot. The user will tap on a map where they want the robot to go, and it'll go. We've already got the robot capable of going anywhere on the map, and finding its way around. My problem is, the program to control the robot's motion is in C++, but the UI is being written in Java. Due to the complexity of the robot's operating system, writing both in a single C++ program is pretty much out of the question. The touch-screen drivers and the motors' drivers can't talk to each other very easily, so the program would have access to one or the other, but not both.

What I'm wondering is, is it possible to start a C++ program and send it commands from within a Java program? How would I go about doing this?

This is precisely what Google's Protocol Buffers was designed for, you can define your messages and then instantiate them on either side, fill in the data, then just push it through a socket and deserialize on the other side.


Also worth looking into Java Native functionality. You can have some C++ functions declared in a header file (implemented elsewhere, ofc) and you can use java to call these C++ functions. Also worth looking into static and dynamic libraries (.lib and .dll). Best of luck on your inter-language integration! There are a thousand ways to accomplish what you are looking to do, but you only need one, so if you think one is too hard, move on to the next!

I'll check out these things too. And thanks, I think I'll need the luck
Who called in the fleet?
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
Last Edited: 2012-03-16 20:49:04
March 16 2012 20:47 GMT
#2548
it boils down to either making your robot stuff a .dll (or linux equivalent) and using it with a native interface in java, or writing a c++ standalone host application that gets sent commands via network sockets. The latter is certainly more work, as you have to write a proper network handler in c++ in addition to the java client, but on the other hand allows you to easily write a lot more clients and implement remote-control through lan/wlan/internet.

that google proto stuff that someone linked seems to be just a marshalling format, i suppose this would help in the socket approach as you can just create java and c++ stucts for your data objects which both use the same marshalling format, so you can easily flatten data into a network stream and reconstruct it at the other end. So if you go this way, that might be helpful. for direct method invocation through native interfaces, it's probably rather irrelevant.

/edit: java can start other programs, have a look at http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html
Gold isn't everything in life... you need wood, too!
aderum
Profile Blog Joined January 2011
Sweden1459 Posts
Last Edited: 2012-03-16 22:47:53
March 16 2012 22:37 GMT
#2549
Hello everybody! I am currently working on small school project (just a small online library system), and in it you should be able to search for a book. Anyways, i wrote a SOL-Query (ViIsual Studios MYSQL) that looks like this:


+ Show Spoiler +
SELECT bTitle,Bocker.bId,bPubliceringsAr,bGenre,ISBN,fFornamnNamn, fEfternamn, fPnr,fId,
FROM Bocker, Forfattare, bokForfattare
WHERE bTitle=@bokTitle AND Bocker.bId=bokForfattare.bId AND Forfattare.fId=bokForfattare.fId;


Some names in Swedish but its pretty straight forward. It gets a book title and some other stuff and also authors to the book, through a middle table since the book can have many authors.

Anyways, when i tested the query in VS i changed it automatically to this:

+ Show Spoiler +

SELECT bTitle, Bocker.bId, bPubliceringsAr, bGenre, ISBN, fFornamn, fEfternamn, fPnr, Forfattare.fId
FROM Bocker
INNER JOIN bokForfattare ON Bocker.bId = bokForfattare.bId
INNER JOIN Forfattare ON bokForfattare.fId = Forfattare.fId
WHERE (Bocker.bTitle = @bokTitle)


Now i understand this full and well, but my question is why it changed it. Is this method faster? putt less stress on the database? I can agree that it looks more proffesional, but is it better?

Love ♥
Crazy people dont sit around and wonder if they are insane
Millitron
Profile Blog Joined August 2010
United States2611 Posts
March 16 2012 23:23 GMT
#2550
On March 17 2012 05:47 MisterD wrote:
it boils down to either making your robot stuff a .dll (or linux equivalent) and using it with a native interface in java, or writing a c++ standalone host application that gets sent commands via network sockets. The latter is certainly more work, as you have to write a proper network handler in c++ in addition to the java client, but on the other hand allows you to easily write a lot more clients and implement remote-control through lan/wlan/internet.

that google proto stuff that someone linked seems to be just a marshalling format, i suppose this would help in the socket approach as you can just create java and c++ stucts for your data objects which both use the same marshalling format, so you can easily flatten data into a network stream and reconstruct it at the other end. So if you go this way, that might be helpful. for direct method invocation through native interfaces, it's probably rather irrelevant.

/edit: java can start other programs, have a look at http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

I'm looking into the Runtime API, and I'm wondering, can the output stream of the runtime object act as the console for the C++ program? So instead of dealing with native interfaces or networking, I could just have the C++ program read the instructions from the console? I'm thinking that from the C++ program's point of view, a console is a console, it doesn't really care what fills in the prompts on the console, does it?
Who called in the fleet?
Neshapotamus
Profile Blog Joined May 2006
United States163 Posts
Last Edited: 2012-03-16 23:40:26
March 16 2012 23:39 GMT
#2551
aderum , what you want to google is implicit join vs explicit join.

The following is considered ANSI syntax:

SELECT bTitle, Bocker.bId, bPubliceringsAr, bGenre, ISBN, fFornamn, fEfternamn, fPnr, Forfattare.fId
FROM Bocker
INNER JOIN bokForfattare ON Bocker.bId = bokForfattare.bId
INNER JOIN Forfattare ON bokForfattare.fId = Forfattare.fId
WHERE (Bocker.bTitle = @bokTitle)

This version also has less predicates(# of where clauses) and is easier for debugging purposes.

The execution time for both are the same. Take a look at the execution plan to see what the both the queries are doing. They will have the same execution plan.
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
March 16 2012 23:53 GMT
#2552
On March 17 2012 08:23 Millitron wrote:
Show nested quote +
On March 17 2012 05:47 MisterD wrote:
it boils down to either making your robot stuff a .dll (or linux equivalent) and using it with a native interface in java, or writing a c++ standalone host application that gets sent commands via network sockets. The latter is certainly more work, as you have to write a proper network handler in c++ in addition to the java client, but on the other hand allows you to easily write a lot more clients and implement remote-control through lan/wlan/internet.

that google proto stuff that someone linked seems to be just a marshalling format, i suppose this would help in the socket approach as you can just create java and c++ stucts for your data objects which both use the same marshalling format, so you can easily flatten data into a network stream and reconstruct it at the other end. So if you go this way, that might be helpful. for direct method invocation through native interfaces, it's probably rather irrelevant.

/edit: java can start other programs, have a look at http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

I'm looking into the Runtime API, and I'm wondering, can the output stream of the runtime object act as the console for the C++ program? So instead of dealing with native interfaces or networking, I could just have the C++ program read the instructions from the console? I'm thinking that from the C++ program's point of view, a console is a console, it doesn't really care what fills in the prompts on the console, does it?


Wouldn't it be possible to just re-write the touch screen GUI in C++? Having 2 different languages operating the same robot seems like a bitch to maintain and more trouble than actual help.
Time is precious. Waste it wisely.
aderum
Profile Blog Joined January 2011
Sweden1459 Posts
March 16 2012 23:55 GMT
#2553
On March 17 2012 08:39 Neshapotamus wrote:
aderum , what you want to google is implicit join vs explicit join.

The following is considered ANSI syntax:

SELECT bTitle, Bocker.bId, bPubliceringsAr, bGenre, ISBN, fFornamn, fEfternamn, fPnr, Forfattare.fId
FROM Bocker
INNER JOIN bokForfattare ON Bocker.bId = bokForfattare.bId
INNER JOIN Forfattare ON bokForfattare.fId = Forfattare.fId
WHERE (Bocker.bTitle = @bokTitle)

This version also has less predicates(# of where clauses) and is easier for debugging purposes.

The execution time for both are the same. Take a look at the execution plan to see what the both the queries are doing. They will have the same execution plan.



Okay great, reading about it right now (remember reading about it when i started to learn SQL...)

Thank you kind sir =)
Crazy people dont sit around and wonder if they are insane
Cloud
Profile Blog Joined November 2004
Sexico5880 Posts
March 17 2012 00:03 GMT
#2554
About to start a project - school admin system (grades, library, personnel, finance modules + other possible stuff like forum). Will be a ruby on rails app and I have plans to monetize it in the future (there's a dire need for good school admin systems here in Mexico). If anyone is interested in participating, pm me, some knowledge of ruby/rails is a bonus, willingness to work is preferable. This sounds like a job offer but it isn't, just an open source project where you can participate. And it can instead become a programming/ruby/rails study group.
BlueLaguna on West, msg for game.
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
March 17 2012 00:32 GMT
#2555
On March 17 2012 08:23 Millitron wrote:
Show nested quote +
On March 17 2012 05:47 MisterD wrote:
it boils down to either making your robot stuff a .dll (or linux equivalent) and using it with a native interface in java, or writing a c++ standalone host application that gets sent commands via network sockets. The latter is certainly more work, as you have to write a proper network handler in c++ in addition to the java client, but on the other hand allows you to easily write a lot more clients and implement remote-control through lan/wlan/internet.

that google proto stuff that someone linked seems to be just a marshalling format, i suppose this would help in the socket approach as you can just create java and c++ stucts for your data objects which both use the same marshalling format, so you can easily flatten data into a network stream and reconstruct it at the other end. So if you go this way, that might be helpful. for direct method invocation through native interfaces, it's probably rather irrelevant.

/edit: java can start other programs, have a look at http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

I'm looking into the Runtime API, and I'm wondering, can the output stream of the runtime object act as the console for the C++ program? So instead of dealing with native interfaces or networking, I could just have the C++ program read the instructions from the console? I'm thinking that from the C++ program's point of view, a console is a console, it doesn't really care what fills in the prompts on the console, does it?


a programs stdin, stdout and stderr are all pipes that can be redirected to whatever in any operating system. For instance, you can write two programs that only use stdin and stdout, and then "connect" them by calling "programA | programB" on your command line.

For instance, you can build processing chains like "ls all file names", "grep all file names whose regexp matches X", "delete all matched files" by building a chain with "ls -parameters > grep regexp > del" or something like this. > is a one-way-pipe redirecting stdout, | is a both way pipe connecting stdin and stdout forward an backwards i believe. You can also redirect stderr through >&2 or something weird like that, google up on that if you really want to know. You can even redirect stdout and stderr to a file (./program > stdout.txt), or append to a file (./program >> stdout.txt) or even us a file as stdin (./program < stdin.txt).

This all works without using any special language features, every program just needs to use its stdin and stdout. The operating system can already redirect those however it likes.

Anyhow, when invoking a process from within java (and other languages certainly offer equal features), of course you can read and write from these pipes, too. To obtain a pipe to the programs stdin in java, do something like this:
Process process = Runtime.getRuntime().exec("command") ;
PrintWriter toProgram = new PrintWriter(process.getOutputStream());
toProgram.println("drive left!");
toProgram.println("drive straight!");
the effect is the same as when you usually would type into the programs console.
Similarly you can obtain the programs stdout as process.getInputStream() and stderr as process.getErrorStream(), and then read from those. Wrap in BufferedReaders for automatic .readLine() and the likes, use it just the same as when reading from a FileInputStream. Read up on what you can do with these process objects here: http://docs.oracle.com/javase/7/docs/api/java/lang/Process.html
Gold isn't everything in life... you need wood, too!
Millitron
Profile Blog Joined August 2010
United States2611 Posts
March 17 2012 05:29 GMT
#2556
On March 17 2012 08:53 Manit0u wrote:
Show nested quote +
On March 17 2012 08:23 Millitron wrote:
On March 17 2012 05:47 MisterD wrote:
it boils down to either making your robot stuff a .dll (or linux equivalent) and using it with a native interface in java, or writing a c++ standalone host application that gets sent commands via network sockets. The latter is certainly more work, as you have to write a proper network handler in c++ in addition to the java client, but on the other hand allows you to easily write a lot more clients and implement remote-control through lan/wlan/internet.

that google proto stuff that someone linked seems to be just a marshalling format, i suppose this would help in the socket approach as you can just create java and c++ stucts for your data objects which both use the same marshalling format, so you can easily flatten data into a network stream and reconstruct it at the other end. So if you go this way, that might be helpful. for direct method invocation through native interfaces, it's probably rather irrelevant.

/edit: java can start other programs, have a look at http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

I'm looking into the Runtime API, and I'm wondering, can the output stream of the runtime object act as the console for the C++ program? So instead of dealing with native interfaces or networking, I could just have the C++ program read the instructions from the console? I'm thinking that from the C++ program's point of view, a console is a console, it doesn't really care what fills in the prompts on the console, does it?


Wouldn't it be possible to just re-write the touch screen GUI in C++? Having 2 different languages operating the same robot seems like a bitch to maintain and more trouble than actual help.

The biggest advantage for us using Java for the GUI is that we can test it on any computer, not just the robot. We could write the GUI in C++ I suppose, but to be able to test it on a normal PC, it would have to be completely separate from the robot's code anyways. Because of the file structure and operating system on the robot, it is pretty difficult to install stuff to it. If it was written directly into the robot's code, it would have to be compiled and re-installed every time we made a change, which would be a huge pain. So this means we pretty much need two programs anyways, 1 for the GUI, one for the robot's motion. And if we already need two programs, we may as well have the GUI in Java, so when I graduate, other students at my school can easily pick up where I left off, since Java is taught freshman year.

On March 17 2012 09:32 MisterD wrote:
Show nested quote +
On March 17 2012 08:23 Millitron wrote:
On March 17 2012 05:47 MisterD wrote:
it boils down to either making your robot stuff a .dll (or linux equivalent) and using it with a native interface in java, or writing a c++ standalone host application that gets sent commands via network sockets. The latter is certainly more work, as you have to write a proper network handler in c++ in addition to the java client, but on the other hand allows you to easily write a lot more clients and implement remote-control through lan/wlan/internet.

that google proto stuff that someone linked seems to be just a marshalling format, i suppose this would help in the socket approach as you can just create java and c++ stucts for your data objects which both use the same marshalling format, so you can easily flatten data into a network stream and reconstruct it at the other end. So if you go this way, that might be helpful. for direct method invocation through native interfaces, it's probably rather irrelevant.

/edit: java can start other programs, have a look at http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

I'm looking into the Runtime API, and I'm wondering, can the output stream of the runtime object act as the console for the C++ program? So instead of dealing with native interfaces or networking, I could just have the C++ program read the instructions from the console? I'm thinking that from the C++ program's point of view, a console is a console, it doesn't really care what fills in the prompts on the console, does it?


a programs stdin, stdout and stderr are all pipes that can be redirected to whatever in any operating system. For instance, you can write two programs that only use stdin and stdout, and then "connect" them by calling "programA | programB" on your command line.

For instance, you can build processing chains like "ls all file names", "grep all file names whose regexp matches X", "delete all matched files" by building a chain with "ls -parameters > grep regexp > del" or something like this. > is a one-way-pipe redirecting stdout, | is a both way pipe connecting stdin and stdout forward an backwards i believe. You can also redirect stderr through >&2 or something weird like that, google up on that if you really want to know. You can even redirect stdout and stderr to a file (./program > stdout.txt), or append to a file (./program >> stdout.txt) or even us a file as stdin (./program < stdin.txt).

This all works without using any special language features, every program just needs to use its stdin and stdout. The operating system can already redirect those however it likes.

Anyhow, when invoking a process from within java (and other languages certainly offer equal features), of course you can read and write from these pipes, too. To obtain a pipe to the programs stdin in java, do something like this:
Process process = Runtime.getRuntime().exec("command") ;
PrintWriter toProgram = new PrintWriter(process.getOutputStream());
toProgram.println("drive left!");
toProgram.println("drive straight!");
the effect is the same as when you usually would type into the programs console.
Similarly you can obtain the programs stdout as process.getInputStream() and stderr as process.getErrorStream(), and then read from those. Wrap in BufferedReaders for automatic .readLine() and the likes, use it just the same as when reading from a FileInputStream. Read up on what you can do with these process objects here: http://docs.oracle.com/javase/7/docs/api/java/lang/Process.html

Oh man, the Process class is so cool. I wish I knew about it sooner. It's just so elegant.
Who called in the fleet?
Highways
Profile Joined July 2005
Australia6105 Posts
March 17 2012 12:17 GMT
#2557
The creator of jquery is a starcraft player

http://www.reddit.com/r/IAmA/comments/h42ak/i_am_john_resig_creator_of_jquery_ama/
#1 Terran hater
NeMeSiS3
Profile Blog Joined February 2012
Canada2972 Posts
March 18 2012 00:16 GMT
#2558
So here's my question...

I have absolutely no knowledge of how to program, none, and I am moving into Computer Sciences at UNB this fall and I'm curious if anyone can give me the possibility to enter into programming in a manner that its not a huge steep learning curve... I know a lot about computers, but just nothing about the process of programming them : ( Anyone help? Just general tips would be nice
FoTG fighting!
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
March 18 2012 00:36 GMT
#2559
On March 18 2012 09:16 NeMeSiS3 wrote:
So here's my question...

I have absolutely no knowledge of how to program, none, and I am moving into Computer Sciences at UNB this fall and I'm curious if anyone can give me the possibility to enter into programming in a manner that its not a huge steep learning curve... I know a lot about computers, but just nothing about the process of programming them : ( Anyone help? Just general tips would be nice

Try this: http://cecilsunkure.blogspot.com/2011/02/i-want-to-learn-programming-but-i-know.html
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
March 18 2012 01:07 GMT
#2560
On March 17 2012 14:29 Millitron wrote:
Show nested quote +
On March 17 2012 08:53 Manit0u wrote:
On March 17 2012 08:23 Millitron wrote:
On March 17 2012 05:47 MisterD wrote:
it boils down to either making your robot stuff a .dll (or linux equivalent) and using it with a native interface in java, or writing a c++ standalone host application that gets sent commands via network sockets. The latter is certainly more work, as you have to write a proper network handler in c++ in addition to the java client, but on the other hand allows you to easily write a lot more clients and implement remote-control through lan/wlan/internet.

that google proto stuff that someone linked seems to be just a marshalling format, i suppose this would help in the socket approach as you can just create java and c++ stucts for your data objects which both use the same marshalling format, so you can easily flatten data into a network stream and reconstruct it at the other end. So if you go this way, that might be helpful. for direct method invocation through native interfaces, it's probably rather irrelevant.

/edit: java can start other programs, have a look at http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

I'm looking into the Runtime API, and I'm wondering, can the output stream of the runtime object act as the console for the C++ program? So instead of dealing with native interfaces or networking, I could just have the C++ program read the instructions from the console? I'm thinking that from the C++ program's point of view, a console is a console, it doesn't really care what fills in the prompts on the console, does it?


Wouldn't it be possible to just re-write the touch screen GUI in C++? Having 2 different languages operating the same robot seems like a bitch to maintain and more trouble than actual help.

The biggest advantage for us using Java for the GUI is that we can test it on any computer, not just the robot. We could write the GUI in C++ I suppose, but to be able to test it on a normal PC, it would have to be completely separate from the robot's code anyways. Because of the file structure and operating system on the robot, it is pretty difficult to install stuff to it. If it was written directly into the robot's code, it would have to be compiled and re-installed every time we made a change, which would be a huge pain. So this means we pretty much need two programs anyways, 1 for the GUI, one for the robot's motion. And if we already need two programs, we may as well have the GUI in Java, so when I graduate, other students at my school can easily pick up where I left off, since Java is taught freshman year.


Well, if you have stuff in C++ in the robot OS, I hardly see a problem. Especially that GUI like wxWidgets (which I'm just getting into) is platform-independent and pretty damn neat.

http://www.wxwidgets.org/

From the 'about':


wxWidgets is a C++ library that lets developers create applications for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures as well as several mobile platforms including Windows Mobile, iPhone SDK and embedded GTK+. It has popular language bindings for Python, Perl, Ruby and many other languages. Unlike other cross-platform toolkits, wxWidgets gives its applications a truly native look and feel because it uses the platform's native API rather than emulating the GUI. It's also extensive, free, open-source and mature.
Time is precious. Waste it wisely.
Prev 1 126 127 128 129 130 1032 Next
Please log in or register to reply.
Live Events Refresh
Korean StarCraft League
03:00
Week 82
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nina 206
ProTech122
StarCraft: Brood War
Sea 928
Zeus 585
Noble 21
Hm[arnc] 21
Bale 13
Dota 2
NeuroSwarm94
LuMiX1
League of Legends
JimRising 634
Reynor19
Counter-Strike
fl0m320
Other Games
summit1g16780
tarik_tv13013
WinterStarcraft376
C9.Mang0373
FrodaN182
Organizations
Other Games
gamesdonequick750
Counter-Strike
PGL151
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki14
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt709
Other Games
• Shiphtur173
Upcoming Events
CranKy Ducklings
3h 22m
IPSL
11h 22m
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
11h 22m
Lambo vs Clem
Scarlett vs TriGGeR
ByuN vs TBD
Zoun vs TBD
BSL 21
13h 22m
Gosudark vs Kyrie
Gypsy vs OyAji
UltrA vs Radley
Dandy vs Ptak
Replay Cast
16h 22m
Sparkling Tuna Cup
1d 3h
WardiTV Korean Royale
1d 5h
IPSL
1d 11h
JDConan vs WIZARD
WolFix vs Cross
LAN Event
1d 11h
BSL 21
1d 13h
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
[ Show More ]
Replay Cast
2 days
Wardi Open
2 days
WardiTV Korean Royale
3 days
Replay Cast
4 days
Kung Fu Cup
4 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
4 days
The PondCast
5 days
RSL Revival
5 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.