Go to Post ADMIT IT! Dave Lavery has better legs than Amanda Morrison! - DCA Fan [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 09-02-2015, 19:07
dougwilliams's Avatar
dougwilliams dougwilliams is offline
Engineer - Controls, Electronics
FRC #2053 (TigerTronics)
Team Role: Mentor
 
Join Date: May 2013
Rookie Year: 2013
Location: Vestal, NY
Posts: 109
dougwilliams is on a distinguished road
Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

Just wondering if anyone has had any luck getting OpenCV (or for that matter, any) functions to run in a separate WPILib task / thread on the RoboRIO?

If you had it would be helpful to know how well it works in terms of eliminating latency in your main robot code? We also need help in implementing the task creation. If someone has example code they could point me to for making a new thread (not necessarily OpenCV) that would be great to use as a reference for proper implementation of the WPILib Task functions.
Reply With Quote
  #2   Spotlight this post!  
Unread 10-02-2015, 00:22
calcmogul's Avatar
calcmogul calcmogul is offline
WPILib Developer
AKA: Tyler Veness
FRC #3512 (Spartatroniks)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Santa Maria, CA
Posts: 52
calcmogul is just really nicecalcmogul is just really nicecalcmogul is just really nicecalcmogul is just really nice
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

If you're using C++, you can make a new thread with std::thread. http://www.cplusplus.com/reference/thread/thread/

Use std::mutex for synchronization (i.e. variable passing) between threads. std::future would also work well here.
Reply With Quote
  #3   Spotlight this post!  
Unread 12-02-2015, 02:20
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

My team has been using tasks for a variety of things for years now. All our tasks are simply based on a class jankyTask. Please see the following post for links to the github code and a write-up I did on how it all works a few years ago.

http://www.chiefdelphi.com/forums/sh...ght=Tasks+in+C

RoboBob
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2015, 07:56
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 195
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

Yep. We just got that implemented last night and our code is on our git hub page.


https://github.com/team2053tigertron...DRobot2015/src

It is in the robot.cpp file
Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2015, 10:18
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 195
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

I just realized you posted this! Oops! Well I guess we solved our own problem! Well, it works now.
Reply With Quote
  #6   Spotlight this post!  
Unread 12-02-2015, 16:57
FleventyFive FleventyFive is offline
Registered User
FRC #4118
 
Join Date: Sep 2014
Location: Gainesville, FL
Posts: 23
FleventyFive is on a distinguished road
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

Quote:
Originally Posted by jreneew2 View Post
Yep. We just got that implemented last night and our code is on our git hub page.


https://github.com/team2053tigertron...DRobot2015/src

It is in the robot.cpp file
Are you okay with other teams using part of this project? Also, what version of OpenCV are you linking to and how did you get/compile it? Thanks
Reply With Quote
  #7   Spotlight this post!  
Unread 12-02-2015, 17:41
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 195
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
Post Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

Yeah, you are ok to use it! We are still refining the vision code for detecting totes though so you should redo that part if you can do it better. For compiling and linking, this is a lengthy process. We used just plain OpenCV2. We followed team 2168's linking instructions which are a bit vague so I will try and explain.

1. Download our OpenCV project from our github here. And move the project somewhere safe (we have C:\OpenCV_frc\arm\include\OpenCV\opencv2)

2. Then I assume you have an existing project for C++ (im not sure if this differs from java) go open eclipse and right click on your project go to Properties->C/C++ Build->Settings. Then go to the tool settings tab and click on Cross G++ Linker and add -rpath,C:\OpenCV_frc\arm\libs\opencv (what ever your directory is). Also make sure you have a comma in between entries.

3. Then go to C/C++ general and go to paths and symbols. Click on the library paths tab and hit add. Add the directory from your file system and type in C:\OpenCV_frc\arm\libs\opencv (what ever your directory was) hit apply.

4. Then go to the Libraries tab and add opencv_core,opencv_highgui,opencv_imgproc from C:\OpenCV_frc\arm\libs\opencv (whatever your directory is)

5.Now hit apply and add the cpp and h files in a folder in your project. we have our called Vision2015. Then add the necessary includes and and using namespace cv;

6. You should be able to compile and run the robot. You might want to see how to run the code on a separate task though because it will slow down drive code if running in a separate task. Our actual robot project in robot.cpp shows how to do that.


Please feel free to reply if you have any questions. Also, if you improve the tote detector in any way, contact us.

Have a fun time!,
Drew (2053 Programmer)

Last edited by jreneew2 : 12-02-2015 at 20:26.
Reply With Quote
  #8   Spotlight this post!  
Unread 13-02-2015, 14:25
PaulDavis1968's Avatar
PaulDavis1968 PaulDavis1968 is offline
Embedded Software/Systems Engineer
AKA: Master of Complexity
FRC #2053 (TigerTronics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Endicot NY
Posts: 91
PaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nice
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

Quote:
Originally Posted by jreneew2 View Post
Yeah, you are ok to use it! We are still refining the vision code for detecting totes though so you should redo that part if you can do it better. For compiling and linking, this is a lengthy process. We used just plain OpenCV2. We followed team 2168's linking instructions which are a bit vague so I will try and explain.

1. Download our OpenCV project from our github here. And move the project somewhere safe (we have C:\OpenCV_frc\arm\include\OpenCV\opencv2)

2. Then I assume you have an existing project for C++ (im not sure if this differs from java) go open eclipse and right click on your project go to Properties->C/C++ Build->Settings. Then go to the tool settings tab and click on Cross G++ Linker and add -rpath,C:\OpenCV_frc\arm\libs\opencv (what ever your directory is). Also make sure you have a comma in between entries.

3. Then go to C/C++ general and go to paths and symbols. Click on the library paths tab and hit add. Add the directory from your file system and type in C:\OpenCV_frc\arm\libs\opencv (what ever your directory was) hit apply.

4. Then go to the Libraries tab and add opencv_core,opencv_highgui,opencv_imgproc from C:\OpenCV_frc\arm\libs\opencv (whatever your directory is)

5.Now hit apply and add the cpp and h files in a folder in your project. we have our called Vision2015. Then add the necessary includes and and using namespace cv;

6. You should be able to compile and run the robot. You might want to see how to run the code on a separate task though because it will slow down drive code if running in a separate task. Our actual robot project in robot.cpp shows how to do that.


Please feel free to reply if you have any questions. Also, if you improve the tote detector in any way, contact us.

Have a fun time!,
Drew (2053 Programmer)

Did you get the tracking working on the RoboRio? Last I saw everything was a tote. I am assuming you got it working because Jason had it working on the laptop and this should of been a straight up port. I ask because when I saw it earlier yesterday it was running in the separate thread OK it just wasn't tracking right yet.
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2015, 16:28
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 195
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

Yeah, it was working when you were video conferencing with us. We just have to refine the colors.
Reply With Quote
  #10   Spotlight this post!  
Unread 13-02-2015, 16:33
PaulDavis1968's Avatar
PaulDavis1968 PaulDavis1968 is offline
Embedded Software/Systems Engineer
AKA: Master of Complexity
FRC #2053 (TigerTronics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Endicot NY
Posts: 91
PaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nice
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

If you update wpilib c++ robot development, be sure to go into wpilib.h and comment out #define REAL
Reply With Quote
  #11   Spotlight this post!  
Unread 13-02-2015, 22:23
FleventyFive FleventyFive is offline
Registered User
FRC #4118
 
Join Date: Sep 2014
Location: Gainesville, FL
Posts: 23
FleventyFive is on a distinguished road
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

Quote:
Originally Posted by jreneew2 View Post
Yeah, you are ok to use it! We are still refining the vision code for detecting totes though so you should redo that part if you can do it better. For compiling and linking, this is a lengthy process. We used just plain OpenCV2. We followed team 2168's linking instructions which are a bit vague so I will try and explain.

1. Download our OpenCV project from our github here. And move the project somewhere safe (we have C:\OpenCV_frc\arm\include\OpenCV\opencv2)

2. Then I assume you have an existing project for C++ (im not sure if this differs from java) go open eclipse and right click on your project go to Properties->C/C++ Build->Settings. Then go to the tool settings tab and click on Cross G++ Linker and add -rpath,C:\OpenCV_frc\arm\libs\opencv (what ever your directory is). Also make sure you have a comma in between entries.

3. Then go to C/C++ general and go to paths and symbols. Click on the library paths tab and hit add. Add the directory from your file system and type in C:\OpenCV_frc\arm\libs\opencv (what ever your directory was) hit apply.

4. Then go to the Libraries tab and add opencv_core,opencv_highgui,opencv_imgproc from C:\OpenCV_frc\arm\libs\opencv (whatever your directory is)

5.Now hit apply and add the cpp and h files in a folder in your project. we have our called Vision2015. Then add the necessary includes and and using namespace cv;

6. You should be able to compile and run the robot. You might want to see how to run the code on a separate task though because it will slow down drive code if running in a separate task. Our actual robot project in robot.cpp shows how to do that.


Please feel free to reply if you have any questions. Also, if you improve the tote detector in any way, contact us.

Have a fun time!,
Drew (2053 Programmer)

Thanks for the great instructions! However, every time I setup a project (including importing yours and fixing the paths to opencv) I get like 175 errors in opencv2/core/core.hpp. I had the same problem when I tried earlier in the season to get opencv in the project. Any idea why I would get so many errors? Sound like something to do with the index, but I've rebuilt in many times.

Edit: followed PaulDavis1968's suggestion to comment out that line in WPILIB. No idea what that does, but it fixed it!

Last edited by FleventyFive : 13-02-2015 at 22:36.
Reply With Quote
  #12   Spotlight this post!  
Unread 15-02-2015, 14:30
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 195
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
Re: Has anyone run OpenCV in a separate WPILLib Task / Thread on the RoboRIO?

Yeah, we found that out the hard way. After searching forever through OpenCV and wpilib we found that REAL is defined in both wpilib and OpenCV. Good luck with auto!
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


All times are GMT -5. The time now is 13:11.

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