diff --git a/src/gripper.py b/src/gripper.py index aff5b9c44be8359d8ab606b02d396094f67e33ce..27b72215533b7f2414874aca6fb8068055dd86e7 100755 --- a/src/gripper.py +++ b/src/gripper.py @@ -2,9 +2,9 @@ TODO: Integrate with FarmbotClient or FarmbotYoloClient """ -from client import FarmbotClient -from creds import device_id -from creds import token +from utils.client import FarmbotClient +from utils.creds import device_id +from utils.creds import token GRIPPER_PIN = 12 GRIPPER_OPEN_STATE = 0 diff --git a/src/main.py b/src/main.py index c68b26834577376f28ee6adbdeb8bf66f9ee69db..d719b2a8023d4f8d9747b4c0ec0a6f81bd68707e 100644 --- a/src/main.py +++ b/src/main.py @@ -48,7 +48,6 @@ def remove_overlap(table_coordinate:DataFrame, tolerance=50.00)->DataFrame: return table_coordinate - def remove_temp(path: Path)-> None: ''' Clean temporary files, i.e., photos, location.txt, annotations diff --git a/src/move.py b/src/move.py index 3768b918c06a894d58bd0311faac64012f0eed35..afa038ffd45ee74d472ff4473201a08e631858fc 100644 --- a/src/move.py +++ b/src/move.py @@ -8,6 +8,7 @@ Note: it is for remote server, can ben replaced by a local script from argparse import ArgumentParser from logging import getLogger from os import path, makedirs, system +import sys from time import sleep, strftime, time #from serial import Serial, PARITY_NONE, STOPBITS_ONE, EIGHTBITS from requests.api import delete @@ -20,8 +21,8 @@ from datetime import timezone, datetime from dateutil.parser import parse from requests import get, delete -import creds -from client import FarmbotClient +import utils.creds as creds +from utils.client import FarmbotClient _SWEEEP_HEIGHT = 0 @@ -40,7 +41,7 @@ class Opts: def scan(img_path: Path, location_path: Path, # smaller delta - min_x=0, max_x=1300, min_y=0, max_y=1000, delta=1000, offset=0, flag=True) -> List: #里面的数字需要重新测量 + min_x=0, max_x=1175, min_y=0, max_y=974, delta=300, offset=0, flag=True) -> List: #里面的数字需要重新测量 ''' scan the bed at a certain height, first move along x axis, then y, like a zig zag; Taking pictures and record the location of the camera that corresponds to the picture @@ -76,7 +77,8 @@ def scan(img_path: Path, location_path: Path, # smaller delta client.move(0, 0, _SWEEEP_HEIGHT) # ensure moving from original for x, y in pts: client.move(x, y, _SWEEEP_HEIGHT) # move camera - take_photo(img_path) + #take_photo(img_path) + client.take_photo() client.shutdown() # write to img/location with open(path.join(location_path, "location.txt"), 'w') as f: @@ -85,14 +87,21 @@ def scan(img_path: Path, location_path: Path, # smaller delta return None -def take_photo(img_path: Path): - HERE = path.dirname(__file__) - IMG_DIR = path.join(HERE, img_path) +def take_photo(): + client = FarmbotClient(creds.device_id, creds.token) + client.take_photo() + # download image + system('python ./utils/download.py') + + +# def take_photo(img_path: Path): +# HERE = path.dirname(__file__) +# IMG_DIR = path.join(HERE, img_path) - with request.urlopen('http://localhost:8080/?action=snapshot') as photo: - filename = datetime.now().strftime("%Y-%m-%dT%H:%M:%S") + ".jpg" - with open(path.join(IMG_DIR, filename), mode="wb") as save_file: - save_file.write(photo.read()) +# with request.urlopen('http://localhost:8080/?action=snapshot') as photo: +# filename = datetime.now().strftime("%Y-%m-%dT%H:%M:%S") + ".jpg" +# with open(path.join(IMG_DIR, filename), mode="wb") as save_file: +# save_file.write(photo.read()) def simple_move(x: int, y: int, z: int) -> None: @@ -145,12 +154,14 @@ if __name__ == '__main__': destination_x = int(input('X:')) destination_y = int(input('Y:')) destination_z = int(input('Z:')) - photo = True if input('Take a photo or not?[Y/N]:') == 'Y' else False simple_move_start = time() - simple_move(destination_x, destination_y, destination_z, photo) + simple_move(destination_x, destination_y, destination_z) Logger.info(f'time cost {time()-simple_move_start}') elif arguments.mode == 2: scan(arguments.photo, arguments.locations, flag=False) + #take_photo(arguments.photo) + elif arguments.mode == 3: + take_photo() else: Logger.error('Wrong mode number {arguments.mode}') diff --git a/src/client.py b/src/utils/client.py similarity index 96% rename from src/client.py rename to src/utils/client.py index 22f34607d44c4b73a66ebc2fff10fcbf865dc4d7..8768294e2024a1470054068fbbb991d74c1cef33 100755 --- a/src/client.py +++ b/src/utils/client.py @@ -33,12 +33,12 @@ def read_pin_request(pin_number, pin_mode="digital"): return {"kind": "rpc_request", "args": {"label": ""}, - "body": [{"kind": "read_pin" + "body": [{"kind": "read_pin", "args": { "label": "pin" + str(pin_number), "pin_mode": modes[pin_mode] or (modes["digital"]), "pin_number": pin_number - } + }}]} def write_pin_request(pin_number, pin_value, pin_mode="digital"): modes = {"digital": 0, "analog": 1} @@ -58,7 +58,7 @@ def write_pin_request(pin_number, pin_value, pin_mode="digital"): ] } -def toggle_pin_request(pin_number) +def toggle_pin_request(pin_number): return {"kind": "rpc_request", "args": {"label": ""}, "body": [{"kind": "toggle_pin", diff --git a/src/request_token.py b/src/utils/request_token.py similarity index 100% rename from src/request_token.py rename to src/utils/request_token.py