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
135 static ParameterCategory
const ParamCateg(
"Engine Options");
139 "file name (e.g., movie.mpg) or image sequence (e.g., im%02d.jpg, to read frames "
140 "im00.jpg, im01.jpg, etc).",
145 "manually, it is set through boot-time configuration.",
150 "using the global JeVois params.cfg config file.",
151 CameraLens::standard, CameraLens_Values, ParamCateg);
153 JEVOIS_DECLARE_PARAMETER(imudev, std::string,
"IMU SPI device name, typically starting with /dev/spidev..., "
154 "or empty if device does not have an IMU with SPI interface.",
163 "On host hardware, a display window will be used unless gadgetdev is None (useful "
164 "for benchmarking) or is a file stem for a movie file that does not start with /dev/ "
165 "(and which should contain a printf-style directive for a single int argument, "
166 "the movie number).",
175 "Note that this parameter is only available when parsing command-line arguments. "
176 "At runtime, the setmapping command should be used instead.",
182 "in the GUI, which can be used to peek at serial communications not "
183 "directed to the console. Can be turned off at start time (e.g., in the "
184 "global JeVois params.cfg) as there is some small CPU cost to it.",
190 "or 'stdio' to use the console, or empty for no hardware serial port",
207 "buffer memory. This can accelerate severalfolds access to the captured image data, but "
208 "it may also yield stripe artifacts with some modules, such as PassThrough. The stripes "
209 "are pieces of incorrect data in the cache. You should experiment with each particular "
210 "module. Turbo mode is not recommended for any production-grade application.",
218 SerPort::None, SerPort_Values, ParamCateg);
222 "in the video stream. Only takes effect if streaming video to USB.",
227 SerPort::None, SerPort_Values, ParamCateg);
237 , CPUmode::Performance, CPUmode_Values, ParamCateg);
242 CPUmode::Performance, CPUmode_Values, ParamCateg);
248 ". To enable overclock frequencies above 2208 MHz, you need to first edit "
249 "/boot/env.txt and change max_freq_a73, then reboot. Use with caution!"
253 , 1344, { 120, 240, 312, 408, 480, 504, 600, 648, 720, 816, 912, 1008,
254 1044, 1056, 1080, 1104, 1116, 1152, 1200, 1224, 1248, 1296, 1344 },
258 , 2208, { 500, 667, 1000, 1200, 1398, 1512, 1608, 1704, 1800, 1908, 2016,
259 2100, 2208, 2304, 2400 },
268 "To enable overclock frequencies above 1800 MHz, you need to first edit "
269 "/boot/env.txt and change max_freq_a53, then reboot. Use with caution!",
271 1800, { 500, 667, 1000, 1200, 1398, 1512, 1608, 1704, 1800, 1908, 2016,
278 "reduces the amount of USB bandwidth used by each JeVois camera, from 3kb "
279 "per USB isochronous microframe to 1kb. All 3 JeVois cameras must have this "
280 "option enabled, and the JeVois linux kernel module should also have "
281 "been loaded with multicam on.",
286 "received at the command-line interface. Recommended for advanced users only.",
291 "attempting to load a python module will throw an exception. Disabling python saves "
292 "a lot of memory and may be useful when using C++ modules that run large deep neural "
298 "using sendSerial(), for each video frame, or 0 for no limit. Any message sent by "
299 "the module beyond the first serlimit ones will be dropped. This is useful to avoid "
300 "overloading the serial link, for example in case one is running a ArUco detector and "
301 "a large number of ArUco tags are present in the field of view of JeVois.",
311 "interference, only effective on JeVois-Pro Platform, otherwise ignored. Set conslock "
312 "to false if you are experiencing hard crashes and want to run jevoispro-daemon in gdb.",
317 "is stuck somehow, or 0.0 for no watchdog",
322 "machine vision modules, cycling to the next modules after a number "
323 "of seconds specified by this parameter (or 0.0 for no demo mode).",
403 public Parameter<engine::cameradev, engine::camerasens, engine::cameralens, engine::cameranbuf,
404 engine::gadgetdev, engine::gadgetnbuf, engine::imudev, engine::videomapping,
405 engine::serialdev, engine::usbserialdev, engine::camreg, engine::imureg,
406 engine::camturbo, engine::serlog, engine::videoerrors, engine::serout,
407 engine::cpumode, engine::cpumax, engine::multicam, engine::quietcmd,
408 engine::python, engine::serlimit
410 , engine::serialmonitors, engine::gui, engine::conslock, engine::cpumaxl,
411 engine::cpumodel, engine::watchdog, engine::demomode
417 Engine(std::string
const & instance);
420 Engine(
int argc,
char const* argv[], std::string
const & instance);
435 float oframespersec)
const;
449 size_t getVideoMappingIdx(
unsigned int iformat,
unsigned int iframe,
unsigned int interval)
const;
501 void sendSerial(std::string
const & str,
bool islog =
false);
504 std::shared_ptr<Module>
module()
const;
507 std::shared_ptr<IMU> imu()
const;
510 std::shared_ptr<Camera>
camera()
const;
565 void runScriptFromFile(std::string
const & filename, std::shared_ptr<UserInterface> ser,
569 void onParamChange(engine::serialdev
const & param, std::string
const & newval)
override;
572 void onParamChange(engine::usbserialdev
const & param, std::string
const & newval)
override;
575 void onParamChange(engine::cpumode
const & param, engine::CPUmode
const & newval)
override;
578 void onParamChange(engine::cpumax
const & param,
unsigned int const & newval)
override;
581 void onParamChange(engine::videoerrors
const & param,
bool const & newval)
override;
585 void onParamChange(engine::gui
const & param,
bool const & newval)
override;
588 void onParamChange(engine::cpumaxl
const & param,
unsigned int const & newval)
override;
591 void onParamChange(engine::cpumodel
const & param, engine::CPUmode
const & newval)
override;
594 void onParamChange(engine::demomode
const & param,
float const & newval)
override;
621 bool parseCommand(std::string
const & str, std::shared_ptr<UserInterface> s, std::string
const & pfx =
"");
624 std::list<std::shared_ptr<UserInterface> > itsSerials;
626 void setFormatInternal(
size_t idx);
630 void foreachCamCtrl(std::function<
void(
struct v4l2_queryctrl & qc, std::set<int> & doneids)> && func);
633 std::string camCtrlHelp(
struct v4l2_queryctrl & qc, std::set<int> & doneids);
636 std::string camCtrlInfo(
struct v4l2_queryctrl & qc, std::set<int> & doneids);
639 void cmdInfo(std::shared_ptr<UserInterface> s,
bool showAll, std::string
const & pfx =
"");
642 void modCmdInfo(std::shared_ptr<UserInterface> s, std::string
const & pfx =
"");
645 std::string camctrlname(
unsigned int id,
char const * longname)
const;
648 unsigned int camctrlid(std::string
const & shortname);
653 void reportErrorInternal(std::string
const & err =
"");
657 bool itsManualStreamon;
658 std::atomic<bool> itsVideoErrors;
660 std::string itsModuleConstructionError;
662#ifdef JEVOIS_PLATFORM_A33
664 void checkMassStorage();
665 std::future<void> itsCheckMassStorageFut;
666 std::atomic<bool> itsCheckingMassStorage;
667 std::atomic<bool> itsMassStorageMode;
668 void startMassStorageMode();
669 void stopMassStorageMode();
672 std::atomic<size_t> itsNumSerialSent;
673 std::atomic<int> itsRequestedFormat;
676 std::shared_ptr<GUIhelper> itsGUIhelper;
679 void camCtrlGUI(
struct v4l2_queryctrl & qc, std::set<int> & doneids);
681 std::shared_ptr<jevois::Watchdog> itsWatchdog;
683 bool itsDemoReset =
true;
690 std::vector<std::pair<std::string , std::string >> params;
692 std::vector<DemoData> itsDemoData;
693 bool itsNextDemoRequested =
false;
699 std::map<void *, Component *> itsPythonRegistry;
700 mutable std::mutex itsPyRegMtx;
#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.
JEVOIS_DECLARE_PARAMETER(cameralens, CameraLens, "Camera lens. Users should usually not set this parameter " "using the global JeVois params.cfg config file.", CameraLens::standard, CameraLens_Values, ParamCateg)
Parameter.
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 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,...
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.