|
1
|
|
|
import logging |
|
2
|
|
|
from itertools import cycle |
|
3
|
|
|
from curio import sleep |
|
4
|
|
|
from bricknil import attach, start |
|
5
|
|
|
from bricknil.hub import BoostHub |
|
6
|
|
|
from bricknil.sensor import TrainMotor, VisionSensor, Button, LED, InternalTiltSensor, InternalMotor |
|
7
|
|
|
from bricknil.process import Process |
|
8
|
|
|
from bricknil.const import Color |
|
9
|
|
|
|
|
10
|
|
|
@attach(Button, name='hub_btn', capabilities=['sense_press']) |
|
11
|
|
|
@attach(LED, name='hub_led') |
|
12
|
|
|
#@attach(VisionSensor, name='vision_sensor', capabilities=['sense_count', 'sense_distance']) |
|
13
|
|
|
@attach(InternalTiltSensor, name='tilt_sensor', capabilities=['sense_angle']) |
|
14
|
|
|
@attach(InternalMotor, name='motor_l') |
|
15
|
|
|
@attach(InternalMotor, name='motor_r') |
|
16
|
|
|
class Robot(BoostHub): |
|
17
|
|
|
|
|
18
|
|
|
async def hub_btn_change(self): |
|
19
|
|
|
pass |
|
20
|
|
|
async def vision_sensor_change(self): |
|
21
|
|
|
pass |
|
22
|
|
|
async def motor_l_change(self): |
|
23
|
|
|
pass |
|
24
|
|
|
async def motor_r_change(self): |
|
25
|
|
|
pass |
|
26
|
|
|
async def tilt_sensor_change(self): |
|
27
|
|
|
pass |
|
28
|
|
|
|
|
29
|
|
|
async def run(self): |
|
30
|
|
|
self.message_info("Running") |
|
31
|
|
|
await sleep(20) # Give it enough time to gather data |
|
32
|
|
|
|
|
33
|
|
|
async def system(): |
|
34
|
|
|
hub = Robot('robot', True) |
|
35
|
|
|
|
|
36
|
|
|
if __name__ == '__main__': |
|
37
|
|
|
logging.basicConfig(level=logging.DEBUG) |
|
38
|
|
|
start(system) |
|
39
|
|
|
|