moof-src / ArduCamFocus

repository for ArduCamFocus octoprint plugin. Control an ArduCam focus from octoprint on an octopi.
16 stars 6 forks source link

can't set focus while the stream is active #7

Open EstimatedProphet opened 3 years ago

EstimatedProphet commented 3 years ago

For some reason I can't set the focus while the camera is streaming. Not with your plugin and not with the sample scripts from ArduCam. If I stop the webcamd service I can control the focus.

Here's the error I'm seeing in the octoprint log:

2020-12-29 08:11:29,924 - octoprint.plugins.ArduCamFocus - INFO - setting FOCUS to 110
2020-12-29 08:11:29,925 - octoprint.util.comm - ERROR - Error while processing hook ArduCamFocus for phase queuing and command ARDUCAMFOCUS:
Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/comm.py", line 4605, in _process_atcommand_phase
    hook(self, phase, atcommand, parameters, tags=tags)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/__init__.py", line 1890, in wrapper
    return f(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/__init__.py", line 98, in processAtCommand
    self.focus(self.current_focus + int(parameters))
  File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/__init__.py", line 85, in focus
    self.bus.write_byte_data(0xc, data1, data2)
OSError: [Errno 121] Remote I/O error

And here's the error I'm getting from Motorized_Focus_Camera_Preview.py:

mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates
moof-src commented 3 years ago

ENOSPC means you are out of disk space. maybe /tmp is full?

On Tue, Dec 29, 2020 at 4:09 AM EstimatedProphet notifications@github.com wrote:

For some reason I can't set the focus while the camera is streaming. Not with your plugin and not with the sample scripts from ArduCam. If I stop the webcamd service I can control the focus.

Here's the error I'm seeing in the octoprint log:

2020-12-29 08:11:29,924 - octoprint.plugins.ArduCamFocus - INFO - setting FOCUS to 110 2020-12-29 08:11:29,925 - octoprint.util.comm - ERROR - Error while processing hook ArduCamFocus for phase queuing and command ARDUCAMFOCUS: Traceback (most recent call last): File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/comm.py", line 4605, in _process_atcommand_phase hook(self, phase, atcommand, parameters, tags=tags) File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/init.py", line 1890, in wrapper return f(*args, **kwargs) File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/init.py", line 98, in processAtCommand self.focus(self.current_focus + int(parameters)) File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/init.py", line 85, in focus self.bus.write_byte_data(0xc, data1, data2) OSError: [Errno 121] Remote I/O error

And here's the error I'm getting from Motorized_Focus_Camera_Preview.py:

mmal: mmal_vc_component_enable: failed to enable component: ENOSPC mmal: camera component couldn't be enabled mmal: main: Failed to create camera component mmal: Failed to run camera app. Please check for firmware updates

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/moof-src/ArduCamFocus/issues/7, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUA23LLNNTTX6XV4YW7SHLSXGME5ANCNFSM4VM7P4YA .

EstimatedProphet commented 3 years ago

Nope, I'm fine on space and everything works when the camera isn't streaming. I've verified that there's only one process using the camera and I increased max number of file watches because I read hitting the limit can be a cause of this error, but that didn't help. I realize this isn't a problem with your plugin so I don't want to waste your time with this, I just thought you might have an answer. I'll contact ArduCam.

pi@octopi:~/RaspberryPi/Motorized_Focus_Camera/python $ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root        7462444 4810452   2308616  68% /
devtmpfs         1793064       0   1793064   0% /dev
tmpfs            1925160       0   1925160   0% /dev/shm
tmpfs            1925160   16828   1908332   1% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs            1925160       0   1925160   0% /sys/fs/cgroup
/dev/mmcblk0p1    258095   48607    209488  19% /boot
tmpfs             385032       0    385032   0% /run/user/1000

pi@octopi:~/RaspberryPi/Motorized_Focus_Camera/python $ sudo lsof | grep video
mjpg_stre 455                           root  mem       CHR       81,7                 404 /dev/video0
mjpg_stre 455                           root    4u      CHR       81,7      0t0        404 /dev/video0
mjpg_stre 455 485 mjpg_stre             root  mem       CHR       81,7                 404 /dev/video0
mjpg_stre 455 485 mjpg_stre             root    4u      CHR       81,7      0t0        404 /dev/video0
mjpg_stre 455 486 mjpg_stre             root  mem       CHR       81,7                 404 /dev/video0
mjpg_stre 455 486 mjpg_stre             root    4u      CHR       81,7      0t0        404 /dev/video0
moof-src commented 3 years ago

I have not seen nor can I reproduce your problem. I tried google as you must have. Although their problem was different, I have seen multiple posts like this one:

https://raspberrypi.stackexchange.com/questions/89021/how-to-fix-remote-i-o-error-whilst-using-i2c-oled

However, if that were the case, i would expect an intermittent success and not a repeatable problem.

Is it possible you have multiple I2C devices with the same address?

Have you reinstalled the i2c libraries?

I wish I had an answer for you.

emilyboda commented 3 years ago

I'm having the same problem. I was able to get the demos from Arducam working by doing: sudo service webcamd stop

But then, of course, the webcam's stream in octoprint also stops working and I can't see whether it's focused or not. Arducam used to have a demo program that would save snapshots to the directory which would be helpful, but it has been removed from their github.

I'm getting the exact same error:

2021-03-30 15:45:27,075 - octoprint.plugins.ArduCamFocus - INFO - setting FOCUS to 110
2021-03-30 15:45:27,076 - octoprint.util.comm - ERROR - Error while processing hook ArduCamFocus for phase queuing and command ARDUCAMFOCUS:
Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/comm.py", line 4605, in _process_atcommand_phase
    hook(self, phase, atcommand, parameters, tags=tags)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/__init__.py", line 1890, in wrapper
    return f(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/__init__.py", line 98, in processAtCommand
    self.focus(self.current_focus + int(parameters))
  File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/__init__.py", line 85, in focus
    self.bus.write_byte_data(0xc, data1, data2)
OSError: [Errno 121] Remote I/O error

Edit: I didn't change anything, but waited ten minutes while I googled things, and now it appears to be working. Very strange.

moof-src commented 3 years ago

emilyboda: please provide more information. Each person on this thread had a different error, or didn't reply after I commented. So, please reread this thread and see if you can find the answer. If things still aren't working, please send me more information to help me track down the problem you are experiencing. Thanks.

On Tue, Mar 30, 2021 at 3:43 PM emilyboda @.***> wrote:

I'm having the same problem. I was able to get the demos from Arducam working by doing: sudo service webcamd stop

But then, of course, the webcam's stream in octoprint also stops working and I can't see whether it's focused or not. Arducam used to have a demo program that would save snapshots to the directory which would be helpful, but it has been removed from their github.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/moof-src/ArduCamFocus/issues/7#issuecomment-810529550, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUA23OGWJUYQXC772A2YADTGISWRANCNFSM4VM7P4YA .

emilyboda commented 3 years ago

It started working after about a half hour. Perhaps it doesn't work at first and only after a few reboots?

moof-src commented 3 years ago

I’m glad it’s working for you. There is nothing timing sensitive. After following the octoprint ArduCamFocus plugin install instructions, a single reboot is required.

emilyboda commented 3 years ago

Hey moof, today it doesn't seem to be working anymore! Currently the Arducam focus plugin is set to "310" but the camera has gone back to the factory focus and when I try to change the focus I get the same error as yesterday in the logs:

2021-03-31 11:24:45,714 - octoprint.plugins.ArduCamFocus - INFO - setting FOCUS to 320
2021-03-31 11:24:45,715 - octoprint.util.comm - ERROR - Error while processing hook ArduCamFocus for phase queuing and command ARDUCAMFOCUS:
Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/comm.py", line 4605, in _process_atcommand_phase
    hook(self, phase, atcommand, parameters, tags=tags)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/__init__.py", line 1890, in wrapper
    return f(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/__init__.py", line 98, in processAtCommand
    self.focus(self.current_focus + int(parameters))
  File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/__init__.py", line 85, in focus
    self.bus.write_byte_data(0xc, data1, data2)
OSError: [Errno 121] Remote I/O error

As I mentioned above, I have a similar error when trying to use Arducam's stock demo. I'm unable to use raspistill until I turn off the webcamd service. But when I turn off the webcamd service, I can't see the webcam anymore to see if there's a focus.

You mentioned above it might be a hardware error, but I don't think that could be the case, since it works sometimes and doesn't work other times without me touching it. I've also use two different cables and gotten this issue across both of them, and I've tried both of the ports on the Pi.

I looked at the above thread and tried to check everything you mentioned. /tmp is not full:

pi@octopi:~ $ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root       61109100 3404424  55185196   6% /
devtmpfs          413524       0    413524   0% /dev
tmpfs             446804       4    446800   1% /dev/shm
tmpfs             446804    6008    440796   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             446804       0    446804   0% /sys/fs/cgroup
/dev/mmcblk0p1    258095   48789    209306  19% /boot
tmpfs              89360       0     89360   0% /run/user/1000

How can I go about reinstalling the i2c library? How do I check to see if there are multiple i2c devices at one address? The only things plugged into my pi are the camera and the printer.

emilyboda commented 3 years ago

As an update: I started running a print and now I'm able to focus the camera. This is very strange.

emilyboda commented 3 years ago

The only thing that I can think might be an issue is that I have the muticamera plug in running. Ordinarily my default camera is set to an external IP camera and my secondary camera is the arducam. However, the arducam is the one that is connected to the Pi, so I don't think that should be an issue.

I have noticed that focusing works when I set my default camera to be the arducam and doesn't work when I set my default camera to be the external IP camera. However, when I make that switch the focusing doesn't work immediately and it doesn't always work at all, so I don't know if that's the problem.

emilyboda commented 3 years ago

Here's my full log, starting from the last time I tried to focus and got the error to now when it suddenly starts working:

2021-03-31 12:48:52,574 - octoprint.plugins.ArduCamFocus - INFO - setting FOCUS to 320
2021-03-31 12:48:52,577 - octoprint.util.comm - ERROR - Error while processing hook ArduCamFocus for phase queuing and command ARDUCAMFOCUS:
Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/comm.py", line 4605, in _process_atcommand_phase
    hook(self, phase, atcommand, parameters, tags=tags)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/__init__.py", line 1890, in wrapper
    return f(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/__init__.py", line 98, in processAtCommand
    self.focus(self.current_focus + int(parameters))
  File "/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/__init__.py", line 85, in focus
    self.bus.write_byte_data(0xc, data1, data2)
OSError: [Errno 121] Remote I/O error
2021-03-31 12:49:08,932 - octoprint.util.comm - INFO - Starting job on behalf of user eboda
2021-03-31 12:49:08,937 - octoprint.util.comm - INFO - Changing monitoring state from "Operational" to "Starting"
2021-03-31 12:49:08,957 - octoprint.printer.standard.job - INFO - Print job started - origin: local, path: flower_pot_8h43.gcode, owner: eboda, user: eboda
2021-03-31 12:49:09,063 - octoprint.util.comm - INFO - M110 detected, setting current line number to 0
2021-03-31 12:49:09,067 - octoprint.plugins.DisplayLayerProgress - INFO - Printing started. Detailed progress started.{'name': 'flower_pot_8h43.gcode', 'path': 'flower_pot_8h43.gcode', 'origin': 'local', 'size': 5223222, 'owner': 'eboda', 'user': 'eboda'}
2021-03-31 12:49:09,083 - octoprint.plugins.PrintJobHistory - INFO - Try reading Temperature from PreHeat-Plugin...
2021-03-31 12:49:09,084 - octoprint.util.comm - INFO - Changing monitoring state from "Starting" to "Printing"
2021-03-31 12:49:09,114 - octoprint.plugins.PrintJobHistory - INFO - ... Temperature found '60.0' ' Tool 'tool0' '200.0'
2021-03-31 12:49:09,117 - octoprint.plugins.TpLinkAutoShutdown - INFO - True
2021-03-31 12:49:09,117 - octoprint.plugins.TpLinkAutoShutdown - INFO - Print has been started
2021-03-31 12:49:11,159 - octoprint.util.comm - INFO - Printer seems to support the busy protocol, will adjust timeouts and set busy interval accordingly
2021-03-31 12:49:11,523 - octoprint.util.comm - INFO - Cancelling job on behalf of user eboda
2021-03-31 12:49:11,528 - octoprint.util.comm - INFO - Changing monitoring state from "Printing" to "Cancelling"
2021-03-31 12:49:11,585 - octoprint.printer.standard.job - INFO - Print job cancelled - origin: local, path: flower_pot_8h43.gcode, owner: eboda, user: eboda
2021-03-31 12:49:11,613 - octoprint.plugins.DisplayLayerProgress - INFO - Printing stopped. Detailed progress stopped.
2021-03-31 12:49:11,627 - octoprint.plugins.PrintJobHistory - INFO - Print result:canceled, CaptureMode:successful
2021-03-31 12:49:11,631 - octoprint.plugins.PrintJobHistory - INFO - PrintJob not captured, because not activated!
2021-03-31 12:49:11,634 - octoprint.plugins.filamentmanager - INFO - Updating Filament usage for octoprint configured toolcount: 1
2021-03-31 12:49:11,634 - octoprint.plugins.filamentmanager - INFO - Filament tracked toolcount: 1
2021-03-31 12:49:11,634 - octoprint.plugins.filamentmanager - INFO - Filament tracked values: [0.0]
2021-03-31 12:49:11,635 - octoprint.plugins.filamentmanager - INFO - Filament used: 0.0 mm (tool0)
2021-03-31 12:49:11,723 - octoprint.plugins.filamentmanager - INFO - Updated remaining filament on spool 'Rainbow 1 - PLA (Sunlu)' from 992.0705765736034g to 992.0705765736034g (0.0g)
2021-03-31 12:49:11,960 - octoprint.plugins.DisplayLayerProgress - INFO - Printing stopped. Detailed progress stopped.
2021-03-31 12:49:37,618 - octoprint.server.util.sockjs - INFO - New connection from client: ::ffff:192.168.1.168
2021-03-31 12:49:37,698 - octoprint.server.util.flask - INFO - Passively logging in user eboda from ::ffff:192.168.1.168
2021-03-31 12:49:37,699 - octoprint.access.users - INFO - Logged in user: eboda
2021-03-31 12:49:40,484 - octoprint.server.util.flask - INFO - Passively logging in user eboda from ::ffff:192.168.1.168
2021-03-31 12:49:40,485 - octoprint.access.users - INFO - Logged in user: eboda
2021-03-31 12:49:41,209 - octoprint.server.util.sockjs - INFO - User eboda logged in on the socket from client ::ffff:192.168.1.168
2021-03-31 12:49:43,368 - octoprint.server.util.sockjs - INFO - Client connection closed: ::ffff:192.168.1.168
2021-03-31 12:49:44,485 - octoprint.server.util.flask - INFO - Passively logging in user eboda from ::ffff:192.168.1.168
2021-03-31 12:49:44,486 - octoprint.access.users - INFO - Logged in user: eboda
2021-03-31 12:49:50,961 - octoprint.server.util.sockjs - INFO - New connection from client: ::ffff:192.168.1.168
2021-03-31 12:49:51,056 - octoprint.server.util.flask - INFO - Passively logging in user eboda from ::ffff:192.168.1.168
2021-03-31 12:49:51,057 - octoprint.access.users - INFO - Logged in user: eboda
2021-03-31 12:50:05,240 - octoprint.server.util.sockjs - INFO - User eboda logged in on the socket from client ::ffff:192.168.1.168
2021-03-31 12:51:36,278 - octoprint.util.comm - INFO - Telling the printer to set the busy interval to our "communicationBusy" timeout - 1s = 2s
2021-03-31 12:51:36,286 - octoprint.plugins.ArduCamFocus - INFO - setting FOCUS to 320
2021-03-31 12:51:36,606 - octoprint.plugins.ArduCamFocus - INFO - setting FOCUS to 310
2021-03-31 12:51:36,889 - octoprint.plugins.ArduCamFocus - INFO - setting FOCUS to 320
2021-03-31 12:51:37,206 - octoprint.util.comm - INFO - Changing monitoring state from "Cancelling" to "Operational"
2021-03-31 12:51:39,486 - octoprint.server.util.sockjs - INFO - New connection from client: ::ffff:192.168.1.251
2021-03-31 12:51:39,667 - octoprint.server.util.flask - INFO - Passively logging in user eboda from ::ffff:192.168.1.251
2021-03-31 12:51:39,668 - octoprint.access.users - INFO - Logged in user: eboda
2021-03-31 12:51:39,770 - octoprint.server.util.sockjs - INFO - User eboda logged in on the socket from client ::ffff:192.168.1.251
moof-src commented 3 years ago

please tell me version numbers and hardware you are using too, if you can. example

OctoPrint version : 1.5.3 OctoPi version : 0.17.0

and a copy of /boot/octopi.txt and a copy of /boot/config.txt

emilyboda commented 3 years ago

octoprint.version: 1.5.3 env.plugins.pi_support.model: Raspberry Pi 3 Model B Plus Rev 1.3 env.plugins.pi_support.octopi_version: 0.18.0

I am using this Arducam and a Pi 3 B+.

More notes on my configuration:

config.txt

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]
#dtoverlay=vc4-fkms-v3d
# enable raspicam
start_x=1
gpu_mem=128
dtparam=i2c_vc=on

octopi.txt

### Windows users: To edit this file use Notepad++, VSCode, Atom or SublimeText.
### Do not use Notepad or WordPad.

### MacOSX users: If you use Textedit to edit this file make sure to use 
### "plain text format" and "disable smart quotes" in "Textedit > Preferences"

### Configure which camera to use
#
# Available options are:
# - auto: tries first usb webcam, if that's not available tries raspi cam
# - usb: only tries usb webcam
# - raspi: only tries raspi cam
#
# Defaults to auto
#
#camera="auto"

### Additional options to supply to MJPG Streamer for the USB camera
#
# See https://faq.octoprint.org/mjpg-streamer-config for available options
#
# Defaults to a resolution of 640x480 px and a framerate of 10 fps
#
#camera_usb_options="-r 640x480 -f 10"

### Additional webcam devices known to cause problems with -f
#
# Apparently there a some devices out there that with the current 
# mjpg_streamer release do not support the -f parameter (for specifying 
# the capturing framerate) and will just refuse to output an image if it 
# is supplied.
#
# The webcam daemon will detect those devices by their USB Vendor and Product
# ID and remove the -f parameter from the options provided to mjpg_streamer.
#
# By default, this is done for the following devices:
#   Logitech C170 (046d:082b)
#   GEMBIRD (1908:2310)
#   Genius F100 (0458:708c)
#   Cubeternet GL-UPC822 UVC WebCam (1e4e:0102)
#
# Using the following option it is possible to add additional devices. If
# your webcam happens to show above symptoms, try determining your cam's
# vendor and product id via lsusb, activating the line below by removing # and 
# adding it, e.g. for two broken cameras "aabb:ccdd" and "aabb:eeff"
#
#   additional_brokenfps_usb_devices=("aabb:ccdd" "aabb:eeff")
#
# If this fixes your problem, please report it back so we can include the device
# out of the box: https://github.com/guysoft/OctoPi/issues
#
#additional_brokenfps_usb_devices=()

### Additional options to supply to MJPG Streamer for the RasPi Cam
#
# See https://faq.octoprint.org/mjpg-streamer-config for available options.
#
# NOTE: Newer raspi cam modules are reporting as usb devices causing these
#       options to be ignored. Set `camera="raspi"` to avoid these issues.
#
# Defaults to 10fps
#
#camera_raspi_options="-fps 10"

### Configuration of camera HTTP output
#
# Usually you should NOT need to change this at all! Only touch if you
# know what you are doing and what the parameters mean.
#
# Below settings are used in the mjpg-streamer call like this:
#
#   -o "output_http.so -w $camera_http_webroot $camera_http_options"
#
# Current working directory is the mjpg-streamer base directory.
#
#camera_http_webroot="./www-octopi"
#camera_http_options="-n"

### EXPERIMENTAL
# Support for different streamer types.
#
# Available options:
#   mjpeg [default] - stable MJPG-streamer
#   hls - experimental FFMPEG HLS streamer
#camera_streamer=mjpeg
moof-src commented 3 years ago

please try the new 0.0.6 release and see if that fixes your problem.