|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#16
|
||||
|
||||
|
Re: Network Tables
Quote:
https://www.youtube.com/watch?v=nLmviNrMers Shows a demo of everything... and in here is a link to the first forge... I'll include here for convenience: http://firstforge.wpi.edu/sf/projects/smartcppdashboard Now... this code is due for an update, but we are just about ready to head out to Lonestar regionals... so after that I may get the code all updated probably in the next two weeks, but in its current state it should get you going pretty well. Here is a sneak peak of what the newer stuff can do (not yet checked in there): https://www.youtube.com/watch?v=fccxxlvMqY0 |
|
#17
|
||||
|
||||
|
Re: Network Tables
I think he's talking about this: http://firstforge.wpi.edu/sf/sfmain/...rtcppdashboard
The opencv files should be structured something like so: Code:
C:\Python27\opencv_ffmpeg2xx.dll C:\Python27\lib\site-packages\cv2.pyd |
|
#18
|
||||
|
||||
|
Re: Network Tables
We had to install ffdshow as well to get loading from a file working on windows.
|
|
#19
|
||||
|
||||
|
Re: Network Tables
So it really seems as though you were in the same boat as me three weeks ago. There is one very easy fix to the problem you are fixing, but it requires kinda out of the box thinking
![]() Through my VC++ opencv adventure, I learned that many processor intensive routines may have a such a low performance that the processing rate will become less than the capture rate. I believe I properly understand your setup. You are using an MJPEG stream with VideoCapture. I have two solutions available for you that should be relatively easy to use. If you must stay with the network MJPEG stream approach, --Decrease the capture rate of the camera to the MAX rate that your vision software will run at. This will cause you to economize on your lag and if for some reason the software runs a bit faster, it will just wait for the next frame. --THREAD YOUR GRABBER The second option is what saved me. I was before getting 30 seconds of lag even though I was running at 5fps. What this will do is run the grabber parallelly. I believe you are pretty decent at C++ so you should be able to figure it out. Try <thread> and <mutex>. So what you want to do is wait for the next frame to be available from the camera and download it immediately. Do not do this in the main Mat because it will make the entire program wait and brick up your effort. After the frame grab, send the data to the actual processing Mat. In your processing loop, copy over that global Mat into a local Mat so the system can free the resource as quick as possible! Then, perform the operations you want to do. This way, the old frames are constantly deleted as new frames are available Try to use both the following together. Using just the first option will make no difference. Using both options is when you get both efficient and get rid of the lag. I have been paying attention to your posts lately and I believe you have a PandaBoard. Snag an inexpensive USB webcam and that should eliminate most of the lag you are experiencing! I just gave you my two cents, so good luck! Also, you might find it easier to implement a UDP bidirectional socket instead of NetworkTables. There are libraries for this in C++, Java and even LabView! |
|
#20
|
||||
|
||||
|
Re: Network Tables
Quote:
|
|
#21
|
|||||
|
|||||
|
Re: Network Tables
Quote:
Assuming the data to send is the same size (which depends on implementation), UDP would in the real world send less data, as it never resends packets that failed. You are also sending images on the same ethernet link, so a few extra bytes or packets here or there really makes no difference. In either case, you need a listener somewhere to read all of the packets from the buffer. Network Tables already created a thread to do this, with UDP you are doing it on your own. In many ways, I prefer UDP sockets as it is very simple to implement (there are thousands of tutorials on the internet describing basic sockets), you can use a simple struct to organize the data, and a checksum to discard packets that are garbled in transit. No library required. In LV, you can do it super easily by flattening a cluster to a string and then unflattering it on the other side. |
|
#22
|
||||
|
||||
|
Re: Network Tables
Quote:
Quote:
So ... you don't need to have a dedicated thread if you are using WinSock2, but for VxWorks, and the original WinSock... you do. |
|
#23
|
|||||
|
|||||
|
Re: Network Tables
Quote:
You do need to read the incoming network data at least as fast as it is arriving, but there is no requirement for you to do it in its own thread. |
|
#24
|
||||
|
||||
|
Re: Network Tables
Quote:
What you say here is what I was trying to say more or less... WinSock2 handles the stress of neglecting to process the packets. It was indeed the neglect of processing the incoming packets that caused this symptom which I confirmed with Greg McKaskle, and Brian from team 118 also ran into this issue back in 2012. It may indeed be possible that you can make it where it doesn't have its own thread... you could implement some kind of hand shake solution or defer sending packets until Auton or Telop functions are being called. But these alternatives are messy implementation IMHO. NetworkTables on the other hand does not have these issues at all, and probably one of the main reasons I switched... that and the ease of use, where adding more variables manually in UDP is a real pain. I've included these UDP_Listener.h UDP_Listener.cpp for reference where I could macro switch from UDP to Network Tables... it was so much easier working with network tables that I dropped this whole interfacing design. |
|
#25
|
|||
|
|||
|
Re: Network Tables
So, maybe I didn't follow your analysis and notes well enough, but FYI I had similar problems using direct python opencv VideoCapture bindings, until I had the Windows PATH variables set correctly to the OpenCV install. I'm seeing latencies like a second, but nothing like 30.
|
|
#26
|
|||||
|
|||||
|
Re: Network Tables
Why wait until Auton or Teleop functions are called?
Why don't you just run your code all the time, and then additionally run auton or teleop code based on the driver station data? |
|
#27
|
||||
|
||||
|
Re: Network Tables
Quote:
But let's go back for a moment... when I first did UDP and waited for Auton and Teleop before I knew about this bug. Why did I do it then? Because writing threads is a messy business, and should be avoided if at all possible. I mean look at the trouble that happened with the lockup bug in Network Tables... Using winsock2 I was able to listen to packets on the same thread and it was nice and clean code to work out. So given that... all of our code runs on a single thread... we don't use the PID that comes with WPI... it does not need to be on a separate thread. Instead we introduce a time-slice delta in seconds to the computations... this way the PID can work in 10ms (ish) iterations on the same thead rather than the default 50 on a separate thread... thus being free from any mess of critical sections! |
|
#28
|
||||
|
||||
|
Re: Network Tables
Thanks for all the help
![]() So does anybody have the Network Tables library for C++? I haven't got Wind River and nobody on my team know where the CD is... |
|
#29
|
|||||
|
|||||
|
Re: Network Tables
We run everything in a single task (including a UDP listener and RS232 listener). We just don't stop the task when auton or teleop is disabled. We clear the integrators and reset to a safe state when the disabled signal goes from low to high, and run everything in a single 10ms high priority task. The UDP listener reads in a While loop with a 0ms timeout and breaks when the read returns a timeout. The RS232 listener does similar.
|
|
#30
|
||||
|
||||
|
Re: Network Tables
I don't have the UDP the setup down, but I would like to get the code down sometime soon.
I was wondering if anyone knows how to write a socket server with javax.microedition.io.*; I am currently shot in the dark and have no idea to start |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|