-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
73 lines (58 loc) · 2.11 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from time import sleep
import random
import imager2 as IMR
from reflectance_sensors import ReflectanceSensors
from camera import Camera
from motors import Motors
from ultrasonic import Ultrasonic
from Bbcon import *
# Gjor at roboten danser
def dancer():
m = Motors()
m.forward(0.2, 3)
m.backward(0.2, 3)
m.right(0.5, 3)
m.left(0.5, 3)
m.backward(0.3, 2.5)
m.set_value([0.5, 0.1], 10)
m.set_value([-0.5, -0.1], 10)
# This tests the UV (distance) sensors. The robot moves forward to within 10 cm of the nearest obstacle. It
# then does a little dancing before backing up to approximately 50 cm from the nearest obstacle.
def explorer(dist=10):
m = Motors()
u = Ultrasonic()
while u.update() > dist:
m.forward(0.2, 0.2)
m.backward(.1, 0.5)
m.left(.5, 3)
m.right(.5, 3.5)
sleep(2)
while u.update() < dist*5:
m.backward(.2, 0.2)
m.left(.75, 5)
def random_step(motors, speed=0.25, duration=1):
dir = random.choice(['forward', 'backward', 'left', 'right'])
eval('Motors.'+ dir)(motors,speed,duration)
# This moves around randomly until it gets to a dark spot on the floor (detected with the infrared belly sensors).
# It then rotates around, snapping pictures as it goes. It then pastes all the pictures together into a
# panoramo view, many of which may be created per "vacation".
def tourist(steps=25, shots=5, speed=0.25):
rs = ReflectanceSensors(); m = Motors(); c = Camera()
for i in range(steps):
random_step(m, speed=speed, duration=1)
vals = rs.update()
if sum(vals) < 1: # very dark area
im = shoot_panorama(c,m,shots)
im.dump_image('vacation_pic'+str(i)+'.jpeg')
def shoot_panorama(camera, motors, shots=5):
s = 1
im = IMR.Imager(image=camera.update()).scale(s,s)
rotation_time = 3/shots # At a speed of 0.5(of max), it takes about 3 seconds to rotate 360 degrees
for i in range(shots-1):
motors.right(0.5, rotation_time)
im = im.concat_horiz(IMR.Imager(image=camera.update()))
return im
#m = Motors()
#m.forward(0.25, 0.5)
b = Bbcon()
b.controller()