コード例 #1
0
 def sit(self):
     """ Puppy sit with leg motors"""
     # TODO: modify to use paired motors
     self.legR.start_at_power(75)
     self.legL.start_at_power(75)
     wait_for_seconds(.4)
     self.legR.start_at_power(0)
     self.legL.start_at_power(0)
     print("Sitting Down")
コード例 #2
0
 def stand(self):
     """ Puppy stand with leg motors"""
     # TODO: modify to use paired motors
     self.legR.start_at_power(-75)
     self.legL.start_at_power(-75)
     wait_for_seconds(.4)
     self.legR.start_at_power(0)
     self.legL.start_at_power(0)
     print("Standing Up")
コード例 #3
0
ファイル: ZiyiCode.py プロジェクト: milandahal213/Summer2020
 def observation(self):
     """Adds one training observation to the training data"""
     print('Press up or down button to tell the puppy which command you are\
         demonstrating.\n Press the center to stop training')
     while True:# Waits for button press to record an observation
         print(self.colorsensor.get_ambient_light())
         if self.hub.left_button.was_pressed():
             # Record an A command observation
             force = self.force.get_force_newton()
             dog_command = 'A'
             print('Puppy learns that this means command A')
             # Adds the observation to the recorded data
             self.ATraining.append(force)
             wait_for_seconds(0.5)
             return force, dog_command
コード例 #4
0
    def happy(self):
        """Happy behavior
        Assumes puppy is seated"""

        self.self.prime_hub.light_matrix.show_image('MEH')
        for value in range(1, 4):
            #self.legs.drive(-100, 0)
            self.bark()
            wait_for_seconds(.2)
            self.legs.stop()
            wait_for_seconds(.3)
            #self.legs.drive(10, 0)
            wait_for_seconds(.3)
            self.legs.stop()
        self.self.prime_hub.light_matrix.show_image('HAPPY')
コード例 #5
0
ファイル: ZiyiCode.py プロジェクト: milandahal213/Summer2020
                force = self.force.get_force_newton()
                dog_command = 'A'
                print('Puppy learns that this means command A')
                # Adds the observation to the recorded data
                self.ATraining.append(force)
                wait_for_seconds(0.5)
                return force, dog_command
​
            elif self.hub.right_button.was_pressed():
                # Record a B command observation
                force = self.force.get_force_newton()
                dog_command = 'B'
                print('Puppy learns that this means command B')
                # Adds the observation to the recorded data
                self.BTraining.append(force)
                wait_for_seconds(0.5)
                return force, dog_command
​
            elif self.colorsensor.get_ambient_light() > 30:
                # Stop training
                angle = 0
                dog_command = 'Exit'
                print('Puppy is done training for now.')
                return angle, dog_command
​
    def watch(self):
        """Adds multiple training observations to the training data
        Puppy watches for commands until the center button is pressed"""
        command = ''
        print('Puppy is ready to start learning!')
        while command != "Exit":
コード例 #6
0
import hub, utime
# import spike
from spike.control import wait_for_seconds

A = 440
B = 494
Cis = 554
D = 587
E = 659
Fis = 698
hub.sound.volume(10)

notes = [A, B, Cis, D, E, Fis]
time = [500, 500, 100, 200, 300, 1000]

hub.sound.beep(B, 500, 1)
# for i in range (1, 3):
#     hub.sound.beep(A, 500, 3)

for i in range(0, len(notes)):
    print(i)
    # hub.sound.beep(A, 1000, 1)
    wait_for_seconds(1)
    hub.sound.beep(notes[i], time[i], 1)  # note, time (ms), sinewave
コード例 #7
0
from spike import ColorSensor
from spike.control import wait_for_seconds

# Initialize the Color Sensor.
paper_scanner = ColorSensor('E')

while True:
    # Measure the intensity.
    red = paper_scanner.get_red()
    green = paper_scanner.get_green()
    blue = paper_scanner.get_blue()
    # Print the color name to the console
    print('Red intensity', red)
    print('Green intensity', green)
    print('Blue intensity', blue)
    wait_for_seconds(2)
コード例 #8
0
from spike.control import wait_for_seconds

print("Twinkle Twinkle")
# wait for 2 second (pause the program flow)
wait_for_seconds(2)
print("little star")
# wait for 1.5 seconds (pause the program flow)
wait_for_seconds(1.5)
print("how I wonder")
# wait for 0.5 seconds (pause the program flow)
wait_for_seconds(0.5)
print("where you are")
コード例 #9
0
ファイル: Gyro.py プロジェクト: jmo-ops/examples_python
from spike.control import wait_for_seconds, wait_until, Timer
from math import *

hub = PrimeHub()

motor_pair = MotorPair('A', 'B')  # Set the motor ports in the motor_pair.

motor_pair.set_default_speed(30)  # Set the default speed of the motor_pair.

# Set the distance that the robot travels for one rotation its wheels. The value comes from# the diameter of the wheel  multiplied by "π" (3.14).
motor_pair.set_motor_rotation(22, 'cm')

# Activate the brakes when the robot stops. The other conditions are 'hold' and 'coast'.
motor_pair.set_stop_action('brake')

wait_for_seconds(1)  # Wait for one second.

#Reset the Gyro sensor. The current yaw angle value is equal to 0.
hub.motion_sensor.reset_yaw_angle()

motor_pair.start(
    steering=100
)  # Turn left around the center of the wheelbase. Leftward because of steering=-100 parameter.


# To program the robot to wait until the robot has turned, we need to define a fuction that checks if the robot has turned.
def left_turn_end():  # Define the function
    return hub.motion_sensor.get_yaw_angle(
    ) > 90  # Return true or false depending on the yaw angle value.

コード例 #10
0
from spike import PrimeHub, LightMatrix, Motor, MotorPair
from spike.control import wait_for_seconds, wait_until, Timer

hub = PrimeHub()

hub.status_light.on('blue')
doAWhile = True
while doAWhile:
    hub.light_matrix.off()
    for x in range(0, 4):
        wait_for_seconds(3)
        hub.light_matrix.set_pixel(0, x)
        doAWhile = False
コード例 #11
0
from spike import PrimeHub
from spike.control import wait_for_seconds

hub = PrimeHub()

hub.light_matrix.set_pixel(1, 0, 100)
wait_for_seconds(0.2)
hub.light_matrix.set_pixel(1, 1, 80)
wait_for_seconds(0.2)
hub.light_matrix.set_pixel(1, 2, 60)
wait_for_seconds(0.2)
hub.light_matrix.set_pixel(1, 3, 40)
wait_for_seconds(0.2)
hub.light_matrix.set_pixel(1, 4, 20)
wait_for_seconds(0.2)

# Turn off all pixels
#hub.light_matrix.off()