diff --git a/src/creds.py b/src/creds.py new file mode 100644 index 0000000000000000000000000000000000000000..f1d436c094fadcb7cabee25a930c8845a99c5fe3 --- /dev/null +++ b/src/creds.py @@ -0,0 +1,2 @@ +device_id="***REMOVED***" +token=***REMOVED*** diff --git a/src/main.py b/src/main.py index ba5dc8adb13f7a695c6ee730ebe7458ffafa07c4..d33fc3b8378bdad6605718becb488b1d534a2f76 100644 --- a/src/main.py +++ b/src/main.py @@ -8,6 +8,7 @@ from logging import StringTemplateStyle import os from pathlib import Path from typing import Tuple +from numpy import sqrt from pandas import DataFrame from move import * @@ -16,14 +17,33 @@ from location import * _Log = getLogger(__name__) +GRIP_Z = -200 # measure! +SCAN_Z = -100 + def remove_overlap(table_coordinate:DataFrame, tolerance=50.00)->DataFrame: ''' compare every two coordinates, if their Euclidean distance is smaller than tolerance , delete the one with lower probability + + Choose a reasonable tolerance!! + :param table_coordinate: pandas dataframe that each row corresponds to a target [class, x, y, confidence] + :param tolerance: a distance threshold ''' # 这又要求重写前面的了,加入 probability - return table_coordinate + num_coordinates, num_col = table_coordinate.shape + for i in range(num_coordinates-1): + x, y, confidence = table_coordinate.loc[i, ['x','y', 'confidence']] + for j in range(i+1, num_coordinates): + x_j, y_j, confidence_j = table_coordinate.loc[j, ['x','y', 'confidence']] + distance = sqrt((x-x_j)*(x-x_j)+(y-y_j)*(y-y_j)) # 用map优化? + if distance <= tolerance: + if confidence < confidence_j: + table_coordinate.drop(i) + else: + table_coordinate.drop(j) + return table_coordinate + # 还要定期清理掉img下所有文件 def remove_temp(): @@ -38,15 +58,24 @@ def main(args: Namespace): # calculate locations list_global_coordinate = cal_location() # choose class - table_global_coordinate = DataFrame(list_global_coordinate, columns=['class', 'x', 'y']) - goal_class = list_global_coordinate[table_global_coordinate['class']==args.category] - # 添加一个if判断,如果该类为空,则显示 + table_global_coordinate = DataFrame(list_global_coordinate, columns=['class', 'x', 'y', 'confidence']) # remove overlap - - # move - - # grip - + table_global_coordinate = remove_overlap(table_global_coordinate) + goal_class = table_global_coordinate[table_global_coordinate['class']==args.category] + # if there is no desiered class og plants + if goal_class.empty: + _LOG.info("There is no {}".format(args.category)) + # move and grip + num_goals, num_col = goal_class.shape + for i in range(num_goals): + x, y = goal_class.loc[i, ['x','y']] + simple_move(x, y, GRIP_Z, False) + gripper(True) + gripper(False) # 如何保证每次gripper都是开着的? + # 等待若干秒 + # 回原点 + simple_move(x, y, GRIP_Z, False) + gripper(True) # clean temporary files if all the previous step work return diff --git a/src/move.py b/src/move.py index 32efa824a47eb09562a46c8f75670dccbbe842a6..26fc55550d800e6d5b0f8b0481b4c35abfd04f4a 100644 --- a/src/move.py +++ b/src/move.py @@ -5,12 +5,11 @@ This script is for all the functions that drive Farmbot to Move, including: 3. Sweep the planting bed 4. Grip a target 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 from time import sleep, time -from serial import Serial, PARITY_NONE, STOPBITS_ONE, EIGHTBITS +#from serial import Serial, PARITY_NONE, STOPBITS_ONE, EIGHTBITS # from requests.api import delete from typing import List from pathlib import Path @@ -124,7 +123,7 @@ def download_images() -> Path: return local_img_dir -def simple_move(x: int, y: int, z: int, photo: bool) -> None: +def simple_move(x: int, y: int, z: int, photo: bool) -> None: ''' Move to a place, if flag is true, take a picture Input: x, y,z: destination point