如何将pimoroni平移式倾斜帽子与Motioneye集成在一起?

时间:2019-04-12 22:36:36

标签: python bash pan tilt motioneyeos

对于代码和python来说,我是很陌生的,因此在Motioneye监控软件中集成按钮来控制Pimoroni倾斜锅帽时遇到麻烦。我找到了adafruit PCA9685伺服控制器的代码,当按下按钮时它将调用bash脚本。然后,bash脚本将调用python脚本,只要按下按钮,该脚本就会连续平移或倾斜伺服器,这是我想做的事情。不幸的是,我不知道要进行什么更改才能使其与Pimoroni伺服器一起工作。

动眼 https://github.com/ccrisan/motioneye/wiki

帽子 https://shop.pimoroni.com/products/pan-tilt-hat

使用adafruit PCA9685伺服控制器控制运动眼中平移倾斜的脚本 https://github.com/luetzel/motion_eye_servo_action

我尝试更改代码中的GPIO引脚,并将pantilthat导入代码中。但是,这似乎不起作用。那会让我

Remote I/O error

下面是向下倾斜的示例代码。同样,这是针对Adafruit PCA9685驱动程序的。

如果有人可以帮助我使该工具与pimoroni锅倾斜帽子配合使用或将我指向正确的方向,我将非常感激!

亲切的问候 柯斯特

#!/usr/bin/env python
from __future__ import division
import time

# Import the PCA9685 module.
import Adafruit_PCA9685
import RPi.GPIO as GPIO
import pantilthat
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

# power-up servo controller
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, 0)
time.sleep(.5)

# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()

# Configure min and max servo pulse lengths (450 total, 25 corresponds to 10 degrees)
servo_min = 225  # Min pulse length out of 4096
servo_max = 725  # Max pulse length out of 4096

with open('/etc/motioneye/vert_pos', 'r') as f:
    vert_pos = int(f.readline())
    print vert_pos
    f.close()

# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)

if ( vert_pos != servo_max ):
        vert_pos += 25
        pwm.set_pwm(0, 0, vert_pos)
        with open('/etc/motioneye/vert_pos', 'w') as f:
            f.write(str(vert_pos))
            f.close()

# power-up servo controller
time.sleep(.5)`
GPIO.output(18, 1)

raise SystemExit```


1 个答案:

答案 0 :(得分:0)

我不确定是否可以完全按照您的要求进行。 Motioneye中的动作按钮仅运行脚本,如果您想移动摄像机更多,则必须再次按下按钮而不是按住它。 但是,让操作按钮与倾斜式帽子配合使用非常简单。 首先,我假设您已经将Motioneye设置为在树莓派运行拉伸上运行。 如果是这样,请在“ / etc / motioneye”目录中创建一个名为“ left_1”的文件 接下来对其进行编辑并添加以下内容:

#!/bin/bash
/usr/bin/python3 /etc/motioneye/left.py

现在使该文件可执行:sudo chmod 777 left_1

现在使用以下代码创建left.py:

#!/usr/bin/python

import time
import pantilthat

currentPos = pantilthat.get_servo_one()
newPos = currentPos +20
if newPos >= 80: newPos = 80
pantilthat.servo_one(newPos)
time.sleep(1)

这里要注意的一件事是,最大的地雷可以向左移动80,测试你的 对于right,请执行相同的操作,但要正确命名文件,right.py的代码为:

#!/usr/bin/python

import time
import pantilthat

currentPos = pantilthat.get_servo_one()
#print (currentPos)
newPos = currentPos - 20
if newPos <= -80: newPos = -80
pantilthat.servo_one(newPos)
time.sleep (1)

向上和向下相同,但将“ servo_one”更改为“ servo_two”

最后,使用按钮将相机移回“ 0”很有用。 为此,使用以下命令创建一个名为“ preset1_1”的文件:

#!/bin/bash
/usr/bin/python3 /etc/motioneye/reset.py

和一个名为“ reset.py”的py文件:

#!/usr/bin/python

import time
import pantilthat

pantilthat.servo_one(0)
pantilthat.servo_two(0)
time.sleep(1)

祝你好运!