Skip to content
Snippets Groups Projects
Unverified Commit 548b938b authored by Anton Tetov Johansson's avatar Anton Tetov Johansson
Browse files

Merge remote-tracking branch 'origin/gripper'

parents 300fe9b9 2207a159
Branches
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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}')
......
......@@ -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",
......
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment