Raspberry Paul
Posts: 86
Joined: Mon Jun 10, 2013 3:40 pm
Contact: Website

Using RPIO PWM and os.subsystem - failing

Fri Feb 21, 2014 4:42 pm

I'm trying to build a pan and tilt camera using 2 servos and a webcam. The servos are attached directly to pins 23 and 24. Raspberry model A, Logitiech webcam, USB wifi.

When I try using RPIO PWM and os.system in the same script, the os.system part runs correctly, but the script basically shuts down after.

If I rem out the servo commands the os.system runs correctly and the script completes

I've tried various ways of running commands within Python but seem to get the same result. Have tried a fresh install of raspbian, also tried a model B.

Any thoughts?

Code: Select all

#!/usr/bin/env python
import time
import os
import ftplib

from RPIO import PWM

servo = PWM.Servo()

intPan = 600
intTilt = 1300
strPicName = "webcam"

strTempFilename = "/home/pi/" + strPicName + "Temp.jpg"
strFilename = "/home/pi/" + strPicName + ".jpg"

#print("############################## Pan and Tilt")
#servo.set_servo(23, intTilt)
#servo.set_servo(24, intPan)

time.sleep( 2 )

print("############################## Taking Photo")

os.system("fswebcam -d /dev/video0 -r 384x288 " + strFilename)
print("Finished")

 
print("############################## resetting")

servo.stop_servo(23)
servo.stop_servo(24)
With Servo lines

Code: Select all

  --- Processing captured image...                                                                                                                                                                                                       
Writing JPEG image to '/home/pi/webcam.jpg'.                                                                                                                                                                                           
shutting down dma channel 0                                                                                                                                                                                                            
clear_channel: channel=0 
 
With servo lines removed:-

Code: Select all

--- Processing captured image...                                                                                                                                                                                                       
Writing JPEG image to '/home/pi/webcam.jpg'.                                                                                                                                                                                           
Finished                                                                                                                                                                                                                               
############################## resetting  
I've tried using a Raspberry Pi cam and raspistill but same issue. Managed to get the native Python Camera module working with the PWM code but want to use webcam.
http://www.raspberrypaul.co.uk

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Using RPIO PWM and os.subsystem - failing

Sat Feb 22, 2014 12:00 am

Do you need to create 2 separate 'servo' objects, one for each channel?

Code: Select all

pi@raspberrypi ~/paul $ sudo python paul.py
Using hardware: PWM
PW increments:  10us
############################## Pan and Tilt
Initializing channel 0...
add_channel_pulse: channel=0, gpio=23, start=0, width=130
init_gpio 23
add_channel_pulse: channel=0, gpio=24, start=0, width=60
init_gpio 24
############################## Taking Photo
dummy webcam call
Finished
############################## resetting
clear_channel_gpio: channel=0, gpio=23
clear_channel_gpio: channel=0, gpio=24
shutting down dma channel 0
clear_channel: channel=0
pi@raspberrypi ~/paul $
This from running -

Code: Select all

pi@raspberrypi ~/paul $ cat paul.py
#!/usr/bin/env python
import time
import os
import ftplib

from RPIO import PWM

servo = PWM.Servo()
servo2 = PWM.Servo()

intPan = 600
intTilt = 1300
strPicName = "webcam"

strTempFilename = "/home/pi/" + strPicName + "Temp.jpg"
strFilename = "/home/pi/" + strPicName + ".jpg"

print("############################## Pan and Tilt")
servo.set_servo(23, intTilt)
servo2.set_servo(24, intPan)

time.sleep( 2 )

print("############################## Taking Photo")

#os.system("fswebcam -d /dev/video0 -r 384x288 " + strFilename)
print ("dummy webcam call")
print("Finished")


print("############################## resetting")

servo.stop_servo(23)
servo2.stop_servo(24)
pi@raspberrypi ~/paul $
Obviously I haven't run fswebcam - not sure if that will make a difference?
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Raspberry Paul
Posts: 86
Joined: Mon Jun 10, 2013 3:40 pm
Contact: Website

Re: Using RPIO PWM and os.subsystem - failing

Sat Feb 22, 2014 9:51 am

If I rem out all the os.subsystem related commands the servos move correctly.

If I rem out all the servo related commands the os.subsystem command runs ok.

But if both commands are in the same script, the os.subsystem seems to end abnormally and the script cancels
http://www.raspberrypaul.co.uk

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Using RPIO PWM and os.subsystem - failing

Sat Feb 22, 2014 10:32 am

Just because you have the system commands in order does not mean that python will execute them that way.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Using RPIO PWM and os.subsystem - failing

Sat Feb 22, 2014 11:52 am

Just because you have the system commands in order does not mean that python will execute them that way.
:eek:

Could you expand a bit on this?

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

User avatar
jojopi
Posts: 3271
Joined: Tue Oct 11, 2011 8:38 pm

Re: Using RPIO PWM and os.subsystem - failing

Sat Feb 22, 2014 1:06 pm

This is a bug in RPIO.PWM. It sets up signal handlers to ensure that the DMA channels are shut down cleanly if the program exits unexpectedly. But it sets up handlers for all signals, without regard to whether they were previously ignored.

os.system() forks a child process, and when that process exits a SIGCHLD is delivered. Normally that would be ignored, but RPIO.PWM makes it fatal. As a workaround, add this after initialising the PWM.Servo object:

Code: Select all

import signal
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
Richard-TX wrote:Just because you have the system commands in order does not mean that python will execute them that way.
Nonsense.

Raspberry Paul
Posts: 86
Joined: Mon Jun 10, 2013 3:40 pm
Contact: Website

Re: Using RPIO PWM and os.subsystem - failing

Mon Feb 24, 2014 8:55 pm

Code: Select all

import signal
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
Thanks for the reply. The code now works completely from end to end. :)
http://www.raspberrypaul.co.uk

Return to “Python”