nikivanov / watney

Watney is a low-cost 3D-printable FPV rover
GNU General Public License v3.0
384 stars 39 forks source link

Possible to add servo for left right on camera #21

Closed man4567890 closed 2 years ago

man4567890 commented 3 years ago

Hi, Cool project, but I have a pan tilt servo mounted on the camera, where would the changes be in the code for using Q and W for left and right please, I connected the additional servo pin to GPIO3 and made changes in rover.conf

[SERVOUD]
PWMPin=2
# Min restricts the camera movement down
Min=5.5
# Max restricts the camera movement up
Max=9.2
Neutral=7.5

[SERVOLR]
PWMPin=3
# Min restricts the camera movement left
Min=5.5
# Max restricts the camera movement right
Max=9.2
Neutral=7.5

and added the new function to servocontroller.py

class ServoController:

    def __init__(self, config):
        Events.getInstance().janusFirstConnect.append(lambda: self.onJanusConnected())

        servoConfig = config["SERVOUD"]
        self.pwmPin = int(servoConfig["PWMPin"])
        self.neutral = float(servoConfig["Neutral"])
        self.min = float(servoConfig["Min"])
        self.max = float(servoConfig["Max"])

        servoConfig = config["SERVOLR"]
        self.pwmPin = int(servoConfig["PWMPin"])
        self.neutral = float(servoConfig["Neutral"])
        self.min = float(servoConfig["Min"])
        self.max = float(servoConfig["Max"])

But I do not know what changes are needed in the UI code, please

nikivanov commented 3 years ago

Look in js/watney.js - you want to catch Q / W keyDown / keyUp, add lookLR near sendKeys and finally actually send it to sendCommand endpoint. In python you need to parse those values and call the servo controller