コード例 #1
0
def assemble_robot():
    robot = Pitop()

    robot.add_component(Camera(resolution=(640, 480), rotate_angle=90))
    robot.add_component(PincerController())
    robot.add_component(
        NavigationController(left_motor_port="M3", right_motor_port="M0")
    )

    return robot
コード例 #2
0
def assemble_robot():
    pitop = Pitop()

    pitop.add_component(TiltRollHeadController())
    pitop.head.calibrate()

    pitop.add_component(Camera(resolution=(640, 480), flip_top_bottom=True))

    pitop.add_component(UltrasonicSensor("A1"))

    return pitop
コード例 #3
0
from pitop import Camera, DriveController, Pitop
from pitop.labs import RoverWebController

rover = Pitop()
rover.add_component(DriveController())
rover.add_component(Camera())

rover_controller = RoverWebController(
    get_frame=rover.camera.get_frame,
    drive=rover.drive,
)

rover_controller.serve_forever()
コード例 #4
0
ファイル: run.py プロジェクト: pi-top/pi-top-Python-SDK
from pitop import Camera, Pitop
from pitop.labs import WebController

photobooth = Pitop()
photobooth.add_component(Camera())


def save_photo(data):
    photobooth.camera.current_frame().save(f'{data["name"]}.jpg')


controller = WebController(get_frame=photobooth.camera.get_frame,
                           message_handlers={"save_photo": save_photo})

controller.serve_forever()
コード例 #5
0
            canvas=canvas, emoji="Looking", bounding_box=wide_bounding_box, offset_y=5
        )
        draw_text(canvas=canvas, text="Looking...")

    robot.miniscreen.display_image(image)


def run_emotion_and_face_detector(frame):
    face = face_detector(frame)
    emotion = emotion_classifier(face)
    update_displayed_image(face, emotion)


robot = Pitop()
camera = Camera(resolution=(640, 480), flip_top_bottom=True)
robot.add_component(camera)

image = Image.new(
    robot.miniscreen.mode,
    robot.miniscreen.size,
)

w_ms, h_ms = robot.miniscreen.size

sample_text = "100% Happy"
_, top_section_height = text_font.getsize(sample_text)

left_bounding_box = (0, top_section_height, w_ms // 2, h_ms - top_section_height)
right_bounding_box = (
    w_ms // 2,
    top_section_height,
コード例 #6
0
from random import randint
from time import sleep

from pitop import Pitop
from pitop.robotics.drive_controller import DriveController

# Create a basic robot
robot = Pitop()
drive = DriveController(left_motor_port="M3", right_motor_port="M0")
robot.add_component(drive)


# Use miniscreen display
robot.miniscreen.display_multiline_text("hey there!")


def random_speed_factor():
    # 0.01 - 1, 0.01 resolution
    return randint(1, 100) / 100


def random_sleep():
    # 0.5 - 2, 0.5 resolution
    return randint(1, 4) / 2


# Move around randomly
robot.drive.forward(speed_factor=random_speed_factor())
sleep(random_sleep())

robot.drive.left(speed_factor=random_speed_factor())
コード例 #7
0
    face = face_detector(frame)
    robot_view = face.robot_view

    cv2.imshow("Faces", robot_view)
    cv2.waitKey(1)

    if face.found:
        face_angle = face.angle
        robot.head.track_head_angle(face_angle)
        print(f"Face angle: {face.angle}")
    else:
        robot.head.roll.sweep(speed=0)
        print("Cannot find face!")


robot = Pitop()

robot.add_component(
    TiltRollHeadController(servo_roll_port="S0", servo_tilt_port="S3"))
robot.head.calibrate()
robot.head.tilt.target_angle = 70
robot.head.roll.target_angle = 0

robot.add_component(Camera(resolution=(640, 480), flip_top_bottom=True))

face_detector = FaceDetector()

robot.camera.on_frame = track_face

pause()
コード例 #8
0
from signal import pause

from pitop import Camera, DriveController, Pitop
from pitop.processing.algorithms.line_detect import process_frame_for_line

# Assemble a robot
robot = Pitop()
robot.add_component(
    DriveController(left_motor_port="M3", right_motor_port="M0"))
robot.add_component(Camera())


# Set up logic based on line detection
def drive_based_on_frame(frame):
    processed_frame = process_frame_for_line(frame)

    if processed_frame.line_center is None:
        print("Line is lost!", end="\r")
        robot.drive.stop()
    else:
        print(f"Target angle: {processed_frame.angle:.2f} deg ", end="\r")
        robot.drive.forward(0.25, hold=True)
        robot.drive.target_lock_drive_angle(processed_frame.angle)
        robot.miniscreen.display_image(processed_frame.robot_view)


# On each camera frame, detect a line
robot.camera.on_frame = drive_based_on_frame

pause()
コード例 #9
0
from time import sleep

import gevent

from pitop import LED, Button, Pitop, UltrasonicSensor
from pitop.labs import WebController

robot = Pitop()
robot.add_component(Button("D1"))
robot.add_component(LED("D2"))
robot.add_component(UltrasonicSensor("D3"))

dashboard_server = WebController()


def broadcast_state():
    while True:
        sleep(0.1)
        dashboard_server.broadcast(robot.state)


hub = gevent.get_hub()
hub.threadpool.spawn(broadcast_state)

dashboard_server.serve_forever()
コード例 #10
0
from time import sleep

from pitop import LED, Pitop
from pitop.robotics.drive_controller import DriveController

pitop = Pitop()
drive_controller = DriveController()
led = LED("D0", name="red_led")

# Add components to the Pitop object
pitop.add_component(drive_controller)
pitop.add_component(led)

# Do something with the object
pitop.red_led.on()
pitop.drive.forward(0.5)
sleep(2)
pitop.red_led.off()
pitop.drive.stop()

# Store configuration to a file
pitop.save_config("/home/pi/my_custom_config.json")
コード例 #11
0

def main():
    square_side_length = 1.0  # m
    square_top_right = (square_side_length / 2, -square_side_length / 2)
    square_top_left = (square_side_length / 2, square_side_length / 2)
    square_bottom_left = (-square_side_length / 2, square_side_length / 2)
    square_bottom_right = (-square_side_length / 2, -square_side_length / 2)

    for _ in range(0, 2):
        set_goal_with_obstacle_detection(position=square_top_right)
        set_goal_with_obstacle_detection(position=square_top_left)
        set_goal_with_obstacle_detection(position=square_bottom_left)
        set_goal_with_obstacle_detection(position=square_bottom_right)

    # go back to start_position
    robot.navigate.go_to(position=(0, 0),
                         angle=0,
                         on_finish=navigation_finished,
                         backwards=True).wait()
    print(f"Goal reached with state: \n{robot.navigate.state_tracker}")


goal_reached = False
robot = Pitop()
robot.add_component(
    NavigationController(left_motor_port="M3", right_motor_port="M0"))
robot.add_component(UltrasonicSensor("D3"))

main()