fixed missing api calls and documentation
This commit is contained in:
parent
c515c0062b
commit
d58a41da69
6 changed files with 82 additions and 30 deletions
|
@ -34,7 +34,7 @@ fpm -s python --python-bin python3 --python-pip pip3 --python-package-name-prefi
|
||||||
-d "python3-pigpio" \
|
-d "python3-pigpio" \
|
||||||
-d "python3-numpy" \
|
-d "python3-numpy" \
|
||||||
-d "ffmpeg" \
|
-d "ffmpeg" \
|
||||||
-v 0.2.2-0 -t deb setup.py
|
-v 0.2.3-0 -t deb setup.py
|
||||||
|
|
||||||
# --deb-changelog changelog \
|
# --deb-changelog changelog \
|
||||||
# --deb-upstream-changelog changelog \
|
# --deb-upstream-changelog changelog \
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Seeding:
|
||||||
return result, res.status_code
|
return result, res.status_code
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getCargo(color: str) -> Tuple[Dict, int]:
|
def get_cargo(color: str) -> Tuple[Dict, int]:
|
||||||
"""Makes the /api/listCargo call to the api.
|
"""Makes the /api/listCargo call to the api.
|
||||||
|
|
||||||
:param color: Color parameter which specifies which cargo should be taken. (A string which is either "green", "red", "yellow" or "blue"
|
:param color: Color parameter which specifies which cargo should be taken. (A string which is either "green", "red", "yellow" or "blue"
|
||||||
|
@ -110,7 +110,7 @@ class DoubleElim:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_position() -> Tuple[Position, int]:
|
def get_position() -> Tuple[Position, int]:
|
||||||
"""Get position of the robot
|
"""Makes the /api/getPos call to the api.
|
||||||
|
|
||||||
:return: A Position object with robot position
|
:return: A Position object with robot position
|
||||||
:rtype: Tuple[Position, int]
|
:rtype: Tuple[Position, int]
|
||||||
|
@ -127,7 +127,7 @@ class DoubleElim:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_opponent() -> Tuple[Position, int]:
|
def get_opponent() -> Tuple[Position, int]:
|
||||||
"""Get position of the opponents robot
|
"""Makes the /api/getOp call to the api.
|
||||||
|
|
||||||
:return: A Position object with opponents robot position
|
:return: A Position object with opponents robot position
|
||||||
:rtype: Tuple[Position, int]
|
:rtype: Tuple[Position, int]
|
||||||
|
@ -144,7 +144,7 @@ class DoubleElim:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_goal() -> Tuple[Position, int]:
|
def get_goal() -> Tuple[Position, int]:
|
||||||
"""Get position of the goal
|
"""Makes the /api/getGoal call to the api.
|
||||||
|
|
||||||
:return: A Position object with x and y coordinates of the goal, rotation is always -1
|
:return: A Position object with x and y coordinates of the goal, rotation is always -1
|
||||||
:rtype: Tuple[Position, int]
|
:rtype: Tuple[Position, int]
|
||||||
|
@ -161,7 +161,7 @@ class DoubleElim:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_items() -> Tuple[List[Dict], int]:
|
def get_items() -> Tuple[List[Dict], int]:
|
||||||
"""Get a list with all current items
|
"""Makes the /api/getItems call to the api.
|
||||||
|
|
||||||
:return: A list will all items currently on the game field. Items are dictionaries that look like: {"id": 0, "x": 0, "y": 0}
|
:return: A list will all items currently on the game field. Items are dictionaries that look like: {"id": 0, "x": 0, "y": 0}
|
||||||
:rtype: Tuple[List[Dict], int]
|
:rtype: Tuple[List[Dict], int]
|
||||||
|
@ -178,7 +178,7 @@ class DoubleElim:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_scores() -> Tuple[Dict, int]:
|
def get_scores() -> Tuple[Dict, int]:
|
||||||
"""Get the current scores
|
"""Makes the /api/getScores call to the api.
|
||||||
|
|
||||||
:return: A dictionary with all scores included like: {"self":2,"opponent":0}
|
:return: A dictionary with all scores included like: {"self":2,"opponent":0}
|
||||||
:rtype: Tuple[Dict, int]
|
:rtype: Tuple[Dict, int]
|
||||||
|
@ -192,3 +192,20 @@ class DoubleElim:
|
||||||
response = json.loads(res.content)
|
response = json.loads(res.content)
|
||||||
Logging.get_logger().debug(f"DoubleElim.get_scores = {response}, status code = {res.status_code}")
|
Logging.get_logger().debug(f"DoubleElim.get_scores = {response}, status code = {res.status_code}")
|
||||||
return response, res.status_code
|
return response, res.status_code
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_meteoroid() -> Tuple[Dict, int]:
|
||||||
|
"""Makes the /api/getMeteoroid call to the api.
|
||||||
|
|
||||||
|
:return: A dictionary with all scores included like: {"self":2,"opponent":0}
|
||||||
|
:rtype: Tuple[Dict, int]
|
||||||
|
"""
|
||||||
|
res = requests.get(API_URL_GET_METEOROID)
|
||||||
|
if res.status_code == 408:
|
||||||
|
Logging.get_logger().error(f"DoubleElim.get_meteoroid timeout!")
|
||||||
|
time.sleep(0.01)
|
||||||
|
return DoubleElim.get_scores()
|
||||||
|
|
||||||
|
response = json.loads(res.content)
|
||||||
|
Logging.get_logger().debug(f"DoubleElim.get_meteoroid = {response}, status code = {res.status_code}")
|
||||||
|
return response, res.status_code
|
|
@ -1,4 +1,4 @@
|
||||||
__version__ = "0.2.2-0"
|
__version__ = "0.2.3-0"
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
import compLib.LogstashLogging
|
import compLib.LogstashLogging
|
||||||
|
|
|
@ -23,7 +23,7 @@ copyright = '2021, robo4you'
|
||||||
author = 'robo4you'
|
author = 'robo4you'
|
||||||
|
|
||||||
# The full version, including alpha/beta/rc tags
|
# The full version, including alpha/beta/rc tags
|
||||||
release = '0.0.2'
|
release = '0.2.3'
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -32,31 +32,31 @@ Calling Seeding API
|
||||||
|
|
||||||
from compLib.Api import Seeding
|
from compLib.Api import Seeding
|
||||||
|
|
||||||
park, code = Seeding.get_park()
|
zones, code = Seeding.get_delivery()
|
||||||
if code == 403:
|
if code == 403:
|
||||||
print(f"I am not in the correct zone to make that request!")
|
print(f"I am not in the correct zone to make that request!")
|
||||||
else:
|
else:
|
||||||
park = park["id"]
|
print(f"First we need to go to zone {zone[0]}")
|
||||||
print(f"I should move to parking position: {park}")
|
# put code here to follow line and drive to the zone
|
||||||
|
print(f"Now we need to go to zone {zone[1]}")
|
||||||
|
# put code here to follow line and drive to the next zone
|
||||||
|
print(f"Now we need to go to zone {zone[2]}")
|
||||||
|
# put code here to follow line and drive to the last zone
|
||||||
|
print(f"We delivered all packages, hopefully we scored some points!")
|
||||||
|
|
||||||
if park == 0:
|
.. code-block:: python
|
||||||
print(f"I can't move to this position yet :(")
|
|
||||||
elif park == 1:
|
|
||||||
print(f"Moving to position 1!")
|
|
||||||
# drive to parking position using Motors module...
|
|
||||||
print(f"Now hopefully at position 1")
|
|
||||||
# drive back using Motors module...
|
|
||||||
elif park == 2:
|
|
||||||
# do something similar to park == 1..
|
|
||||||
elif park == 3:
|
|
||||||
# do something similar to park == 1..
|
|
||||||
|
|
||||||
success = Seeding.pay_park()
|
from compLib.Api import Seeding
|
||||||
# check which code the api returned
|
|
||||||
if success == 204:
|
package, code = Seeding.get_cargo("yellow")
|
||||||
print(f"We scored some points!")
|
if code == 403:
|
||||||
else:
|
print(f"I am not in the correct zone to make that request!")
|
||||||
print(f"We failed :(")
|
elif code == 404:
|
||||||
|
print(f"I am in the correct zone, but there is no yellow package here.")
|
||||||
|
elif code == 413:
|
||||||
|
print(f"I am in the correct zone, but I already have two packages loaded.")
|
||||||
|
else code == 200:
|
||||||
|
print(f"The {package['color']} has been picked up!")
|
||||||
|
|
||||||
Calling Double Elimination API
|
Calling Double Elimination API
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
@ -70,3 +70,38 @@ Calling Double Elimination API
|
||||||
|
|
||||||
goal, status = DoubleElim.get_goal()
|
goal, status = DoubleElim.get_goal()
|
||||||
print(f"Goal is at: x={goal.x}, y={goal.y}, the server responded with status code: {status}")
|
print(f"Goal is at: x={goal.x}, y={goal.y}, the server responded with status code: {status}")
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from compLib.Api import DoubleElim
|
||||||
|
import time
|
||||||
|
|
||||||
|
# function which waits for the game to be started (you should include this in your double elimination program)
|
||||||
|
def wait_for_start():
|
||||||
|
_, status = DoubleElim.get_position()
|
||||||
|
while status == 503:
|
||||||
|
time.sleep(0.1)
|
||||||
|
_, status = DoubleElim.get_position()
|
||||||
|
|
||||||
|
wait_for_start()
|
||||||
|
print(f"Game has started, lets score some points!!")
|
||||||
|
|
||||||
|
position, status = DoubleElim.get_position()
|
||||||
|
print(f"Position of my robot is: x={position.x}, y={position.y} and rotation is: {position.degrees}, the server responded with status code: {status}")
|
||||||
|
|
||||||
|
opponent_position, status = DoubleElim.get_opponent()
|
||||||
|
print(f"Position of the opponents robot is: x={opponent_position.x}, y={opponent_position.y} and rotation is: {opponent_position.degrees}, the server responded with status code: {status}")
|
||||||
|
|
||||||
|
goal, status = DoubleElim.get_goal()
|
||||||
|
print(f"Goal is at: x={goal.x}, y={goal.y}, the server responded with status code: {status}")
|
||||||
|
|
||||||
|
items, status = DoubleElim.get_items()
|
||||||
|
print(f"There are currently {len(items)} on the gameboard: {items}, the server responded with status code: {status}")
|
||||||
|
|
||||||
|
score, status = DoubleElim.get_score()
|
||||||
|
print(f"The current score of the game is {score}, the server responded with status code: {status}")
|
||||||
|
|
||||||
|
meteoroids, status = DoubleElim.get_meteoroid()
|
||||||
|
print(f"The current meteoroids in the game are {meteoroids}, the server responded with status code: {status}")
|
||||||
|
|
||||||
|
In this second example we wait until the game is started by the judges and then make all possible requests once. You should use the wait_for_start function in your double elimination program. If your robot starts too soon your run will not count!
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -12,7 +12,7 @@ else:
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="complib",
|
name="complib",
|
||||||
version="0.2.2-0",
|
version="0.2.3-0",
|
||||||
author="F-WuTs",
|
author="F-WuTs",
|
||||||
author_email="--",
|
author_email="--",
|
||||||
description="",
|
description="",
|
||||||
|
|
Reference in a new issue