From 6b2a19ebdc626c57f5569ffa5df27a828c278cdc Mon Sep 17 00:00:00 2001 From: d3rped Date: Mon, 26 Mar 2018 09:10:13 +0200 Subject: [PATCH] Everything should work now. But it doesn't. --- src/communication.py | 10 ++++++---- src/main.py | 44 ++++++++++++++++---------------------------- src/move.py | 6 +++--- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/communication.py b/src/communication.py index 6dcdb5f..c2be708 100644 --- a/src/communication.py +++ b/src/communication.py @@ -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 == []): diff --git a/src/main.py b/src/main.py index 14d8236..1d9833d 100644 --- a/src/main.py +++ b/src/main.py @@ -24,40 +24,28 @@ 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 - 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) + 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() + move.traversetonextstation(False) # DO NOT EDIT diff --git a/src/move.py b/src/move.py index f444aec..79298dc 100644 --- a/src/move.py +++ b/src/move.py @@ -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)