コード例 #1
0
        if (char == "s"):
            if tilt.get_servo_max() > tilt.get_current_pwm():
                tilt.set_current_pwm(tilt.get_current_pwm() +
                                     tilt.get_intervall_pwm())
            printscreen()

        # The Pan-Tilt-Kit turns to the right.
        if (char == "d"):
            if pan.get_current_pwm() > pan.get_servo_min():
                pan.set_current_pwm(pan.get_current_pwm() -
                                    pan.get_intervall_pwm())
            printscreen()

        # The Pan-Tilt-Kit turns to the left.
        if (char == "a"):
            if pan.get_servo_max() > pan.get_current_pwm():
                pan.set_current_pwm(pan.get_current_pwm() +
                                    pan.get_intervall_pwm())
            printscreen()

        # By pressing the key "x" the endless loop for reading the
        # keyboard inputs stopps and the program ends.
        if (char == "x"):
            pan.reset()
            tilt.reset()
            print("Exit program")
            break

        # The variable char is cleared after each loop run to be able to
        # read the next key pressed by the user.
        char = ""
コード例 #2
0
#!/usr/bin/env python
import os
import sys
import getpass

from config.servo_config import ServoConfig

env = os.path.expanduser(
    os.path.expandvars('/home/' + getpass.getuser() +
                       '/robotcar/driver/actor'))
sys.path.insert(0, env)

from servo import ServoMotor

# Main function.
if __name__ == "__main__":
    conf = ServoConfig()

    steering = ServoMotor(0, conf.getNeutral('steering'),
                          conf.getMin('steering'), conf.getMax('steering'), 5)
    pan = ServoMotor(4, conf.getNeutral('pan'), conf.getMin('pan'),
                     conf.getMax('pan'), 5)
    tilt = ServoMotor(3, conf.getNeutral('tilt'), conf.getMin('tilt'),
                      conf.getMax('tilt'), 5)

    steering.reset()
    pan.reset()
    tilt.reset()