Skip to content

Commit

Permalink
Final checkin of mineworld, passed black and flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
iliabaranov committed Nov 3, 2022
1 parent 041d7b5 commit 557ffeb
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 37 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ python3 -m pip install -r requirements.txt



##### To launch the mine world gui example

`python3 mineworld.py`

<img src="images/mineworld_screenshot.png" width="412">

1. Enter your Bearer Token and Device Key.

2. Click Connect, and after a second or so, you will get current position and data about your simulated vehicle.

3. Click on some open space in the map, and the vehicle will navigate itself there.

4. Explore! Have fun (note: you will have to click STOP to send a new goal)


## Caladan API

Check the bottom of the caladan_api.py file for example usage of the API in Python directly, for use in your own code. Example:
Expand All @@ -104,7 +119,7 @@ Python 3.8.10

## FAQs

- Q: I Don't have a token and key?
- Q: I don't have a token and key?
- A: Sign up for our beta!

- NB: Add your token and key to farmworld_config.py and portworld_config.py files directly, so you don't have to copy/paste them in every time you start the examples.
Expand Down
21 changes: 13 additions & 8 deletions caladan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def get_uuid(self):
api_url = self.url + "uuid?device_key=" + self.key
response = requests.get(api_url, headers=self.headers, timeout=30)
return self.status_check(response.json())


def get_position(self):
api_url = self.url + "position?device_key=" + self.key
Expand All @@ -58,14 +57,20 @@ def send_gps_goal(self, lat, lon, yaw):
timeout=10,
)
return self.status_check(response.json())
def send_waypoints(self, goals): #Expect an array of 3 entry sets

def send_waypoints(self, goals): # Expect an array of 3 entry sets
api_url = self.url + "send-waypoints?device_key=" + self.key
r = {"goals":[]}
r = {"goals": []}
for waypoint in goals:
print(json.dumps(waypoint[2]))
r["goals"].append({"lat":json.dumps(waypoint[0]),"lon":json.dumps(waypoint[1]),"yaw":json.dumps(waypoint[2])})
print (r)
r["goals"].append(
{
"lat": json.dumps(waypoint[0]),
"lon": json.dumps(waypoint[1]),
"yaw": json.dumps(waypoint[2]),
}
)
print(r)
self.headers["Content-Type"] = "application/json"
response = requests.post(
api_url,
Expand All @@ -74,15 +79,15 @@ def send_waypoints(self, goals): #Expect an array of 3 entry sets
timeout=10,
)
self.headers["Content-Type"] = "application/x-www-form-urlencoded"
return self.status_check(response.json())
return self.status_check(response.json())

def cancel_prev_goal(self):
api_url = self.url + "cancel-prev-goal?device_key=" + self.key
response = requests.post(api_url, headers=self.headers, timeout=30)
return self.status_check(response.json())


# Example Usage in
# Example Usage in
# import caladan_api
# url = "https://beta-caladan.polymathrobotics.dev/api/"
# device_key = "*******"
Expand Down
4 changes: 2 additions & 2 deletions config/farmworld_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
api_url = "https://beta-caladan.polymathrobotics.dev/api/"

# Enter your Polymath Robotics provided Bearer Token and Device Key here!
token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InIwdDRQVnowQklGVjhOSFVhbU5ISyJ9.eyJpc3MiOiJodHRwczovL3BvbHltYXRocm9ib3RpY3MudXMuYXV0aDAuY29tLyIsInN1YiI6ImdCMjhGYUFHMjRnZXdmeGlGZE9zN3REUDFTTEJROExFQGNsaWVudHMiLCJhdWQiOiJodHRwOi8vb3BlbnNpbS1jdXN0b21lci1hcGkuY29tIiwiaWF0IjoxNjYzMzUyOTAzLCJleHAiOjE2NjU5NDQ5MDMsImF6cCI6ImdCMjhGYUFHMjRnZXdmeGlGZE9zN3REUDFTTEJROExFIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwicGVybWlzc2lvbnMiOltdfQ.Ne_5v5whfH67nO-UFQg7qQMlMbFx5MHqdJEL1smjRPJ1VehFKuceq0XpW4X3v0yNgoKjzzeK1R3JQgl2pA5GoLqAbfb_holPa2UHUU8c9se5ae_300YHIENcfLpuoVob0YYGErrbzNDOzrf4w_gqf58pApQC6MoGk-ZYFIlvc60SGilhYeYfm_670hd3OAXEBsd808xngZ3P0QtEdxP66TZlXOSpaTx9ua6lcdKnwlYIAL8xUu2yECuLto7kSAQ88Ru5m8WNz4JSuxrn_YmW9WbgvCpX6D89iu3_jj119Y0W1MATdBIeVGmljIMkTXzOmlGoznkok3xn8RR2_nuSnw"
key = "ps2g9vajn"
token = "bearer_token"
key = "device_key"
29 changes: 21 additions & 8 deletions config/mineworld_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@
# Designed as a simple teaching example, not feature complete or fully robust.



# Example single goal to return to the shed
shed_goal = (37.724570, -120.998354, 0)

# Example Buttons, experiment by changing the name and location/orientations sent
button_a = ("Mine Site A", 37.725380, -120.998295, -3.14)
button_b = ("Mine Site B", 37.725189, -120.998295, -3.14)
button_c = ("Processing Plant", 37.724960, -120.998295, -3.14)
button_d = ("Bulldozer Mode", 37.72466, -120.99931, -3.14)
button_e = ("Dump Truck Mode", 37.72466, -120.99944, 0)
button_a = ("Mine Site A", 37.725103, -120.998961, 0)
button_b = ("Mine Site B", 37.724731, -120.999148, -3.14)
button_c = ("Processing Plant", 37.725324, -120.998303, 0)
button_d = ("Bulldozer Mode", 0)
button_e = ("Dump Truck Mode", 0)
button_f = ("Rotate North", 0)
button_g = ("Rotate South", 3.14)

# Moves between two mine sites
bulldoze = (
(37.724682, -120.999465, -3.14),
(37.725299, -120.999431, 0),
)

# Moves from center of the mine to processing plant
dump = (
(37.724977, -120.999469, 1.57),
(37.724834, -120.998283, -1.57),
)

# Overall size of the map, south-west corner, then north-east corner
# south-west: 37.724367, -120.999586
Expand All @@ -34,5 +47,5 @@
api_url = "https://beta-caladan.polymathrobotics.dev/api/"

# Enter your Polymath Robotics provided Bearer Token and Device Key here!
token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InIwdDRQVnowQklGVjhOSFVhbU5ISyJ9.eyJpc3MiOiJodHRwczovL3BvbHltYXRocm9ib3RpY3MudXMuYXV0aDAuY29tLyIsInN1YiI6ImdCMjhGYUFHMjRnZXdmeGlGZE9zN3REUDFTTEJROExFQGNsaWVudHMiLCJhdWQiOiJodHRwOi8vb3BlbnNpbS1jdXN0b21lci1hcGkuY29tIiwiaWF0IjoxNjY2MTMwMzQyLCJleHAiOjE2Njg3MjIzNDIsImF6cCI6ImdCMjhGYUFHMjRnZXdmeGlGZE9zN3REUDFTTEJROExFIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwicGVybWlzc2lvbnMiOltdfQ.CeCFTqqpuIoX7y6g2nDW91sznE6oejA7ohj3cDZ7IL5c9VpvW9tHgz_BynfuznPCWfg2N4BAe--AKu7ikNUfQMQJTscCMo6ZgM14z09K4jCyVDy6yxpUtXDeIq_3VXX5YiWmP3RS_1yzqeyy4IF-02GvsUX9vO8oowmNYI_dxhP5eKzLhWgerNGNlhpWwDRM6O13yrWuFzTIlijw0MxGIh50yb7CB3EfVCoCLalgLHPy_VWJL8Er4_JZMoNTE5MJKlTtCLn41Olq2PYov8TxIo0ALSjXll7Q0Z1wfBt_tl2vId9qtmXPIRPX6R7qgblfXmQ7iJMiRDQ0SquldFpHQA"
key = "ps76qow4c"
token = "bearer_token"
key = "device_key"
6 changes: 3 additions & 3 deletions config/portworld_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
button_a = ("Crane A", 37.725380, -120.998295, -3.14)
button_b = ("Crane B", 37.725189, -120.998295, -3.14)
button_c = ("Crane C", 37.724960, -120.998295, -3.14)
button_d = ("Train Load", 37.72465, -120.99914, 0)
button_d = ("Train Load", 37.72465, -120.99914, 0)
button_e = ("Train Unload", 37.72481, -120.99947, -1.57)

# Overall size of the map, south-west corner, then north-east corner
Expand All @@ -32,5 +32,5 @@
api_url = "https://beta-caladan.polymathrobotics.dev/api/"

# Enter your Polymath Robotics provided Bearer Token and Device Key here!
token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InIwdDRQVnowQklGVjhOSFVhbU5ISyJ9.eyJpc3MiOiJodHRwczovL3BvbHltYXRocm9ib3RpY3MudXMuYXV0aDAuY29tLyIsInN1YiI6ImdCMjhGYUFHMjRnZXdmeGlGZE9zN3REUDFTTEJROExFQGNsaWVudHMiLCJhdWQiOiJodHRwOi8vb3BlbnNpbS1jdXN0b21lci1hcGkuY29tIiwiaWF0IjoxNjYxNzk1NzI2LCJleHAiOjE2NjQzODc3MjYsImF6cCI6ImdCMjhGYUFHMjRnZXdmeGlGZE9zN3REUDFTTEJROExFIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwicGVybWlzc2lvbnMiOltdfQ.Ow739feiiwmyhM7KW8kzNkbZSd6u4eHsGn9Clu464baSnnlIvaCvBjWWQ7itrgTmyH2BGQm_rB5NQ1JewCkhlLkSCNaPOELk4nHksFRSPJWQG2HL5JXoOsj9FpjEKRb74WXFkXA8tJMHQ1D2-OoyspJRPiSyX664ggIKCduG69NgxSGtCBCL_n-MLX_FehAJu_O005JrnOn54CTpcum0mOXPVEJQrO_slC9NBJKqzV5q45UQzvltWk52v1_139fCZXe86e56r6OteSAhEZ7n4tOagCuP42q_GlQaIZ1-CJ7u-JBfMuVBZYZNBs6tcE_h9jgOwgzIhilkRHsH0hU5LA"
key = "ps2g9vajn"
token = "bearer_token"
key = "device_key"
Binary file added images/mineworld_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 40 additions & 8 deletions mineworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
sg.Button(mineworld_config.button_b[0]),
sg.Button(mineworld_config.button_c[0]),
],
[sg.Button(mineworld_config.button_d[0]), sg.Button(mineworld_config.button_e[0])],
[
sg.Button(mineworld_config.button_d[0]),
sg.Button(mineworld_config.button_e[0]),
sg.Button(mineworld_config.button_f[0]),
sg.Button(mineworld_config.button_g[0]),
],
]


Expand Down Expand Up @@ -109,11 +114,22 @@ def tolerance_check(goal, tol):
return False


def parking():
for goal in mineworld_config.parking_goals:
send_goal(*goal)
while not tolerance_check(goal, 0.00003):
time.sleep(0.5)
def bulldoze():
while True: # Cancelled by the STOP button, as this cancels any goal
graph_clean()
for goal in mineworld_config.bulldoze:
send_goal(*goal)
while not tolerance_check(goal, 0.00003):
time.sleep(0.5)


def dump():
while True: # Cancelled by the STOP button, as this cancels any goal
graph_clean()
for goal in mineworld_config.dump:
send_goal(*goal)
while not tolerance_check(goal, 0.00003):
time.sleep(0.5)


def graph_clean():
Expand Down Expand Up @@ -174,11 +190,27 @@ def graph_clean():

if event == mineworld_config.button_d[0]:
graph_clean()
send_goal(*mineworld_config.button_d[1:])
window.perform_long_operation(bulldoze, "-bulldoze DONE-")

if event == mineworld_config.button_e[0]:
graph_clean()
send_goal(*mineworld_config.button_e[1:])
window.perform_long_operation(dump, "-dump DONE-")

if event == mineworld_config.button_f[0]:
graph_clean()
send_goal(
mineworld_config.odom["position"]["latitude"],
mineworld_config.odom["position"]["longitude"],
mineworld_config.button_f[1],
)

if event == mineworld_config.button_g[0]:
graph_clean()
send_goal(
mineworld_config.odom["position"]["latitude"],
mineworld_config.odom["position"]["longitude"],
mineworld_config.button_g[1],
)

if event == "graph":
graph_clean()
Expand Down
4 changes: 0 additions & 4 deletions portworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ def graph_clean():
graph_clean()
send_goal(*portworld_config.shed_goal)

if event == "Parking":
graph_clean()
window.perform_long_operation(parking, "-parking DONE-")

if event == "STOP":
graph_clean()
api.cancel_prev_goal()
Expand Down
6 changes: 3 additions & 3 deletions quick_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
device_key = "psdf65eoh"
token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InIwdDRQVnowQklGVjhOSFVhbU5ISyJ9.eyJpc3MiOiJodHRwczovL3BvbHltYXRocm9ib3RpY3MudXMuYXV0aDAuY29tLyIsInN1YiI6ImdCMjhGYUFHMjRnZXdmeGlGZE9zN3REUDFTTEJROExFQGNsaWVudHMiLCJhdWQiOiJodHRwOi8vb3BlbnNpbS1jdXN0b21lci1hcGkuY29tIiwiaWF0IjoxNjYzMzUyOTAzLCJleHAiOjE2NjU5NDQ5MDMsImF6cCI6ImdCMjhGYUFHMjRnZXdmeGlGZE9zN3REUDFTTEJROExFIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwicGVybWlzc2lvbnMiOltdfQ.Ne_5v5whfH67nO-UFQg7qQMlMbFx5MHqdJEL1smjRPJ1VehFKuceq0XpW4X3v0yNgoKjzzeK1R3JQgl2pA5GoLqAbfb_holPa2UHUU8c9se5ae_300YHIENcfLpuoVob0YYGErrbzNDOzrf4w_gqf58pApQC6MoGk-ZYFIlvc60SGilhYeYfm_670hd3OAXEBsd808xngZ3P0QtEdxP66TZlXOSpaTx9ua6lcdKnwlYIAL8xUu2yECuLto7kSAQ88Ru5m8WNz4JSuxrn_YmW9WbgvCpX6D89iu3_jj119Y0W1MATdBIeVGmljIMkTXzOmlGoznkok3xn8RR2_nuSnw"

api = caladan_api.SimpleAPI(url,device_key,token)
api = caladan_api.SimpleAPI(url, device_key, token)

# print (api.get_uuid())

# print (api.send_gps_goal(37.72474,-120.998748,1.57))

goals = [[37.72474,-120.998748,0],[37.725091,-120.998712,-1.57]]
goals = [[37.72474, -120.998748, 0], [37.725091, -120.998712, -1.57]]

print (api.send_waypoints(goals))
print(api.send_waypoints(goals))

0 comments on commit 557ffeb

Please sign in to comment.