Esempio n. 1
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
import spike
from spike import DistanceSensor
distance_sensor = DistanceSensor('B')
last_distance = DistanceSensor('B').get_distance_cm()
    
Esempio n. 3
0
from spike import MotorPair
from spike import DistanceSensor
import utime

# small wheel to spike wheel ratio
wheel_gain = 55 / 30

# other init
target_dist = 10
last_dist = 10
kp = 5
wall_detector = DistanceSensor('E')
motor_pair = MotorPair('B', 'A')

# move panda forward
while True:
    try:
        dist = wall_detector.get_distance_percentage()
        if dist == None:
            dist = target_dist
        else:
            last_dist = dist
    except:
        dist = last_dist

    motor_power = (int(dist) - target_dist) * kp
    if motor_power > 50:
        motor_power = 50
    elif motor_power < -50:
        motor_power = -50
    print('speed:{} dist:{}'.format(dist, motor_power))
Esempio n. 4
0
import hub,utime
from spike import DistanceSensor
from spike.control import wait_for_seconds
distance_sensor = DistanceSensor('A')
while True:
	last_distance = distance_sensor.get_distance_cm()
	wait_for_seconds(1)
	new_distance = distance_sensor.get_distance_cm()
	while last_distance != new_distance:
	    hub.port.C.motor.run_at_speed(speed = new_distance, max_power = 100, acceleration = 100, deceleration = 100, stall = False)

	
Esempio n. 5
0
    motor_e.set_default_speed(50)
    motor_e.run_for_rotations(+1.50)


def openGrip():
    motor_e.set_default_speed(50)
    motor_e.run_for_rotations(-1.50)


# set up hub, motors and sensors
hub = PrimeHub()
motor_pair = MotorPair('A', 'B')
motor_pair.set_motor_rotation(17.5, 'cm')
motor_pair.set_default_speed(20)
colour_c = ColorSensor('C')
distance = DistanceSensor('D')
motor_e = Motor('E')

# create a peripheral object
remote = BLEPeripheral()

# scan for the target device and connect if found
utime.sleep(1)
remote.on_connect(callback=on_connect)
remote.on_disconnect(callback=on_disconnect)
remote.connect()

grabberOpen = True

while remote.is_connected() is not None:
    # when an object detection notification is received, go and pickup the object