My team is trying to use a Raspberry Pi to run our vision program, and we are having issues trying to get it to run. We have been able to compile it, and we have our full custom script developed, so we simply rewrote the main.cpp file to run with that. However, in the console output of the FRCVision WebDashboard, there is no output that suggests that the program is running. This is the output of the console:
CS: rPi Camera 0: Connecting to USB camera on /dev/video0
CS: rPi Camera 0: set format 1 res 160x120
CS: rPi Camera 0: Connecting to USB camera on /dev/video0
CS: rPi Camera 0: set format 1 res 320x240
CS: rPi Camera 0: set FPS to 30
CS: rPi Camera 0: SetConfigJson: setting exposure to 5
NT: ERROR: select() to 172.22.11.2 port 1735 error 101 - Network is unreachable (TCPConnector.cpp:173)
NT: ERROR: could not resolve roboRIO-5332-FRC.lan address (TCPConnector.cpp:99)
NT: client: CONNECTED to server 10.53.32.2 port 1735
NT: ERROR: could not resolve roboRIO-5332-FRC.frc-field.local address (TCPConnector.cpp:99)
When our vision program starts, it should immediately print a script that says “Hello World.” We have been able to run it on our laptops, but cannot get it to print this to the Pi WebDashboard. Is there a step we are missing here?
What version of the FRCVision image? How did you upload the executable? What are you using to print the output from your program? I’m a little confused when you say “print a script”… did you mean to say you do something like printf() in your .cpp file? You may need to flush stdout; if you’re using std::cout, outputting std::endl will flush.
You can also try using wpi::outs() (include wpi/raw_ostream.h)
wpi::outs() << "Hello World\n";
Also, the console is a bit buggy with always scrolling to the bottom, make sure you’ve actually scrolled it to the bottom of the screen. And output when the console is disabled is lost. You can try clicking the terminate button on the vision status screen… you should see “Waiting for 5 seconds…” and then the output of your program.
Okay, I tried that and it printed the “Hello World” message, but now its printing this error:
Hello World!
NT: ERROR: select() to 172.22.11.2 port 1735 error 101 - Network is unreachable (TCPConnector.cpp:173)
NT: ERROR: could not resolve roboRIO-5332-FRC.lan address (TCPConnector.cpp:99)
NT: client: CONNECTED to server 10.53.32.2 port 1735
NT: ERROR: could not resolve roboRIO-5332-FRC.frc-field.local address (TCPConnector.cpp:99)
(uploaded:703): GStreamer-CRITICAL **: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
So, I’m looking in my code and it appears to be something with the way I call my camera into the code. Right now I use:
cv::VideoCapture cap(0)
And that seems to be throwing the error. I have also tried using “/dev/video0” and it is still not working. Do I need to call the camera in a different way?
So you’re using OpenCV instead of CameraServer to get the camera stream? Clearly you have a quite different image processing pipeline than the template code. If you share your code, myself or someone else may be able to help more.
Our intended idea was to run the code that we originally intended to run on our Jetson on the Pi because it was having connection issues with the Robot Network. We are able to compile this using the Raspbian compiler, but are there any other switches we have to make for it to work with the FRCVision image?
And then call cvSink.GetFrame() to get the image into a cv::Mat.
(you can also do this directly with cscore functions, but the above is just a little shorter, and also publishes the stream information for the unprocessed camera to NT in case you want to view it on your dashboard)
I am trying these commands, but am now getting hit with this error when I try to compile the code:
arm-raspbian9-linux-gnueabihf-g++ -pthread -g -Og -c -o main.o -Iinclude -Iinclude/opencv -Iinclude main.cpp
main.cpp: In function 'int main()':
main.cpp:95:2: error: 'CameraServer' has not been declared
CameraServer::GetInstance().StartAutomaticCapture(0);
^~~~~~~~~~~~
main.cpp:96:22: error: 'CameraServer' has not been declared
cs::CvSink cvSink = CameraServer::GetInstance().GetVideo();
^~~~~~~~~~~~
main.cpp:115:31: error: 'class cs::CvSink' has no member named 'getFrame'; did you mean 'GetName'?
currentFrame = cvSink.getFrame();
^~~~~~~~
Makefile:23: recipe for target 'main.o' failed
make: *** [main.o] Error 1
For reference, I am simply editing the main.cpp file in the same directory as the example code, and I moved in the include call for the CameraServer library.
Whoops, I left out the frc:: namespace. Should be frc::CameraServer::... GetFrame() should also be capitalized. It takes the Mat as a parameter and returns a timestamp (or 0 on error).
Okay, the code is working now, but the settings from the FRCVision dashboard are having no effect on the camera. For example, I can set the exposure from the dashboard, but it is not effecting the camera itself. Is there a way to fix that?
Your code is responsible for setting the camera settings. The webdashboard only saves them to a json file. The template programs load the settings from the json file, but your code isn’t based on the template. So if you want the webdashboard settings page to work you need to copy the appropriate code in from the C++ template.