Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DSLR Camera Control #5

Open
acbuynak opened this issue Mar 17, 2021 · 8 comments
Open

Add DSLR Camera Control #5

acbuynak opened this issue Mar 17, 2021 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@acbuynak
Copy link
Member

@tijaci Demonstrated ability to control a DSLR camera via command line.

2021_03_16
I’ve taken a picture and downloaded it to my computer using the terminal.

Creating this issue to track the creation a control script and addition of this ability to the repo.

@acbuynak acbuynak added the enhancement New feature or request label Mar 17, 2021
@acbuynak
Copy link
Member Author

Info from @tijaci. Copied from external discussion for archive here.

I got it to work in two ways using Python. There is a gphoto2 module already written that is downloadable. The only thing is that it is very opaque to me in how it works. Either because the documentation/examples are limited or there is some implied knowledge I don't have. There are some functions and example programs that work but don't do what I want--so I should be able to write my own from that module once I figure out how that works. This might be something I hit you or Andrew up later if I can't figure it out.

The other method is just using subprocess calls to the command line. This seems pretty janky to me and probably not a good idea, but that's just a guess on my part being new to Linux.

@acbuynak
Copy link
Member Author

Quick thoughts..

The other method is just using subprocess calls to the command line. This seems pretty janky to me and probably not a good idea, but that's just a guess on my part being new to Linux.

This doesn't sound too bad to me. I agree that a direct gphoto2 module may be best suited for our project needs, but if it's complicated enough for the month remaining in this project... then let's go with subprocess calls.

I'm personally cool with subprocess calls if they are low CPU usage and execute quickly. If really necessary we could just use athreading package to push it onto it's own thread.

@acbuynak
Copy link
Member Author

Big Picture wise, I'm imagining that if we can have a class that set's up the setting's like...

camera = CameraClass( settings )

And then in the code we use a single API call that we input a name for the to-be-saved photo and it returns the absolute file path of the saved photo. like this..

new_photo_filepath = camera.take_single_photo( )

I think that's all we need for an MVP.

acbuynak added a commit that referenced this issue Mar 22, 2021
@acbuynak
Copy link
Member Author

@Schellenberg3 & I reviewed the camera.py control code and just wanted to ask for a few changes.

def capture_photo(): #capture photo and download
# Use a breakpoint in the code line below to debug your script.
os.chdir(photo_directory)
#subprocess.call([gphoto2, process_call])
#subprocess_cmd("gphoto2 --filename %H.%M.%S --capture-image-and-download --force-overwrite")
subprocess_cmd(process_call)
#call("lsusb")

1 - As included in the main function, this looks like the API we would want to import and call in the main motion loop. I think we'll just need input variables added. Can you include the below:

  • workspace directory
  • output filename (id) (without the extensions)

2 - I'd also like to document here the file naming structure if we can start that discussion as well.

Side Note,
A long term goal is to record the location, pose, filename, etc for each photo taken. So that's why we want log that information.

@tijaci
Copy link
Contributor

tijaci commented Apr 4, 2021

@acbuynak is this the sort of change you're looking for?


    def __init__(self, filename, directory):
        self.filename = filename
        file_name = " --filename " + filename  # make sure this doesn't repeat names
        gphoto2 = "gphoto2"
        self.directory = directory  # directory photos are downloaded to
        file_name = " --filename " + filename  # make sure this doesn't repeat names
        capture = " --capture-image-and-download"
        overwrite = " --force-overwrite"
        process_call = gphoto2 + file_name + capture + overwrite  # can remove overwrite if file_name is iterative "%n"

        def subprocess_cmd(command):  # allows multiple commands at once
            process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
            proc_stdout = process.communicate()[0].strip()
    
        def capture_photo():  # capture photo and download
            # Use a breakpoint in the code line below to debug your script.
            os.chdir(directory)
            # subprocess.call([gphoto2, process_call])
            # subprocess_cmd("gphoto2 --filename %H.%M.%S --capture-image-and-download --force-overwrite")
            subprocess_cmd(process_call)
            # call("lsusb")
            return directory

@acbuynak
Copy link
Member Author

acbuynak commented Apr 7, 2021

I think this looks good. @Schellenberg3 and I will test it tomorrow in the lab.

Thanks!

@acbuynak
Copy link
Member Author

acbuynak commented Apr 7, 2021

@tijaci Can you write up some instructions on what base libraries and package(s) we need to install on linux to run this?

@acbuynak
Copy link
Member Author

@Schellenberg3 was able to get the commands working via terminal so we know the connection should work now. We just need to purchase a cable long enough for the robot.

@tijaci Can you implement the proposed code above into a PR? Or directly into code, either way works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants