New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve humanize walking variance #5147
Changes from 7 commits
28bb383
a454450
2238376
8c212ff
a99e309
2edd135
83c6e7e
23bcca0
41cf339
14beb6d
51ccc01
3331d56
85d3ef3
7371988
61a73e2
bff812f
adf857b
f71bba0
5a3d7f0
56bbd3d
f9b25e7
c1e66d5
2e77752
399bb48
598ee3e
04e46d6
e86b848
5d22c20
8ec9f62
b8bcdea
0c433b7
4714ae9
6044a74
e28dc40
ecfd324
1381989
df1b17f
810ebc4
744fec0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from math import sqrt | ||
import math | ||
|
||
from random import uniform | ||
from pokemongo_bot.cell_workers.utils import distance | ||
|
@@ -54,10 +54,14 @@ def __init__(self, bot, dest_lat, dest_lng, dest_alt=None, fixed_speed=None): | |
self.dLng = (dest_lng - self.initLng) / int(self.steps) | ||
self.magnitude = self._pythagorean(self.dLat, self.dLng) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. method was removed... |
||
self.unitAlt = (self.alt - self.initAlt) / int(self.steps) | ||
|
||
self.bearing = calc_bearing(self.initLat, self.initLng, self.dLat, self.dLng) | ||
|
||
def step(self): | ||
walk_sway = random_lat_long_delta2(self.bearing) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. random_lat_long_delta2 import missed? |
||
|
||
if (self.dLat == 0 and self.dLng == 0) or self.dist < self.speed: | ||
self.api.set_position(self.destLat + random_lat_long_delta(), self.destLng + random_lat_long_delta(), self.alt) | ||
self.api.set_position(self.destLat + walk_sway[0], self.destLng + walk_sway[1], self.alt) | ||
self.bot.event_manager.emit( | ||
'position_update', | ||
sender=self, | ||
|
@@ -81,8 +85,8 @@ def step(self): | |
scaledDLat = unitLat * self.magnitude | ||
scaledDLng = unitLng * self.magnitude | ||
|
||
cLat = self.initLat + scaledDLat + random_lat_long_delta() | ||
cLng = self.initLng + scaledDLng + random_lat_long_delta() | ||
cLat = self.initLat + scaledDLat + walk_sway[0] | ||
cLng = self.initLng + scaledDLng + walk_sway[1] | ||
cAlt = self.initAlt + self.unitAlt + random_alt_delta() | ||
|
||
self.api.set_position(cLat, cLng, cAlt) | ||
|
@@ -106,3 +110,43 @@ def step(self): | |
|
||
def _pythagorean(self, lat, lng): | ||
return sqrt((lat ** 2) + (lng ** 2)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you import math then this should become
|
||
|
||
def calc_bearing(start_lat, start_lng, dest_lat, dest_lng): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be static method? calc_bearing(self...) ? Or you forget @static decorator? @static # ??
def calc_bearing(start_lat, start_lng, dest_lat, dest_lng) |
||
""" | ||
Calculates the bearing between two points. | ||
|
||
The formulae used is the following: | ||
θ = atan2(sin(Δlong).cos(lat2), | ||
cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong)) | ||
|
||
:Parameters: | ||
- `start_lat in decimal degrees | ||
- `start_lng in decimal degrees | ||
- `dest_lat in decimal degrees | ||
- `dest_lng in decimal degrees | ||
|
||
:Returns: | ||
The bearing in degrees | ||
|
||
:Returns Type: | ||
float | ||
""" | ||
|
||
lat1 = math.radians(start_lat) | ||
lat2 = math.radians(dest_lat) | ||
|
||
diffLong = math.radians(dest_lng - start_lng) | ||
|
||
x = math.sin(diffLong) * math.cos(lat2) | ||
y = math.cos(lat1) * math.sin(lat2) - (math.sin(lat1) | ||
* math.cos(lat2) * math.cos(diffLong)) | ||
|
||
initial_bearing = math.atan2(x, y) | ||
|
||
# Now we have the initial bearing but math.atan2 return values | ||
# from -180° to + 180° which is not what we want for a compass bearing | ||
# The solution is to normalize the initial bearing as shown below | ||
initial_bearing = math.degrees(initial_bearing) | ||
compass_bearing = (initial_bearing + 360) % 360 | ||
|
||
return compass_bearing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you plan to use bearing in the calculation...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're heading at 0/360, we only add variance to latitude. Do some more math between there to scale each respective to that. I'm not sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait I got that backwards. If we're headed north (0/360), we'd change our longitude.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Delta applies to the destination. So as long as the Delta is smaller than the (destination - origin), you will never walk backward.
And as it is now, it is small enough for that. So not sure you need to change anything.