Everything should work now. But it doesn't.
This commit is contained in:
parent
aa6b049ce5
commit
6b2a19ebdc
3 changed files with 25 additions and 35 deletions
|
@ -101,19 +101,21 @@ class Communication:
|
|||
self.client.loop_start()
|
||||
self._status = Mode.EXPLORE
|
||||
self.navto = []
|
||||
self.isfirstrun = True
|
||||
|
||||
def status(self):
|
||||
return self._status
|
||||
|
||||
def update(self, odometry): # TODO: FINISH
|
||||
if(odometry is not None): # use odometry to send data
|
||||
if(self.isfirstrun):
|
||||
pass
|
||||
elif(odometry is not None): # use odometry to send data
|
||||
self.encode_message(Command.PATH, ((self.planet.getcurnode(), self.planet.getcurdir()), ((self.planet.getcurnode()[0] + odometry[0][0], self.planet.getcurnode()[1] + odometry[0][1]), (odometry[1] - 180) % 360), odometry[2]))
|
||||
if(self._status is Mode.GOTOSTATION or self._status is Mode.TARGET):
|
||||
elif(self._status is Mode.GOTOSTATION or self._status is Mode.TARGET):
|
||||
self.encode_message(Command.PATH, ((self.navto[0][0], self.navto[0][1]), (self.planet._planetmap[self.navto[0][0]][self.navto[0][1]][0], self.planet._planetmap[self.navto[0][0]][self.navto[0][1]][1]), self.planet._planetmap[self.navto[0][0]][self.navto[0][1]][2]))
|
||||
self.navto.pop(0)
|
||||
self.process_messages() # this should update curnode and curdir
|
||||
|
||||
def process(self, edges):
|
||||
def process_edges(self, edges):
|
||||
edges = self.planet.checkedges(edges)
|
||||
if(edges == [] and self._status is Mode.EXPLORE):
|
||||
if(self.planet.unexedge == []):
|
||||
|
|
34
src/main.py
34
src/main.py
|
@ -24,39 +24,27 @@ def run():
|
|||
while(communication.planetname is None):
|
||||
communication.process_messages()
|
||||
|
||||
# run first time not in loop because odometry data is not relevant
|
||||
communication.update(None) # TODO: Register in map
|
||||
# correct odometry right here otherwise list of edges will be incorrect
|
||||
move.setcurdir(communication.getdir())
|
||||
communication.process(move.getstationedges())
|
||||
move.turnto(communication.navto[0][1]) # TODO: add control mechanism to communication class
|
||||
sleep(4)
|
||||
communication.planet.setcurdir(communication.navto[0][1])
|
||||
move.setcurdir(communication.getdir())
|
||||
move.reset()
|
||||
print("current dir:", move._odometry.angle_get())
|
||||
print("Navigation Data:", communication.navto)
|
||||
move.traversetonextstation(False)
|
||||
|
||||
while(communication.status() is not Mode.COMPLETE):
|
||||
while(communication.status() is Mode.GOTOSTATION or communication.status() is Mode.TARGET): # should be triggered if current station has no unexplored edges
|
||||
for instructions in communication.navto:
|
||||
for instructions in communication.navto:
|
||||
communication.update(None, None)
|
||||
move.turnto(instructions[1])
|
||||
move.traversetonextstation(True)
|
||||
|
||||
communication.update(move.getstats()) # TODO: Register in map
|
||||
# correct odometry right here otherwise list of edges will be incorrect
|
||||
move.setcurdir(communication.getdir())
|
||||
communication.process(move.getstationedges())
|
||||
move.turnto(communication.navto[0][1]) # TODO: add control mechanism to communication class
|
||||
communication.process_edges(move.getstationedges())
|
||||
if(communication.status() is Mode.GOTOSTATION or communication.status() is Mode.TARGET): # should be triggered if current station has no unexplored edges
|
||||
for instructions in communication.navto:
|
||||
move.turnto(instructions[1])
|
||||
move.traversetonextstation(True)
|
||||
move.setcurdir(communication.planet._planetmap[instructions[0]][instructions[1]][1])
|
||||
communication.update(None)
|
||||
communication.navto.clear()
|
||||
communication._status = Mode.EXPLORE
|
||||
else:
|
||||
move.turnto(communication.navto[0][1])
|
||||
sleep(4)
|
||||
communication.planet.setcurdir(communication.navto[0][1])
|
||||
move.setcurdir(communication.getdir())
|
||||
move.reset()
|
||||
print("current dir:", move._odometry.angle_get())
|
||||
print("Navigation Data:", communication.navto)
|
||||
move.traversetonextstation(False)
|
||||
|
||||
|
||||
|
|
|
@ -97,8 +97,8 @@ class Move:
|
|||
else:
|
||||
found_edges.append(self._odometry.angle_get())
|
||||
self._odometry.angle_set(self._odometry.angle_get())
|
||||
self._wheel_l.turnbyamount(40, 60)
|
||||
self._wheel_r.turnbyamount(-40, 60)
|
||||
self._wheel_l.turnbyamount(20, 40)
|
||||
self._wheel_r.turnbyamount(-20, 40)
|
||||
sleep(2)
|
||||
self._aligntoedge()
|
||||
self._odometry.pos_update((self._wheel_l.getmovement(), self._wheel_r.getmovement()))
|
||||
|
@ -141,7 +141,7 @@ class Move:
|
|||
self._odometry.pos_update((self._wheel_l.getmovement(), self._wheel_r.getmovement()))
|
||||
self._wheel_l.stop()
|
||||
self._wheel_r.stop()
|
||||
if(self._sensor._bumper_r):
|
||||
if(self._sensor.bumperwaspressed is True):
|
||||
self._wheel_l.turnbyamount(-200, 120)
|
||||
self._wheel_r.turnbyamount(-200, 120)
|
||||
sleep(1)
|
||||
|
|
Loading…
Reference in a new issue