Using USB remote to control chdkptp with Raspberry Pi - page 6 - Hello, I'm a NEWBIE - HELP!! (Newbies assistance, User Guides and thank you notes) - CHDK Forum supplierdeeply

Using USB remote to control chdkptp with Raspberry Pi

  • 68 Replies
  • 33979 Views
*

Offline reyalp

  • ******
  • 14117
Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #50 on: 17 / April / 2017, 13:39:56 »
Advertisements
I have tried adding the complete path pipe to /etc/rc.local file and nothing is working!
"nothing is working" isn't very descriptive. Do you see the programs running with ps? Have you tried logging anything to files?

A guess: To get input, your python script needs to be running in the console terminal. Normally, rc scripts run without a terminal.

This thread might be helpful
https://ubuntuforums.org/showthread.php?t=1602381

see also getty https://en.wikipedia.org/wiki/Getty_(Unix)

An alternative would be for your python script to read raw input from the keyboard device without having a terminal, e.g. http://stackoverflow.com/questions/37134686/how-can-i-get-raw-usb-keyboard-data-with-python
Don't forget what the H stands for.

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #51 on: 17 / April / 2017, 13:58:15 »
"nothing is working" isn't very descriptive. Do you see the programs running with ps? Have you tried logging anything to files?

A guess: To get input, your python script needs to be running in the console terminal. Normally, rc scripts run without a terminal.

Sorry, when I say nothing is working, I simply mean that I am attempting to put the same line of code into the rc.local file that I enter when I open the command prompt to start my python program piped into chdkptp, and when I reboot the Pi, nothing is happening. No errors, no anything. If that makes sense. Probably not... But your guess of the python program needing to be run in the terminal seems accurate.

Basically what I need to do is find out a way for the raspberry pi to boot with the terminal open and have my piece of code execute on start up. So it makes sense that nothing happens when I add that command to rc.local if they don't run in a terminal...

Sorry if I am making no sense, I guess I figured it would be relatively simple to mimic me opening the command prompt and having the Pi enter "cd chdkptp-r735 && ./remote_function.py|./chdkptp.sh" right on start up

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #52 on: 17 / April / 2017, 14:15:26 »
AH!

Nevermind. Please ignore my last post. I figured it out:

https://www.raspberrypi.org/forums/viewtopic.php?t=66206&p=485866

I tried this a couple days ago, but figured out that the reason it didn't work when I originally tested it was because of a spelling error. Of course. Taught me to triple check spelling...

So basically I'm having lxterminal open on start up with the command I want it to type, and it now works on start up!

Sorry for the confusion.

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #53 on: 18 / April / 2017, 11:17:10 »
Okay, so even though I figured out how to start this remotely, I am sometimes coming up with an error...

So I created a way to boot up lxterm (just a terminal that doesn't put a lot of strain on the Pi) and start up with the command I want to execute in this folder:

Code: [Select]
~/.config/autostart/lxterm-autostart.desktop
And then I used the text editor to add this:

Code: [Select]
[Desktop Entry]
Encoding=UTF-8
Name=Terminal autostart
Comment=Start a terminal and boot remote_function.py piped into chdkptp.sh
Exec=/usr/bin/lxterm -e 'cd chdkptp-r735 && ./remote_function.py|./chdkptp.sh'

And this works great, but sometimes when I boot up and try to connect to the camera, it will take around 5 seconds to connect. But sometimes it'll connect right away. (And to connect, by the way, my Python program is looking for button presses from my remote and if the "close" button on my remote is pressed, then I send the chdkptp.sh terminal the 'c' character followed by the 'rec' characters to connect and put into recording mode right away)

When I look at the desktop to the Pi, I see the terminal gives me this error:



But even though it prints these errors, the camera will still connect. And you can also see me playing with the zoom too. Which was strange because my camera was zooming in and out with the press of a button even though the terminal is saying the camera is not connected...

Anyways, if you look at attached my remote_function program you'll see that I am using the GPIO to use LEDs with my program to show someone from a distance the zoom level, and then to have a light on when the camera is recording. Also, at the beginning of the program, I have one LED turn on, and then turn back off after half a second to visualize when the program is up and running and ready for the camera to connect.

My first question is this: When I boot up my Pi, the light will flash 3 times even though I only set it up to flash once when turning on... any speculation as to why the program is starting three times?

My second question is this: What are the errors in the chdkptp terminal and how can I go about getting the camera to connect more smoothly?

This is more of a troubleshooting question... things are working, but I am trying to get them to work more quickly.


*

Offline reyalp

  • ******
  • 14117
Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #54 on: 18 / April / 2017, 12:54:36 »
When I look at the desktop to the Pi, I see the terminal gives me this error:


The error means that something already has the camera open, either chdkptp or another photo app.
Quote
But even though it prints these errors, the camera will still connect. And you can also see me playing with the zoom too. Which was strange because my camera was zooming in and out with the press of a button even though the terminal is saying the camera is not connected...
This suggests to me that more than one copy of your startup entry are being started. That seems consistent with the LEDs blinking more than you expect as well.

FWIW, Since you are using X, you could written everything in chdkptp Lua code. You would just need to add some IUP code to catch the key presses. I'm not suggesting you do this now since you already have it working in python, just putting out here for anyone considering a similar project.
Don't forget what the H stands for.

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #55 on: 19 / April / 2017, 11:00:26 »
The error means that something already has the camera open, either chdkptp or another photo app.

Hm, alright... I will have to search around on the Raspberry Pi to see what is opening it. The reason this seems so tricky is because sometimes it connects right away, but other times it doesn't. Time to troubleshoot!

Quote
This suggests to me that more than one copy of your startup entry are being started. That seems consistent with the LEDs blinking more than you expect as well.

FWIW, Since you are using X, you could written everything in chdkptp Lua code. You would just need to add some IUP code to catch the key presses. I'm not suggesting you do this now since you already have it working in python, just putting out here for anyone considering a similar project.

I figured out that when I was attempting to get this started on boot up, I tried a couple different processes, one of which was adding it to the rc.local bash so it was starting up in the background. So simply deleting that from the bash made the LED only flash twice, which means I have it starting up in one other place. Fun.

But yes, I do agree that if someone else wants to make this project, Lua code might be the way to go. The only reason I did this in Python is because that's where I'm more comfortable. I think Lua could open a project like this to more functionality.

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #56 on: 19 / April / 2017, 11:45:01 »
You know what, reyalp... I actually do have a question for you that concerns programming in Lua.

So, for the next part of my project I want to be able to start video recording, but I want to use a separate audio source (an external mic plugged into my Pi for clearer audio). I have my Python program using the subprocess Popen function to send the Pi a command to start recording using the built in ALSA process (if that makes any sense), and I can also kill that process with a press of a button, saving an audio file to my device.

The reason I think Lua might come in handy is because of the get_movie_status command in Lua... I would love to be able to run a loop waiting for the return of that function to become 4 (recording in process), and as soon as it sees that recording is in process, then the audio will start recording. This is simply because I can get the audio recording to start almost automatically, and the video takes about a second to actually start recording.

I guess my question is this: Is there an easy way to do this using my Python program? Or would the simplest way be to use Lua?

A follow up question is this: Is there an easy way for me to find the delay between when I send the "=click('video')/n" command and when the camera actually starts recording to simply find that delay and figure out if it is constant?

*

Offline reyalp

  • ******
  • 14117
Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #57 on: 19 / April / 2017, 16:14:01 »
The reason I think Lua might come in handy is because of the get_movie_status command in Lua... I would love to be able to run a loop waiting for the return of that function to become 4 (recording in process), and as soon as it sees that recording is in process, then the audio will start recording. This is simply because I can get the audio recording to start almost automatically, and the video takes about a second to actually start recording.

I guess my question is this: Is there an easy way to do this using my Python program? Or would the simplest way be to use Lua?
Finding out when video started in chdkptp is easy enough, but with your current setup getting the information back to your python program may be tricky.

To wait for video to start recording, you could use something like
Code: [Select]
click('video') repeat sleep(10) until get_video_status() == 4
(note all code in this post is off the top of my head, untested, may contain typos)

If you wan to start audio recording from within lua, you could use os.execute (http://www.lua.org/manual/5.2/manual.html#6.9) to execute an external command, or io.popen (http://www.lua.org/manual/5.2/manual.html#6.8) to start a program you can send output to later.

Assuming you have some command 'start_audio_recording', you could do it something like this:
Code: [Select]
!con:execwait([[click('video') repeat sleep(10) until get_video_status() == 4]]) os.execute('start_audio_recording')
If you were using the popen method, you'd do some thing like
Code: [Select]
!ph=io.open('some_program','w')
once on startup, and then use ph:write() to send to that programs standard input.

If you want to do it with python, you need a way to communicate back from chdkptp to your python program. You could start chdkptp as a subprocess instead of piping from the shell, but handling both stdin and stdout can be tricky. For a quick and dirty hack, you could just make chdkptp create a file that you can look for with python, e.g.
Code: [Select]
!con:execwait([[click('video') repeat sleep(10) until get_video_status() == 4]]) fh=io.open('video_recording','wb') fh:close()
then check for video_recording existing in your python script, and remove it.

Quote
A follow up question is this: Is there an easy way for me to find the delay between when I send the "=click('video')/n" command and when the camera actually starts recording to simply find that delay and figure out if it is constant?
To return the number of milliseconds it took for get_video_status() to become 4, use something like
Code: [Select]
=t0=get_tick_count() click('video') repeat sleep(10) until get_video_status() == 4 return get_tick_count()-t0
I wouldn't expect to be exactly constant since the camera tries to autofocus before starting and that takes a variable amount of time.  If your camera has dedicated video mode that can start recording with the shutter button, you could probably get a more consistent delay by having the script hold half press for a fixed amount of time and then press play, e.g.

Code: [Select]
press'shoot_half' sleep(500) click'shoot_full'
This gives the camera a fixed half second to focus before starting. I'm not aware of a way to do this on cameras that only let you start with the video button.
Don't forget what the H stands for.


Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #58 on: 19 / April / 2017, 18:07:52 »
To return the number of milliseconds it took for get_video_status() to become 4, use something like
Code: [Select]
=t0=get_tick_count() click('video') repeat sleep(10) until get_video_status() == 4 return get_tick_count()-t0
I wouldn't expect to be exactly constant since the camera tries to autofocus before starting and that takes a variable amount of time.  If your camera has dedicated video mode that can start recording with the shutter button, you could probably get a more consistent delay by having the script hold half press for a fixed amount of time and then press play, e.g.

Code: [Select]
press'shoot_half' sleep(500) click'shoot_full'
This gives the camera a fixed half second to focus before starting. I'm not aware of a way to do this on cameras that only let you start with the video button.

Okay, I definitely want to try this but I have no idea how to execute this piece of Lua code (and I know you said the code is just off the top of your head so you don't know if it'll work, but I have been using the chdkptp CLI this whole time).

I copied what you wrote into a notepad file and saved it as a .lua file called seconds, but to execute that do I need to upload it to the camera?.. I tried doing
Code: [Select]
lua loadfile('seconds.lua')()and I just get an error on my camera.

Sorry... This is definitely a step back from the previous conversation, but since I've already committed to Python (as this project has more pieces than just the camera recording piece) I want to try the route where I test how long it takes to go from "pressing" the video button to when it actually starts recording.

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #59 on: 19 / April / 2017, 21:40:37 »
Okay, so I realized I can execute lua code via the CLI, so I did and this is what I got:



What do I need to fix?

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal