コード例 #1
0
def servo_install(angle):
    servo0 = Servo.Servo(0, bus_number=1)
    servo1 = Servo.Servo(1, bus_number=1)
    servo2 = Servo.Servo(2, bus_number=1)
    servo0.write(angle)
    servo1.write(angle)
    servo2.write(angle)
    
    print "Servo set to", angle, "degrees.\n"
コード例 #2
0
 def __init__(self, channel, initial_angle=90, min_angle=0, max_angle=180):
     self.servo = Servo.Servo(channel)
     self.channel = channel
     self.min_angle = min_angle
     self.max_angle = max_angle
     self.initial_angle = initial_angle
     self.current_angle = initial_angle
     self.move()
コード例 #3
0
	def __init__(self, debug=False, bus_number=1, db="config"):
		''' Init the servo channel '''
		self.db = filedb.fileDB(db=db)
		self.pan_offset = int(self.db.get('pan_offset', default_value=0))
		self.tilt_offset = int(self.db.get('tilt_offset', default_value=0))

		self.pan_servo = Servo.Servo(self.pan_channel, bus_number=bus_number, offset=self.pan_offset)
		self.tilt_servo = Servo.Servo(self.tilt_channel, bus_number=bus_number, offset=self.tilt_offset)
		self.debug = debug
		if self._DEBUG:
			print(self._DEBUG_INFO, 'Pan servo channel:', self.pan_channel)
			print(self._DEBUG_INFO, 'Tilt servo channel:', self.tilt_channel)
			print(self._DEBUG_INFO, 'Pan offset value:', self.pan_offset)
			print(self._DEBUG_INFO, 'Tilt offset value:', self.tilt_offset)

		self.current_pan = 0
		self.current_tilt = 0
		self.ready()
コード例 #4
0
    def __init__(self,
                 bus_number=1,
                 pan_channel=1,
                 tilt_channel=2,
                 camera_type=ABSOLUTE):
        # The value to set Servo object offset to.
        offset = 0

        self._db = filedb.fileDB("config")
        self._pan_offset = int(self._db.get('pan_offset', default_value=0))
        self._tilt_offset = int(self._db.get('tilt_offset', default_value=0))

        self._pan_servo = Servo.Servo(pan_channel,
                                      bus_number=bus_number,
                                      offset=offset)
        self._tilt_servo = Servo.Servo(tilt_channel,
                                       bus_number=bus_number,
                                       offset=offset)

        self._camera_type = RELATIVE if camera_type is RELATIVE else ABSOLUTE

        self._current_pan_angle = 90
        self._current_tilt_angle = 0
コード例 #5
0
	def __init__(self, debug=_DEBUG, bus_number = 1, pan_channel = CAMERA_PAN_CHANNEL, tilt_channel = CAMERA_TILT_CHANNEL):
		
		self._pan_channel = pan_channel
		self._tilt_channel = tilt_channel
		self._straight_tilt_angle = 90
		self._straight_pan_angle = 90
		self.panning_max = 45
		self.tilting_max = 45
		self._turning_offset = 0
		
		#Objects for controlling tilt and pan Servo motors
		self.pan = Servo.Servo(self._pan_channel, bus_number = bus_number, offset = 0)
		self.tilt = Servo.Servo(self._tilt_channel, bus_number = bus_number, offset = 0)
		
		
		self.debug = debug
		if self._DEBUG:
			print("{} Camera Pan PWM channel: {}".format(self._DEBUG_INFO, self._pan_channel))
			print("{} Camera Tilt PWN channel: {}".format(self._DEBUG_INFO, self._tilt_channel))
			print("{} Camera Pan offset value: {}".format(self._DEBUG_INFO, self.turning_offset))
			
		if self._DEBUG:
			print("{} \n\tLeft pan angle: {}\n \tStraight pan angle: {}\n \tRight pan angle: {}".format(self._DEBUG_INFO, self._pan_angle["left"], self._pan_angle["straight"], self._pan_angle["right"]))
			print("{} \n\tDown tilt angle: {}\n \tFlat tilt angle: {}\n \tUp tilt angle: {}".format(self._DEBUG_INFO, self._tilt_angle["down"], self._tilt_angle["flat"], self._tilt_angle["up"]))
コード例 #6
0
ファイル: joystick.py プロジェクト: Arnieboy545/gip
class MyController(Controller):
    picar.setup()
    bw = back_wheels.Back_Wheels()
    fw = front_wheels.Front_Wheels()
    pan_servo = Servo.Servo(1)
    bw.speed = 0
    motor_speed = 60
    cap = cv2.VideoCapture(0)

    def __init__(self, **kwargs):
        Controller.__init__(self, **kwargs)

    def on_x_press(self):
        _,img = self.cap.read()
        cv2.imwrite('Documents\\'+ str(time.time())+ '.png',img)
        print("picture taken")
    def on_L3_up(self, value):
        speed = int((value/400)*-1)
        print("forward:" + str(speed))
        self.bw.speed = speed
        self.bw.backward()
    def on_L3_down(self, value):
        speed = int(value/400)
        print("backward:" + str(speed))
        self.bw.speed = speed
        self.bw.forward()
    def on_L3_left(self, value):
        print("value1:" + str(value))
        angleL = int((75-(-25/32767) * value))
        print("angle1:" + str(angleL))
        self.fw.turn(angleL)
    def on_L3_right(self, value):
        print("value2:" + str(value))
        angleR = int(((60/32767) * value + 75))
        print("angle2: " + str(angleR))
        self.fw.turn(angleR)
コード例 #7
0
# What model to download.
MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'
MODEL_FILE = MODEL_NAME + '.tar.gz'
DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'

# Path to frozen detection graph. This is the actual model that is used for the object detection.
PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'

# List of the strings that is used to add correct label for each box.
PATH_TO_LABELS = os.path.join('data', 'mscoco_label_map.pbtxt')

NUM_CLASSES = 90

bw = back_wheels.Back_Wheels()
fw = front_wheels.Front_Wheels()
pan_servo = Servo.Servo(1)
tilt_servo = Servo.Servo(2)
picar.setup()

fw.offset = 0
# pan_servo.offset = 10
pan_servo.offset = 0
tilt_servo.offset = 0

bw.speed = 0
# fw.turn(90)
# pan_servo.write(90)
# tilt_servo.write(90)

# ## Download Model
コード例 #8
0
ファイル: servotest.py プロジェクト: Arnieboy545/gip
from picar import front_wheels, back_wheels
from picar.SunFounder_PCA9685 import Servo
import picar
from time import sleep
import cv2
import numpy as np
import picar
import os

fw = front_wheels.Front_Wheels()
pan_servo = Servo.Servo(1)
num1 = 0
picar.setup()

fw.offset = 0
pan_servo.offset = 0
while num1 < 190:
    num1 = int(input())
    fw.turn(num1)
    pan_servo.write(0)

コード例 #9
0
ファイル: car.py プロジェクト: williamscales/selfdrivingcar
def get_front_wheel():
    channel = 0
    bus_number = 1
    return Servo.Servo(channel, bus_number=bus_number, offset=0)
コード例 #10
0
#Modified code from here: https://github.com/sunfounder/SunFounder_PiCar-V/blob/master/ball_track/ball_tracker.py
#Created by Kepler Electronics, https://www.youtube.com/keplerelectronics
from picar import front_wheels, back_wheels
from picar.SunFounder_PCA9685 import Servo
import picar
import time
from time import sleep
import numpy as np
import picar  #a second time?
import os
from evdev import InputDevice, categorize, ecodes

gamepad = InputDevice('/dev/input/event0')
print(gamepad)
turnServo = Servo.Servo(0)
picar.setup()
bw = picar.back_wheels.Back_Wheels()
speedup = 0
bw.forward()
bw.speed = 50
time.sleep(5)
bw.stop()
for event in gamepad.read_loop():
    print(event.code)
    if event.type == ecodes.EV_ABS:
        if event.code == 0:
            if event.value == 0:
                turnServo.write(60)
                print("Left")
                #explorerhat.motor.one.forwards(event.value-155)
            elif event.value == 2:
コード例 #11
0
        pub.publish(data)

        rate.sleep()


if __name__ == "__main__":
    picar.setup()
    db_file = "/home/pi/SunFounder_PiCar-V/remote_control/remote_control/driver/config"
    fw = front_wheels.Front_Wheels(debug=False, db=db_file)
    bw = back_wheels.Back_Wheels(debug=False, db=db_file)
    cam = Camera(debug=False, db=db_file)
    cam.ready()
    bw.ready()
    fw.ready()
    bCamTuneOffset = -11
    bCam = Servo.Servo(15, bus_number=1, offset=bCamTuneOffset)
    #bCam.setup()

    frontCam(5.0, 0.0)

    global fwOffset, bwStatus, bCanIOffset
    global tsT, tvT, tf1T, tf2T, tbT  #Target
    global tsC, tvC, tf1C, tf2C, tbC  #Current
    global tsR, tvR, tf1R, tf2R, tbR  #Max Rate
    global tsG, tvG, tf1G, tf2G, tbG  #Gain
    global commandHistory, maxHistory

    tsT = 0
    tvT = 0
    tf1T = 0
    tf2T = 0
コード例 #12
0
ファイル: servo.py プロジェクト: alperenssahin/ototaksi
 def __init__(self, pin):
     self.srv = Servo.Servo(pin)
     self.srv.setup()
コード例 #13
0
CAMERA_Y_ANGLE = 20

MIDDLE_TOLERANT = 5
PAN_ANGLE_MAX   = 170
PAN_ANGLE_MIN   = 10
TILT_ANGLE_MAX  = 150
TILT_ANGLE_MIN  = 70
FW_ANGLE_MAX    = 90+30
FW_ANGLE_MIN    = 90-30

SCAN_POS = [[20, TILT_ANGLE_MIN], [50, TILT_ANGLE_MIN], [90, TILT_ANGLE_MIN], [130, TILT_ANGLE_MIN], [160, TILT_ANGLE_MIN], 
            [160, 80], [130, 80], [90, 80], [50, 80], [20, 80]]

bw = back_wheels.Back_Wheels()
fw = front_wheels.Front_Wheels()
pan_servo = Servo.Servo(1, bus_number=1)
tilt_servo = Servo.Servo(2, bus_number=1)

picar.setup()

fw.offset = 0
pan_servo.offset = 10
tilt_servo.offset = 0

bw.speed = 0
fw.turn(90)
pan_servo.write(90)
tilt_servo.write(90)

motor_speed = 60