예제 #1
0
파일: M11.py 프로젝트: Niko-bru/LegoSpike
from spike import PrimeHub, LightMatrix, Button, StatusLight, ForceSensor, MotionSensor, Speaker, ColorSensor, App, \
    DistanceSensor, Motor, MotorPair
from spike.control import wait_for_seconds, wait_until, Timer
import math

hub = PrimeHub()
motor_pair = MotorPair('A', 'E')
right_motor = Motor('E')
left_color = ColorSensor('B')
right_color = ColorSensor('D')
wheel_distance_apart = 14.5
wheel_radius = 4.25
wheel_circumference = 2 * math.pi * wheel_radius
motor_pair.set_motor_rotation(wheel_circumference, 'cm')
right_motor.set_default_speed(15)

i = 0
motor_pair.start_tank(25, 25)
while i < 200:
    if left_color.get_color() == 'black':
        print('l')
        motor_pair.start_tank(5, 25)
    elif right_color.get_color() == 'black':
        print('r')
        motor_pair.start_tank(25, 5)
    i += 1
motor_pair.stop()
motor_pair.move_tank(165, 'cm', left_speed=15, right_speed=15)
right_motor.run_for_rotations(20)
motor_pair.start_tank(-25, -25)
예제 #2
0
        turn(hub, motor_pair, -60)


# start the robot with the thing right of the right wheel lined up with the line to the left of the top of the white
# word CHALLENGE
# the back of the robot lined up with the line 1st from the thick black line

to_mission(g_hub, g_motor_pair, g_front_motor, g_back_motor)
to_dump(g_hub, g_motor_pair, g_front_motor, g_back_motor)
dump(g_hub, g_motor_pair, g_front_motor, g_back_motor)
to_dance(g_hub, g_motor_pair, g_front_motor, g_back_motor)

to_mission(g_hub, g_motor_pair, g_front_motor, g_back_motor)
dump(g_hub, g_motor_pair, g_front_motor, g_back_motor)

# Dump and move to M13 code
g_motor_pair.move(10, 'cm', steering=0, speed=25)
turn(g_hub, g_motor_pair, -90)
g_motor_pair.move(40, 'cm', steering=0, speed=25)
turn(g_hub, g_motor_pair, -90)
g_motor_pair.move(30, 'cm', steering=0, speed=25)
g_motor_pair.move(-3, 'cm', steering=0, speed=25)
turn(g_hub, g_motor_pair, 90)
g_motor_pair.move(1, 'cm', steering=0, speed=25)
g_motor_pair.move(7, 'cm', steering=0, speed=5)
g_front_motor.run_for_rotations(-.75, 100)
g_motor_pair.move(-10, 'cm', steering=0, speed=5)
g_front_motor.run_for_rotations(.75, 100)
turn(g_hub, g_motor_pair, 90)
g_motor_pair.move(20, 'cm', steering=0, speed=25)