Go to Post Just think outside the box but inside the 28" X 38" X 60" rectangular prism and you may come up with a solution. - Pavan Dave [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-02-2014, 06:39 PM
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Question Visual C++: Getting socket server to run parallel to other processes

I've been offline a bit lately! Hopefully I didn't miss much .
Now, for the question,
I'm finishing up my OpenCV project and need to come up with a mean of communicating with the cRIO. I would like to use TCP because that will work great for what I need and will have plenty of cross-platform support. I am sure that if I create a socket server the traditional way in VC++, the program will sleep until the data is delivered. I want to constantly process the images and cache the data for use by the program. Since I will most likely be using a dual core driver station or a quad core ODROID, how can I make the server run in one core and the app run in every other core?

Thanks for your help and hopefully I see you at competitions!

Last edited by yash101 : 03-02-2014 at 07:57 PM.
  #2   Spotlight this post!  
Unread 03-02-2014, 07:15 PM
heuristics heuristics is offline
Registered User
FRC #3634
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Trumbull, CT
Posts: 21
heuristics is on a distinguished road
Re: Visual C++: Getting socket server to run parallel to other processes

Two separate applications? If so, let the OS handle the scheduling for you. If not, you need to use threads. You can set processor affinity so your threads run on specific processors, but it's really not necessary as again, scheduling will be handled for you.
  #3   Spotlight this post!  
Unread 03-02-2014, 07:19 PM
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Visual C++: Getting socket server to run parallel to other processes

How do I do that. I know that I need to thread the application but I've never written a program this complex . 1500 lines of code, all in a single cpp file isn't too easy to mess with .

I have very little experience with network programming and the only sort of network programming I've done is web management, where I wrote applications in PHP.

I feel quite shot in the dark and if anyone knows something about bare C++ network programming with threads, I'd love it if you can help me out

I don't know how to have 2 programs communicate with each other, but using file IO gives me a few worries. What about the possibility of the file getting corrupted by one program writing it and the other reading it at the same time? I need bidirectional communication so that means the likely-ness of both writing is great. I don't want the program to wait for the socket server because my framerate should NEVER dip under 15fps, meaning I need to juice the processor!

Last edited by yash101 : 03-02-2014 at 07:22 PM.
  #4   Spotlight this post!  
Unread 03-02-2014, 07:51 PM
heuristics heuristics is offline
Registered User
FRC #3634
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Trumbull, CT
Posts: 21
heuristics is on a distinguished road
Re: Visual C++: Getting socket server to run parallel to other processes

I've personally only worked with posix (pthread) and Java threads but it looks like this http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx may be what you need for C++ .net. It sounds like you're going to want to have at least two threads, one for network communication (or maybe you need two for bidirectional communication? I haven't done much network coding) and one for your image processing. And it sounds like you've got some rending going on, too, so you might want another thread to take care of that. The tough part is finding all the critical sections where you want to make sure data isn't accessed/written to at the same time by two separate threads. Usually this can be achieved by locking a mutex and copying all the data from the members that one thread owns to the other thread's members.
  #5   Spotlight this post!  
Unread 03-02-2014, 07:57 PM
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Visual C++: Getting socket server to run parallel to other processes

I'd try to push both up and down communications to the same thread. I will look into it. If anyone has any good examples (or any links), that would be greatly appreciated!
  #6   Spotlight this post!  
Unread 03-02-2014, 09:15 PM
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
Re: Visual C++: Getting socket server to run parallel to other processes

Personally, I would write a program using MinGW (POSIX) C/C++ but that's just me. Visual C++ threading links:
Microsoft MFC
Stack Overflow - MFC Simple Example
Some other tutorial

Now, if you're going to do this on your ODROID, the story is different because it runs Linux so you have to use the POSIX Standard for threading. Also, wouldn't you have to port your OpenCV program to Linux if you used VC++? I don't know how different it is...

Here are some useful tutorials on network programming and concurrency in a POSIX environment:
YoLinux: POSIX Threads
Sockets in Linux
Linux Magazine - Linux Socket Programming
YoLinux - Sockets

Also, I would use UDP for something like a camera feed because if you use TCP and you drop a few packets, you will get old information because TCP guarantees delivery of all packets. Therefore, the packets you drop will come back and your camera feed will be off. Depending on the amount of data lost, your latency could be significant so I recommend UDP to take care of that problem. If you want to look at some vision code my team wrote last year, you can check out the project home page on our Github page. We used both C networking and POSIX threads.

Good luck!

Alex Brinister

Last edited by AlexBrinister : 03-02-2014 at 09:18 PM. Reason: Port to ODROID?
  #7   Spotlight this post!  
Unread 03-02-2014, 09:43 PM
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Visual C++: Getting socket server to run parallel to other processes

Quote:
Originally Posted by AlexBrinister View Post
Personally, I would write a program using MinGW (POSIX) C/C++ but that's just me. Visual C++ threading links:
Microsoft MFC
Stack Overflow - MFC Simple Example
Some other tutorial

Now, if you're going to do this on your ODROID, the story is different because it runs Linux so you have to use the POSIX Standard for threading. Also, wouldn't you have to port your OpenCV program to Linux if you used VC++? I don't know how different it is...

Here are some useful tutorials on network programming and concurrency in a POSIX environment:
YoLinux: POSIX Threads
Sockets in Linux
Linux Magazine - Linux Socket Programming
YoLinux - Sockets

Also, I would use UDP for something like a camera feed because if you use TCP and you drop a few packets, you will get old information because TCP guarantees delivery of all packets. Therefore, the packets you drop will come back and your camera feed will be off. Depending on the amount of data lost, your latency could be significant so I recommend UDP to take care of that problem. If you want to look at some vision code my team wrote last year, you can check out the project home page on our Github page. We used both C networking and POSIX threads.

Good luck!

Alex Brinister
I'm not the greatest fan of MinGW. I love VC++ because I suck at compiling things like OpenCV. My first successful Linux build was today, which I had to get 326 dependencies and use ccmake for the configurer. At least I now have a 2.4.8 bleeding edge build now. The problem comes that there are only 2 IDEs that I really like and understand, Visual Studio and QT Creator. I have kept close to my code and porting from VC++ to C++ should not take more than 15 minutes. One of my main goals since the beginning is cross-compatibility with the code. I spent a long time getting OpenCV to work properly and I like my setup. Also, with a netboot processor, I doubt i can get much performance out of MinGW.
  #8   Spotlight this post!  
Unread 03-02-2014, 10:08 PM
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
Re: Visual C++: Getting socket server to run parallel to other processes

Fair enough. It's just that MinGW supports Linux/POSIX stuff that I'm used to. I have never used VC++.

That being said, if you use an ODROID, your code will have to be POSIX-compliant. The advantage of working in MinGW is that your code would not need to be ported over. You'd already have Linux-compatible code.

That being said, if you are using your ODROID, programming on it would be easiest of all. Though in Linux, VC++ doesn't exist so you should probably learn another IDE like Eclipse or something. I am an everyday Linux user so my preffered environment is VIM and a terminal! QCreator does though...

If you use CMake, compiling should be really easy. You just need to write your own CMakeLists.txt file. Or does ccmake generate one for you?

In the end, it's your choice. Running your vision code on a Linux box gives you the speed and reliability you need for any kind of server applicance such as this. Management is really easy through tools like SSH or Telnet. And it's also an excellent learning experience because in industry, Linux is used virtually everywhere because of its reliability.

Good luck with your code!

Alex Brinister
  #9   Spotlight this post!  
Unread 03-02-2014, 10:32 PM
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Visual C++: Getting socket server to run parallel to other processes

Quote:
Originally Posted by AlexBrinister View Post
Fair enough. It's just that MinGW supports Linux/POSIX stuff that I'm used to. I have never used VC++.

That being said, if you use an ODROID, your code will have to be POSIX-compliant. The advantage of working in MinGW is that your code would not need to be ported over. You'd already have Linux-compatible code.

That being said, if you are using your ODROID, programming on it would be easiest of all. Though in Linux, VC++ doesn't exist so you should probably learn another IDE like Eclipse or something. I am an everyday Linux user so my preffered environment is VIM and a terminal! QCreator does though...

If you use CMake, compiling should be really easy. You just need to write your own CMakeLists.txt file. Or does ccmake generate one for you?

In the end, it's your choice. Running your vision code on a Linux box gives you the speed and reliability you need for any kind of server applicance such as this. Management is really easy through tools like SSH or Telnet. And it's also an excellent learning experience because in industry, Linux is used virtually everywhere because of its reliability.

Good luck with your code!

Alex Brinister
I use ccmake to generate the CMakeLists.txt. It does a good job because it finds what is on the computer and automatically enables it. It took me 15 minutes to get everything set up after I found the resources.

VC++ is basically C++ with some nice extras. However, I wrote my program mostly in strict C++.

I like RDP because i actually get a headed system that i can work on. I also like UART debugging because you even get those kernel messages in realtime

I guess this is really my opinion, but Linux is one of the best implemented kernel, apart from BSD, and if all the man-hours were used to make a good distro like Ubuntu, we would see Linux EVERYWHERE. Pretty soon, Windows will go extinct because my computer cannot stay on for more than a week before starting to completely glitch out.

Has anyone ever used an ODROID? What was your experience and were you able to overclock to 2GHz? That should be 1.5x as fast as my i3 dual core 1.4GHz.

Also, we don't have an ODROID, but we might try to get access to one.
  #10   Spotlight this post!  
Unread 03-03-2014, 08:58 AM
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
Re: Visual C++: Getting socket server to run parallel to other processes

My team hasn't had experience with the ODROID but we have used an Intel NUC (Next Unit of Computing). It offered us a huge boost in image processing and allowed us to do a lot with our OpenCV application. The NUC is rated at 1.70 GHz so its slower than an overclocked ODROID. I think that should be plenty fine for what you want to do with your image processing. The downside to the NUC is that it becomes a really expensive part of the control system so if you're tight on money, it certainly isn't a good choice.

Since you wrote your program in standard C++, the only part you will need to change is the threading/socket model.

Alex Brinister
  #11   Spotlight this post!  
Unread 03-03-2014, 11:24 AM
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Visual C++: Getting socket server to run parallel to other processes

Yeah. I have taken a look at the i5 NUC and it only seems worth it if we are sponsored one by Intel. An i5 would actually be faster because it is hyperthreading, meaning it actually behaves like a quad core system, and an x86_64 system is very fast. One advantage of ARM is that the processors are well priced and you don't end up shelling out $400 on a processor. I believe that is because of the licensing; ARM inc. doesn't seem to charge as much as the x86 equivalent, in the forms of licensing. Also, since the system is a PoP, it is much smaller, faster and more efficient, even at lower bus speeds. The NUC is manufactured by Intel, and (no offense to anyone) Intel has their hardware very pricey. I believe the base model, with a Celeron is $200. Plus, you need to get mSATA SSD and some RAM. The only time an NUC is great is when you absolutely require Windows.

The ODROID, in the other hand, is quite cheap, with the U3 of ~$60. That is quite cheap compared to the NUC, because the U3 has quite a powerful chipset!

My code is Visual C++, but the conversion to Linux C++ should be simple because I don't really use the extra features that VC++ adds. Otherwise, I also have the ability to run my code in Mono/Wine.

Also, the fact that most ARM chips are unlocked is splendid. These computers need only about a 30 minute uptime at competitions, so overclocking at ~2-2.1GHz is not just something to dream about, but a possibility!

If we get an SBC, I will actually have a freshman do the work for me because it is on my list to teach a freshman artificial intelligence, and more advanced computer science, and some precalc is fun too. I have been working on some courseware that I wish to deploy to kids in Elementary school because what is more better than an army or uber-intelligent middle-schoolers? .

I will also have the Freshman port my code to Linux because that will force him/her to read through the code and get a basic understanding of how it works!

Last edited by yash101 : 03-03-2014 at 11:26 AM.
  #12   Spotlight this post!  
Unread 03-03-2014, 10:56 PM
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
Re: Visual C++: Getting socket server to run parallel to other processes

Interesting usage of freshman slave labor...

Does your freshman know socket/thread programming? If not, then you should probably go over that with him because threading can get really complicated really fast and when you have multiple reads and writes going on at the same time through your sockets (which seems to be your plan) , you need to have a sound asynchronous environment that won't fail you during a match.

Yeah the NUC is way too pricey to run Linux. I think the team had money to throw away and we chose to throw it away on our vision processing (which we didn't even fully use in competition).

Alex Brinister
Closed Thread


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


All times are GMT -5. The time now is 03:38 AM.

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