2017-03-05 23:03:21 +01:00
#!/usr/bin/env python3
import uuid
import paho . mqtt . client as mqtt
from planet import Direction , Planet
2018-03-24 06:09:48 +01:00
from communication import Mode , Communication
2018-03-18 14:23:17 +01:00
from move import Move
2017-03-05 23:03:21 +01:00
2018-03-18 14:23:17 +01:00
# DO NOT EDIT
client = None
2017-03-05 23:03:21 +01:00
def run ( ) :
# DO NOT EDIT
global client
2018-03-18 14:23:17 +01:00
# client_id has to be unique among ALL users
client = mqtt . Client ( client_id = str ( uuid . uuid4 ( ) ) ,
2017-03-05 23:03:21 +01:00
clean_session = False ,
protocol = mqtt . MQTTv31 )
2018-03-24 06:09:48 +01:00
communication = Communication ( client )
move = Move ( )
while ( communication . planetname is None ) :
communication . process_messages ( )
while ( communication . status ( ) is not Mode . COMPLETE ) :
2018-03-24 14:32:48 +01:00
while ( communication . status ( ) is Mode . GOTOSTATION or communication . status ( ) is Mode . TARGET ) : # should be triggered if current station has no unexplored edges
2018-03-24 06:09:48 +01:00
for instructions in communication . navto :
2018-03-24 06:32:25 +01:00
for instructions in communication . navto :
2018-03-24 14:32:48 +01:00
communication . update ( None )
2018-03-24 06:32:25 +01:00
move . turnto ( instructions [ 1 ] )
move . traversetonextstation ( True )
2018-03-24 06:09:48 +01:00
2018-03-24 14:32:48 +01:00
communication . update ( move . getstationedges ( ) ) # TODO: Register in map
2018-03-24 06:32:25 +01:00
move . turnto ( communication . navto [ 0 ] [ 1 ] ) # TODO: add control mechanism to communication class
2018-03-24 14:32:48 +01:00
if ( communication . check ( move . traversetonextstation ( False ) ) is False ) : # TODO: let same control mechanism decide if station is known, also traversetonextstation needs a return value
move . setcurdir ( communication . getdir ( ) )
2018-03-24 06:09:48 +01:00
2017-03-05 23:03:21 +01:00
# DO NOT EDIT
if __name__ == ' __main__ ' :
run ( )