Exemplo n.º 1
0
 def __init__(self):
     self.hub = PrimeHub()
     self.colorsensor = ColorSensor('B')
     self.force = ForceSensor('A')
     self.boundary = None# Initial Decision boundary
     self.ATraining = []# Initial A examples
     self.BTraining = []# Initial B examples
     self.averageA = None# Initial average for the A training
     self.averageB = None# Initial average for the B training
Exemplo n.º 2
0
 def __init__(self, dsPort):
     self.prime_hub = PrimeHub()
     self.hub.speaker.beep(72,0.5)
     self.hand_distance = DistanceSensor(dsPort)
     self.boundary = None  # Initial Decision boundary
     self.ATraining = []  # Initial A examples
     self.BTraining = []  # Initial B example
     self.averageA = None  # Initial average for the A training
     self.averageB = None  # Initial average for the B training
Exemplo n.º 3
0
    def __init__(self, leftmotorport, rightmotorport, headmotorport=None):
        """Assumes a three motor puppy configuration
        with two legs and one head motor"""
        self.prime_hub = PrimeHub()
        self.prime_hub.light_matrix.show_image('HAPPY')
        self.legR = Motor(rightmotorport)  # right leg
        self.legL = Motor(leftmotorport)  # left leg

        #self.legs = DriveBase(self.legL, self.legR, 30, 80)
        if headmotorport is not None:
            # If no headmotorport is given, it is not assigned.
            self.head = Motor(headmotorport)  # head motor
        else:
            self.head = None
Exemplo n.º 4
0
# This example finds and connects to a peripheral running the
# UART service (e.g. ble_simple_peripheral.py).
from spike import PrimeHub
from spike import Motor

    # Do something
hub = PrimeHub()


import bluetooth
import random
import struct
import time
import micropython
import ubinascii


def light(n):
    x=n%5
    y=n//5
    hub.light_matrix.set_pixel(x, y)


from micropython import const




if 'FLAG_INDICATE' in dir(bluetooth):
    # We're on MINDSTORMS Robot Inventor
    # New version of bluetooth
Exemplo n.º 5
0
# This example finds and connects to a peripheral running the
# UART service (e.g. ble_simple_peripheral.py).
from spike import PrimeHub
from spike import Motor

# Do something
hubprime = PrimeHub()
import hub

motor_drive = Motor("B")
motor_steer = Motor("A")

motor_steer.run_to_position(17)

import bluetooth
import random
import struct
import time
import micropython
import ubinascii


def light(n):
    x = n % 5
    y = n // 5
    hubprime.light_matrix.set_pixel(x, y)


from micropython import const

_IRQ_CENTRAL_CONNECT = const(1 << 0)
Exemplo n.º 6
0
# 8-11: 1st motor in extended address space
#12-15: 2nd motor in extended address space
def turnMotorOn(PFSensor, PFM):
    print(PFM)
    if PFM < 4:
        PFSensor.PFComboDirectCommand(bytes([PFM]), PFMotor.FORWARD, PFMotor.FLOAT)
    elif PFM < 8:
        PFSensor.PFComboDirectCommand(bytes([PFM-4]), PFMotor.FLOAT, PFMotor.FORWARD)
    elif PFM < 12:
        PFSensor.PFComboDirectCommand(bytes([PFM-8]), PFMotor.FORWARD, PFMotor.FLOAT, 1)
    elif PFM < 16:
        PFSensor.PFComboDirectCommand(bytes([PFM-12]), PFMotor.FLOAT, PFMotor.FORWARD, 1)
    utime.sleep_ms(100)

#This is the actual start of the program
myHub = PrimeHub()
mySensor = colorDistanceSensor("F", 7)
selectedMotor = 0

myHub.light_matrix.write('turn 4 receivers on and press RIGHT')
myHub.right_button.wait_until_pressed()
#Send 4 ChangeAddressSpace commands to each of the sensors to make sure that they switch the address space.
#(You might have to restart the program if they still don't change on first try)
for x in range(1):
    mySensor.PFChangeAddressSpace(PFChannel.CHANNEL_1)
    #utime.sleep_ms(100)
    mySensor.PFChangeAddressSpace(PFChannel.CHANNEL_2)
    #utime.sleep_ms(100)
    mySensor.PFChangeAddressSpace(PFChannel.CHANNEL_3)
    #utime.sleep_ms(100)
    mySensor.PFChangeAddressSpace(PFChannel.CHANNEL_4)
Exemplo n.º 7
0
from spike import PrimeHub
#from mindstorms import MSHub


#DON'T FORGET TO IMPORT THE LIBRARY
#(or paste it here)


technicHub = PrimeHub()
#technicHub = MSHub()
mySensor = colorDistanceSensor("E")
mode = 0;
while True:
    value = mySensor.read()
    technicHub.light_matrix.write(value)
    print(value)
    if technicHub.left_button.is_pressed():
        mode = mode - 1
        mySensor.changeMode(mode)
    if technicHub.right_button.is_pressed():
        mode = mode + 1
        mySensor.changeMode(mode)