36#if defined(JEVOIS_A33)
43#define JEVOIS_CAMERA_DEFAULT "/dev/video0"
46#define JEVOIS_GADGET_DEFAULT "/dev/video1"
49#define JEVOIS_SERIAL_DEFAULT "/dev/ttyS0"
52#define JEVOIS_USBSERIAL_DEFAULT "/dev/ttyGS0"
55#define JEVOIS_CAMERASENS_DEFAULT CameraSensor::ov9650
58#define JEVOIS_IMUSPI_DEFAULT ""
60#elif defined(JEVOIS_PRO)
67#define JEVOIS_CAMERA_DEFAULT "/dev/video0"
70#define JEVOIS_GADGET_DEFAULT ""
73#define JEVOIS_SERIAL_DEFAULT "/dev/ttyS4"
76#define JEVOIS_USBSERIAL_DEFAULT ""
80#define JEVOIS_CAMERASENS_DEFAULT CameraSensor::any
83#define JEVOIS_IMUSPI_DEFAULT "/dev/spidev32766.0"
86#error "Neither JEVOIS_A33 nor JEVOIS_PRO defined -- ABORT"
96#define JEVOIS_CAMERA_DEFAULT "/dev/video0"
99#define JEVOIS_GADGET_DEFAULT ""
102#define JEVOIS_SERIAL_DEFAULT "stdio"
105#define JEVOIS_USBSERIAL_DEFAULT ""
108#define JEVOIS_IMUSPI_DEFAULT ""
112#define JEVOIS_CAMERASENS_DEFAULT CameraSensor::imx290
115#define JEVOIS_CAMERASENS_DEFAULT CameraSensor::ov9650
120namespace cv {
namespace parallel {
class ParallelForAPI; } }
137 static ParameterCategory
const ParamCateg(
"Engine Options");
141 "file name (e.g., movie.mpg) or image sequence (e.g., im%02d.jpg, to read frames "
142 "im00.jpg, im01.jpg, etc).",
147 "manually, it is set through boot-time configuration.",
152 "using the global JeVois params.cfg config file.",
153 CameraLens::standard, CameraLens_Values, ParamCateg);
155 JEVOIS_DECLARE_PARAMETER(imudev, std::string,
"IMU SPI device name, typically starting with /dev/spidev..., "
156 "or empty if device does not have an IMU with SPI interface.",
165 "On host hardware, a display window will be used unless gadgetdev is None (useful "
166 "for benchmarking) or is a file stem for a movie file that does not start with /dev/ "
167 "(and which should contain a printf-style directive for a single int argument, "
168 "the movie number).",
177 "Note that this parameter is only available when parsing command-line arguments. "
178 "At runtime, the setmapping command should be used instead.",
184 "in the GUI, which can be used to peek at serial communications not "
185 "directed to the console. Can be turned off at start time (e.g., in the "
186 "global JeVois params.cfg) as there is some small CPU cost to it.",
192 "or 'stdio' to use the console, or empty for no hardware serial port",
209 "buffer memory. This can accelerate severalfolds access to the captured image data, but "
210 "it may also yield stripe artifacts with some modules, such as PassThrough. The stripes "
211 "are pieces of incorrect data in the cache. You should experiment with each particular "
212 "module. Turbo mode is not recommended for any production-grade application.",
220 SerPort::None, SerPort_Values, ParamCateg);
224 "in the video stream. Only takes effect if streaming video to USB.",
229 SerPort::None, SerPort_Values, ParamCateg);
239 , CPUmode::Performance, CPUmode_Values, ParamCateg);
244 CPUmode::Performance, CPUmode_Values, ParamCateg);
250 ". To enable overclock frequencies above 2208 MHz, you need to first edit "
251 "/boot/env.txt and change max_freq_a73, then reboot. Use with caution!"
255 , 1344, { 120, 240, 312, 408, 480, 504, 600, 648, 720, 816, 912, 1008,
256 1044, 1056, 1080, 1104, 1116, 1152, 1200, 1224, 1248, 1296, 1344 },
260 , 2208, { 500, 667, 1000, 1200, 1398, 1512, 1608, 1704, 1800, 1908, 2016,
261 2100, 2208, 2304, 2400 },
270 "To enable overclock frequencies above 1800 MHz, you need to first edit "
271 "/boot/env.txt and change max_freq_a53, then reboot. Use with caution!",
273 1800, { 500, 667, 1000, 1200, 1398, 1512, 1608, 1704, 1800, 1908, 2016,
280 "reduces the amount of USB bandwidth used by each JeVois camera, from 3kb "
281 "per USB isochronous microframe to 1kb. All 3 JeVois cameras must have this "
282 "option enabled, and the JeVois linux kernel module should also have "
283 "been loaded with multicam on.",
288 "received at the command-line interface. Recommended for advanced users only.",
293 "attempting to load a python module will throw an exception. Disabling python saves "
294 "a lot of memory and may be useful when using C++ modules that run large deep neural "
300 "using sendSerial(), for each video frame, or 0 for no limit. Any message sent by "
301 "the module beyond the first serlimit ones will be dropped. This is useful to avoid "
302 "overloading the serial link, for example in case one is running a ArUco detector and "
303 "a large number of ArUco tags are present in the field of view of JeVois.",
313 "interference, only effective on JeVois-Pro Platform, otherwise ignored. Set conslock "
314 "to false if you are experiencing hard crashes and want to run jevoispro-daemon in gdb.",
319 "is stuck somehow, or 0.0 for no watchdog",
324 "machine vision modules, cycling to the next modules after a number "
325 "of seconds specified by this parameter (or 0.0 for no demo mode).",
405 public Parameter<engine::cameradev, engine::camerasens, engine::cameralens, engine::cameranbuf,
406 engine::gadgetdev, engine::gadgetnbuf, engine::imudev, engine::videomapping,
407 engine::serialdev, engine::usbserialdev, engine::camreg, engine::imureg,
408 engine::camturbo, engine::serlog, engine::videoerrors, engine::serout,
409 engine::cpumode, engine::cpumax, engine::multicam, engine::quietcmd,
410 engine::python, engine::serlimit
412 , engine::serialmonitors, engine::gui, engine::conslock, engine::cpumaxl,
413 engine::cpumodel, engine::watchdog, engine::demomode
419 Engine(std::string
const & instance);
422 Engine(
int argc,
char const* argv[], std::string
const & instance);
437 float oframespersec)
const;
451 size_t getVideoMappingIdx(
unsigned int iformat,
unsigned int iframe,
unsigned int interval)
const;
503 void sendSerial(std::string
const & str,
bool islog =
false);
506 std::shared_ptr<Module>
module()
const;
509 std::shared_ptr<IMU> imu()
const;
512 std::shared_ptr<Camera>
camera()
const;
575 void runScriptFromFile(std::string
const & filename, std::shared_ptr<UserInterface> ser,
579 void onParamChange(engine::serialdev
const & param, std::string
const & newval)
override;
582 void onParamChange(engine::usbserialdev
const & param, std::string
const & newval)
override;
585 void onParamChange(engine::cpumode
const & param, engine::CPUmode
const & newval)
override;
588 void onParamChange(engine::cpumax
const & param,
unsigned int const & newval)
override;
591 void onParamChange(engine::videoerrors
const & param,
bool const & newval)
override;
595 void onParamChange(engine::gui
const & param,
bool const & newval)
override;
598 void onParamChange(engine::cpumaxl
const & param,
unsigned int const & newval)
override;
601 void onParamChange(engine::cpumodel
const & param, engine::CPUmode
const & newval)
override;
604 void onParamChange(engine::demomode
const & param,
float const & newval)
override;
631 bool parseCommand(std::string
const & str, std::shared_ptr<UserInterface> s, std::string
const & pfx =
"");
634 std::list<std::shared_ptr<UserInterface> > itsSerials;
636 void setFormatInternal(
size_t idx);
640 void foreachCamCtrl(std::function<
void(
struct v4l2_queryctrl & qc, std::set<int> & doneids)> && func);
643 std::string camCtrlHelp(
struct v4l2_queryctrl & qc, std::set<int> & doneids);
646 std::string camCtrlInfo(
struct v4l2_queryctrl & qc, std::set<int> & doneids);
649 void cmdInfo(std::shared_ptr<UserInterface> s,
bool showAll, std::string
const & pfx =
"");
652 void modCmdInfo(std::shared_ptr<UserInterface> s, std::string
const & pfx =
"");
655 std::string camctrlname(
unsigned int id,
char const * longname)
const;
658 unsigned int camctrlid(std::string
const & shortname);
663 void reportErrorInternal(std::string
const & err =
"");
667 bool itsManualStreamon;
668 std::atomic<bool> itsVideoErrors;
670 std::string itsModuleConstructionError;
672#ifdef JEVOIS_PLATFORM_A33
674 void checkMassStorage();
675 std::future<void> itsCheckMassStorageFut;
676 std::atomic<bool> itsCheckingMassStorage;
677 std::atomic<bool> itsMassStorageMode;
678 void startMassStorageMode();
679 void stopMassStorageMode();
682 std::atomic<size_t> itsNumSerialSent;
683 std::atomic<int> itsRequestedFormat;
686 std::shared_ptr<GUIhelper> itsGUIhelper;
689 void camCtrlGUI(
struct v4l2_queryctrl & qc, std::set<int> & doneids);
691 std::shared_ptr<jevois::Watchdog> itsWatchdog;
693 bool itsDemoReset =
true;
700 std::vector<std::pair<std::string , std::string >> params;
702 std::vector<DemoData> itsDemoData;
703 bool itsNextDemoRequested =
false;
709 std::map<void *, Component *> itsPythonRegistry;
710 mutable std::mutex itsPyRegMtx;
714 std::shared_ptr<cv::parallel::ParallelForAPI> itsOpenCVparallelAPI;
#define JEVOIS_A33
Target hardware selection:
#define JEVOIS_CAMERASENS_DEFAULT
Default camera sensor.
#define JEVOIS_CAMERA_DEFAULT
On platform hardware, device for the camera sensor.
#define JEVOIS_GADGET_DEFAULT
On platform hardware, device for the USB gadget driver (which sends video frames over USB to a host c...
#define JEVOIS_SERIAL_DEFAULT
On platform hardware, device for the 4-pin hardware serial port.
#define JEVOIS_USBSERIAL_DEFAULT
On platform hardware, device for serial-over-USB port.
#define JEVOIS_IMUSPI_DEFAULT
Default IMU spi device.
Helper class for camera calibration, which allows some modules to compute 3D locations of objects.
A component of a model hierarchy.
JeVois processing engine - gets images from camera sensor, processes them, and sends results over USB...
Component * getPythonComponent(void *pyinst) const
Get the component registered with a given python instance.
void requestSetFormat(int idx)
Use this to request a format change from within process()
void streamOn()
Start streaming on video from camera, processing, and USB.
void drawCameraGUI()
Draw all camera controls into our GUI.
void nextDemo()
When in demo mode, switch to next demo.
void reboot()
Request a reboot.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(usbserialdev, std::string, "Over-the-USB serial device name, or empty", JEVOIS_USBSERIAL_DEFAULT, ParamCateg)
Parameter.
void onParamChange(engine::cpumaxl const ¶m, unsigned int const &newval) override
Parameter callback.
std::atomic< bool > itsStopMainLoop
Flag used to stop the main loop.
JEVOIS_DECLARE_PARAMETER(quietcmd, bool, "When true, do not issue a message 'OK' after every correct command " "received at the command-line interface. Recommended for advanced users only.", false, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(videoerrors, bool, "Show any machine vision module errors (exceptions) " "in the video stream. Only takes effect if streaming video to USB.", true, ParamCateg)
Parameter.
void preInit() override
Override of Manager::preInit()
std::shared_ptr< Module > itsModule
Our current module.
JEVOIS_DECLARE_PARAMETER(python, bool, "When true, enable support for modules written in Python. Otherwise, " "attempting to load a python module will throw an exception. Disabling python saves " "a lot of memory and may be useful when using C++ modules that run large deep neural " "networks.", true, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(watchdog, double, "Timeout in seconds after which we kill this process if the main loop " "is stuck somehow, or 0.0 for no watchdog", 10.0, ParamCateg)
Parameter.
std::atomic< bool > itsStreaming
True when we are streaming video.
void onParamChange(engine::serialdev const ¶m, std::string const &newval) override
Parameter callback.
JEVOIS_DECLARE_PARAMETER(imureg, bool, "Enable raw access to IMU registers through setimureg and getimureg", false, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(serout, SerPort, "Send module serial messages to selected serial port(s)", SerPort::None, SerPort_Values, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(camturbo, bool, "Enable camera turbo mode by relaxing the need for DMA-coherent video " "buffer memory. This can accelerate severalfolds access to the captured image data, but " "it may also yield stripe artifacts with some modules, such as PassThrough. The stripes " "are pieces of incorrect data in the cache. You should experiment with each particular " "module. Turbo mode is not recommended for any production-grade application.", false, ParamCateg)
Parameter.
void saveCameraCalibration(CameraCalibration const &calib, std::string const &stem="calibration")
Helper to save an OpenCV camera matrix and distortion coeffs for the current running module.
std::atomic< bool > itsRunning
True when we are running.
size_t numVideoMappings() const
Return the number of video mappings.
std::shared_ptr< Module > module() const
Get a pointer to our current module (may be null)
void onParamChange(engine::demomode const ¶m, float const &newval) override
Parameter callback.
std::shared_ptr< IMU > itsIMU
void onParamChange(engine::cpumax const ¶m, unsigned int const &newval) override
Parameter callback.
JEVOIS_DECLARE_PARAMETER(conslock, bool, "Lock the console and capture the keyboard and mouse to avoid " "interference, only effective on JeVois-Pro Platform, otherwise ignored. Set conslock " "to false if you are experiencing hard crashes and want to run jevoispro-daemon in gdb.", true, ParamCateg)
Parameter.
void abortDemo()
When in demo mode, abort demo mode.
size_t getDefaultVideoMappingIdx() const
Allow access to the default video mapping index.
JEVOIS_DECLARE_PARAMETER(videomapping, int, "Index of Video Mapping to use, or -1 to use the default mapping. " "Note that this parameter is only available when parsing command-line arguments. " "At runtime, the setmapping command should be used instead.", -1, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(serlog, SerPort, "Show log and debug messages on selected serial port(s)", SerPort::None, SerPort_Values, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(multicam, bool, "Allow up to 3 JeVois cameras on one USB bus. Enabling this " "reduces the amount of USB bandwidth used by each JeVois camera, from 3kb " "per USB isochronous microframe to 1kb. All 3 JeVois cameras must have this " "option enabled, and the JeVois linux kernel module should also have " "been loaded with multicam on.", false, ParamCateg)
Parameter.
JEVOIS_DEFINE_ENUM_CLASS(SerPort,(None)(All)(Hard)(USB))
Enum for Parameter.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(cpumaxl, unsigned int, "CPU maximum frequency in MHz, for A53 little cores. " "To enable overclock frequencies above 1800 MHz, you need to first edit " "/boot/env.txt and change max_freq_a53, then reboot. Use with caution!", 1800, { 500, 667, 1000, 1200, 1398, 1512, 1608, 1704, 1800, 1908, 2016, 2100, 2208 }, ParamCateg)
Parameter.
void setFormat(size_t idx)
Callback for when the user selects a new output video format.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(demomode, float, "Show a demonstration of some available JeVois-Pro " "machine vision modules, cycling to the next modules after a number " "of seconds specified by this parameter (or 0.0 for no demo mode).", 0.0F, ParamCateg)
Parameter.
void onParamChange(engine::usbserialdev const ¶m, std::string const &newval) override
Parameter callback.
JEVOIS_DECLARE_PARAMETER(serlimit, size_t, "Maximum number of serial messages that can be sent by a module " "using sendSerial(), for each video frame, or 0 for no limit. Any message sent by " "the module beyond the first serlimit ones will be dropped. This is useful to avoid " "overloading the serial link, for example in case one is running a ArUco detector and " "a large number of ArUco tags are present in the field of view of JeVois.", 0, ParamCateg)
Parameter.
void onParamChange(engine::gui const ¶m, bool const &newval) override
Parameter callback.
void unRegisterPythonComponent(Component *comp)
Unregister a component as linked to some python code, used by dynamic params created in python.
void onParamChange(engine::cpumodel const ¶m, engine::CPUmode const &newval) override
Parameter callback.
void setOpenCVthreading(char const *name="jevois")
Set OpenCV parallel threading framework.
void sendSerial(std::string const &str, bool islog=false)
Send a string to all serial ports.
void streamOff()
Stop streaming on video from camera, processing, and USB.
void runScriptFromFile(std::string const &filename, std::shared_ptr< UserInterface > ser, bool throw_no_file)
Run a script from file.
JEVOIS_DECLARE_PARAMETER(cameranbuf, unsigned int, "Number of video input (camera) buffers, or 0 for automatic.", 0, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(cpumax, unsigned int, "CPU maximum frequency in MHz" ". To enable overclock frequencies above 2208 MHz, you need to first edit " "/boot/env.txt and change max_freq_a73, then reboot. Use with caution!", 2208, { 500, 667, 1000, 1200, 1398, 1512, 1608, 1704, 1800, 1908, 2016, 2100, 2208, 2304, 2400 }, ParamCateg)
Parameter.
size_t itsDefaultMappingIdx
Index of default mapping.
JEVOIS_DEFINE_ENUM_CLASS(CPUmode,(PowerSave)(Conservative)(OnDemand)(Interactive)(Performance))
Enum for Parameter.
void quit()
Terminate the program.
bool parseCommand(std::string const &str, std::shared_ptr< UserInterface > s, std::string const &pfx="")
Parse a user command received over serial port.
void onParamChange(engine::videoerrors const ¶m, bool const &newval) override
Parameter callback.
int mainLoop()
Main loop: grab, process, send over USB. Should be called by main application thread.
JEVOIS_DECLARE_PARAMETER(gadgetdev, std::string, "Gadget device name. This is used on platform hardware only. " "On host hardware, a display window will be used unless gadgetdev is None (useful " "for benchmarking) or is a file stem for a movie file that does not start with /dev/ " "(and which should contain a printf-style directive for a single int argument, " "the movie number).", JEVOIS_GADGET_DEFAULT, ParamCateg)
Parameter.
VideoMapping const & getVideoMapping(size_t idx) const
Allow access to our video mappings which are parsed from file at construction.
size_t getVideoMappingIdx(unsigned int iformat, unsigned int iframe, unsigned int interval) const
Get the video mapping index for a given UVC iformat, iframe and interval.
JEVOIS_DECLARE_PARAMETER(gadgetnbuf, unsigned int, "Number of video output (USB video) buffers, or 0 for auto", 0, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(serialmonitors, bool, "If true, serial port monitors will be enabled " "in the GUI, which can be used to peek at serial communications not " "directed to the console. Can be turned off at start time (e.g., in the " "global JeVois params.cfg) as there is some small CPU cost to it.", true, ParamCateg)
Parameter.
VideoMapping const & getCurrentVideoMapping() const
Get the current video mapping.
void registerPythonComponent(Component *comp, void *pyinst)
Register a component as linked to some python code, used by dynamic params created in python.
JEVOIS_DECLARE_PARAMETER(camreg, bool, "Enable raw access to camera registers through setcamreg and getcamreg", false, ParamCateg)
Parameter.
CameraCalibration loadCameraCalibration(std::string const &stem="calibration", bool do_throw=false)
Helper to load an OpenCV camera matrix and distortion coeffs for the current running module.
VideoMapping const & findVideoMapping(unsigned int oformat, unsigned int owidth, unsigned int oheight, float oframespersec) const
Find the VideoMapping that has the given output specs, or throw if not found.
void onParamChange(engine::cpumode const ¶m, engine::CPUmode const &newval) override
Parameter callback.
JEVOIS_DECLARE_PARAMETER(camerasens, CameraSensor, "Camera sensor. Users would usually not set this parameter " "manually, it is set through boot-time configuration.", JEVOIS_CAMERASENS_DEFAULT, CameraSensor_Values, ParamCateg)
Parameter.
void reloadVideoMappings()
Re-load video mappings from videomappings.cfg.
void postInit() override
Override of Manager::postInit()
std::shared_ptr< Camera > camera() const
Get a pointer to our Camera (may be null, especially if not using a camera but, eg,...
JEVOIS_DECLARE_PARAMETER(cameralens, CameraLens, "Camera lens. Users should usually set this parameter " "using the global JeVois params.cfg config file.", CameraLens::standard, CameraLens_Values, ParamCateg)
Parameter.
VideoMapping const & getDefaultVideoMapping() const
Allow access to the default video mapping.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(cpumode, CPUmode, "CPU frequency modulation mode" " for A73 big cores", CPUmode::Performance, CPUmode_Values, ParamCateg)
Parameter.
std::shared_ptr< VideoInput > itsCamera
Our camera.
JEVOIS_DECLARE_PARAMETER(cameradev, std::string, "Camera device name (if starting with /dev/v...), or movie " "file name (e.g., movie.mpg) or image sequence (e.g., im%02d.jpg, to read frames " "im00.jpg, im01.jpg, etc).", JEVOIS_CAMERA_DEFAULT, ParamCateg)
Parameter.
std::shared_ptr< VideoOutput > itsGadget
Our IMU.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(cpumodel, CPUmode, "CPU frequency modulation mode for A53 little cores", CPUmode::Performance, CPUmode_Values, ParamCateg)
Parameter.
std::timed_mutex itsMtx
Mutex to protect our internals.
std::vector< VideoMapping > itsMappings
All our mappings from videomappings.cfg.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(serialdev, std::string, "Hardware (4-pin connector) serial device name, " "or 'stdio' to use the console, or empty for no hardware serial port", JEVOIS_SERIAL_DEFAULT, ParamCateg)
Parameter.
void clearErrors()
Clear all errors currently displayed in the JeVois-Pro GUI.
void foreachVideoMapping(std::function< void(VideoMapping const &m)> &&func)
Run a function on every video mapping.
void reportError(std::string const &err)
std::unique_ptr< DynamicLoader > itsLoader
Our module loader.
VideoMapping itsCurrentMapping
Current mapping, may not match any in itsMappings if setmapping2 used.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(gui, bool, "Use a graphical user interface instead of plain display " "when true", true, ParamCateg)
Parameter.
Manager of a hierarchy of Component objects.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Main namespace for all JeVois classes and functions.
Simple struct to hold video mapping definitions for the processing Engine.