-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a navigator that walks along specified points.
- Loading branch information
1 parent
0a9444b
commit de83ed9
Showing
4 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# -*- coding: utf-8 -*- | ||
import logger | ||
from cell_workers.utils import distance, i2f, format_dist | ||
from human_behaviour import sleep | ||
from step_walker import StepWalker | ||
from pgoapi.utilities import f2i | ||
|
||
|
||
class PathNavigator(object): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
self.api = bot.api | ||
self.config = bot.config | ||
self.ptr = 0 | ||
self.mode = self.get_mode() | ||
|
||
if not self.config.path_navigator: | ||
raise RuntimeError('path_navigator config missing') | ||
|
||
self.points = self.get_points() | ||
|
||
def get_points(self): | ||
if not self.config.path_navigator.has_key('points') or len(self.config.path_navigator['points']) < 2: | ||
raise RuntimeError('You need to specify at least two points in the path_navigator config') | ||
|
||
points = [point.split(',') for point in self.config.path_navigator['points']] | ||
return points | ||
|
||
def get_mode(self): | ||
mode = 'linear' | ||
if self.config.path_navigator.has_key('mode'): | ||
if self.config.path_navigator['mode'] == 'loop': | ||
mode = 'loop' | ||
|
||
return mode | ||
|
||
def take_step(self): | ||
point = self.points[self.ptr] | ||
lat = float(point[0]) | ||
lng = float(point[1]) | ||
|
||
if self.config.walk > 0: | ||
step_walker = StepWalker( | ||
self.bot, | ||
self.config.walk, | ||
lat, | ||
lng | ||
) | ||
|
||
if step_walker.step(): | ||
step_walker = None | ||
|
||
else: | ||
self.api.set_position(point['lat'], point['lng']) | ||
|
||
dist = distance( | ||
self.api._position_lat, | ||
self.api._position_lng, | ||
lat, | ||
lng | ||
) | ||
|
||
if dist <= 1 or (self.config.walk > 0 and step_walker == None): | ||
if (self.ptr + 1) == len(self.points): | ||
self.ptr = 0 | ||
if self.mode == 'linear': | ||
self.points = list(reversed(self.points)) | ||
else: | ||
self.ptr += 1 | ||
|
||
return [lat, lng] |