Open calleblyh opened 6 years ago
Hi again, I have slightly modified the code , see attached code. I hope you can see what I want to have. I have been reading on richardghirst forum it's not possible to retreive servo-position data, I wonder why ? I my code my starting position is 150 ( lets call it home position ) so any arrow keystroke will add or subtract new servo value. Unfortunately my programming skills are not good enough...Furthermore I would like when starting the code both servos take the home position. Also hitting HOME key would reset both servo position. How do I implement that code ? "
import curses import os import time import picamera
camera = picamera.PiCamera() camera.resolution = (1024, 768) camera.start_preview(fullscreen=False, window = (680,50,640,480))
os.system('sudo ./servod')
camera.vflip = True camera.hflip = True
screen = curses.initscr()
curses.cbreak()
screen.keypad(True)
servo1 = 150 servo2 = 150
pic = 1 try: while True: char = screen.getch() if char == ord('q'):
break
if char == ord('p'):
#if p is pressed take a photo!
camera.capture('image%s.jpg' % pic)
pic = pic +1
screen.addstr(0, 0, 'picture taken! ')
elif char == curses.KEY_RIGHT:
screen.addstr(2, 0, 'right ')
if servo1 > 50:
servo1 = servo1 -.5
os.system("echo 0=%s > /dev/servoblaster" %servo1)
screen.addstr(2, 10,("HOR Position is: XXX" ))
time.sleep(0.005)
elif char == curses.KEY_LEFT:
screen.addstr(3, 0, 'left ')
if servo1 < 250:
servo1 = servo1 +.5
os.system("echo 0=%s > /dev/servoblaster" %servo1)
screen.addstr(3, 10,("HOR Position is: XXX" ))
time.sleep(0.005)
elif char == curses.KEY_UP:
screen.addstr(4, 0, 'up ')
if servo2 > 50:
servo2 = servo2 -2
os.system("echo 1=%s > /dev/servoblaster" %servo2)
screen.addstr(4, 10,("VER Position is: YYY" ))
time.sleep(0.005)
elif char == curses.KEY_DOWN:
screen.addstr(5, 0, 'down ')
if servo2 < 250:
servo2 = servo2 +2
os.system("echo 1=%s > /dev/servoblaster" %servo2)
screen.addstr(5, 10,("VER Position is: YYY" ))
time.sleep(0.005)
finally:
curses.nocbreak(); screen.keypad(0); curses.echo()
curses.endwin()
"
In your code " elif char == curses.KEY_RIGHT: screen.addstr(2, 0, 'right ') if servo1 > 50: servo1 = servo1 -2 os.system("echo 0=%s > /dev/servoblaster" %servo1) " I donot understand %s althou thats the value that drives the servo to next position (I assume). I need to understand this line of code so I would be able to get the servo1 = servo1 +-N retreived on screen. As a non-programmer I cannot do it. Maybe somebody can help ? Appreciate any input !
Hi, I have successfully adopted pantilt.py in my BirdWatching remote controlled camera. I would like to see on screen the value of servo1 and servo2 after each keystroke. My servos, both pan and tilt, are limited between 60 and 240. What is the syntax ? Nonprogrammer calleblyh Helsinki