if sense: for j in range(0, cellCountY + 1, 1): plant_y = plantLength * j + pos_y moveAbs(plant_x, plant_y, pos_z + plantingRetract) moveAbs(plant_x, plant_y, pos_z) moveAbs(plant_x, plant_y, pos_z + plantingRetract) sense = 0 else: for j in range(cellCountY, -1, -1): plant_y = plantLength * j + pos_y moveAbs(plant_x, plant_y, pos_z + plantingRetract) moveAbs(plant_x, plant_y, pos_z) moveAbs(plant_x, plant_y, pos_z + plantingRetract) sense = 1 #Return seed tool to toolbay. moveAbs(plant_x, plant_y, seedToolZ) moveAbs(plant_x, seedToolY, seedToolZ) moveAbs(seedToolX, seedToolY, seedToolZ) #Seperate seed tool from arm. moveAbs(seedToolX, seedToolY, seedToolZ + 60) #Move to arm storage position. moveAbs(seedToolX, 300, safeZ) device.log('success!!', 'success', ['toast']) if __name__ == '__main__': farmware_name = 'seeding_path'
#!/usr/bin/env python '''Hello Farmware Input A simple Farmware example that tells FarmBot to log a new message including the provided input. ''' from farmware_tools import get_config_value, device INPUT_VALUE = get_config_value(farmware_name='Hello Farmware Input', config_name='input', value_type=str) device.log(message='Hello Farmware! Input was: {}'.format(INPUT_VALUE), message_type='success')
average += i average /= len(moisture_readings) device.log('Total Moisture Average: {}'.format(average), 'info') if average < THRESHOLD: device.execute(water_tool_retrieve_sequence_id) device.execute(water_sequence_id) device.execute(water_tool_return_sequence_id) PIN_LIGHTS = 7 PIN_SENSOR = 59 PIN_WATER = 8 PKG = 'Water Routine' input_errors = [] device.log('INIT') PLANT_TYPES = Qualify.get_csv(PKG, 'plant_types') #device.log('CSVs Qualified') SENSOR_Z_DEPTH = Qualify.integer(PKG, 'sensor_z_depth') Z_TRANSLATE = Qualify.integer(PKG, 'z_translate') OFFSET_X = Qualify.integer(PKG, 'offset_x') OFFSET_Y = Qualify.integer(PKG, 'offset_y') THRESHOLD = Qualify.integer(PKG, 'threshold') NUM_SITES = Qualify.integer(PKG, 'num_sites') NUM_SAMPLES = Qualify.integer(PKG, 'num_samples') #device.log('Integers Qualified') moisture_tool_retrieve_sequence_id = Qualify.sequence( PKG, 'tool_moisture_retrieve') moisture_tool_return_sequence_id = Qualify.sequence(PKG, 'tool_moisture_return') water_tool_retrieve_sequence_id = Qualify.sequence(PKG, 'tool_water_retrieve')
def set_level(level): Logger.LOGGER_LEVEL = int(level) if int(level) in [0, 1, 2, 3] else 0 device.log("[{}] LOGGER_LEVEL set to {}".format( Logger.FARMWARE_NAME, Logger.LOGGER_LEVEL))
def no_data_error(): """Send an error to the log if there's no data.""" message = '[Plot sensor data] No data available for pin {}.'.format(PIN) device.log(message, 'error')
# web-app via Logs. When the Farmware sequence is run, a start command # is sent from the Farmbot's raspberry pi to the Image processing Pi # via serial signal lines. Data generated on the IPpi is returned the # same way. #------------------------------------------------------------------------""" import os import json import time import serial import requests from time import sleep from farmware_tools import device device.log(message='Plant Charact.:', message_type='success', channels=['toast']) #def get_token(): # Inputs: # global EMAIL # EMAIL = input("FarmBot Email: ") # global PASSWORD # PASSWORD = input("WebApp Password: ") # Get your FarmBot Web App token. # headers = {'content-type': 'application/json'} # user = {'user': {'email': EMAIL, 'password': PASSWORD}} # payload = json.dumps(user) # response = requests.post('https://my.farmbot.io/api/tokens',headers=headers, data=payload) # global TOKEN # TOKEN = response.json()['token']['encoded']
#!/usr/bin/env python ''' ' Single Axis ''' import os from farmware_tools import device from farmware_tools import app from farmware_tools import get_config_value # create Celery coordinate node coord = device.assemble_coordinate(0, 0, 0) # apply currrent positions to coordinate node for axis in coord['args']: coord['args'][axis] = device.get_current_position(axis) # get the desired axis to modify and set the coordinate node to the desired value single_axis = get_config_value('Single Axis', 'axis', str).lower() coord['args'][single_axis] = int(get_config_value('Single Axis', 'pos')) #log = 'Axis: {}, Coordinate: {}'.format(single_axis, coord) log = "Moving '%s' axis to %d" % (single_axis.upper(), coord['args'][single_axis]) device.log(log, 'info', ['toast']) # perform the move device.move_absolute(coord, 100, device.assemble_coordinate(0, 0, 0))
#OBTAINING CONSTANT DATA: H**O KERNEL, CALIBRATION PARAMETERS, DESCRIPTORS dir_path = os.path.dirname(os.path.realpath(__file__)) butt_kernel = np.load(dir_path+'/'+'kernel_butt.npy') descriptors = np.load(dir_path+'/'+'all_descriptors.npy') tvec = np.load(dir_path+'/'+'tvec.npy') rmatrix = np.load(dir_path+'/'+'rmatrix.npy') intrinsics = np.load(dir_path+'/'+'nintrinsics.npy') matrix=np.load(dir_path+'/'+'array1.npy') matrix2=np.load(dir_path+'/'+'array2.npy') matrix3=np.load(dir_path+'/'+'array3.npy') matrix4=np.load(dir_path+'/'+'array4.npy') weeder=(23,551,-399) device.log(message='descriptors shape= {}'.format(descriptors.shape), message_type='success') # #MOVEMENTS #capture_pos = device.assemble_coordinate(500,400,0) #device.move_absolute(capture_pos, speed=100, offset=device.assemble_coordinate(0,0,0)) move_absolute((500,400,0),(0,0,0),100) #OBTAINING THE IMAGE img=usb_camera_photo() #img = cv2.imread(dir_path+'/'+'image_orig3.jpeg',1) #img = cv2.imread(dir_path+'/'+'image_orig3_mod.jpeg',1) #PREPROCESSING start = time()
from farmware_tools import device from farmware_tools import get_config_value import json import os evName = get_config_value(farmware_name='FarmwareEnVar', config_name='evName', value_type=str) evValue = get_config_value(farmware_name='FarmwareEnVar', config_name='evValue', value_type=str) device.log(message="Recieved environment variable name: " + str(evName) + " environment variable value: " + str(evValue), message_type="success") config = {evName: evValue} configFileName = '/tmp/farmware/config.json' # If the file exists delete it if os.path.isfile(configFileName): os.remove(configFileName) device.log(message="Config file: " + str(configFileName) + " existed so deleteing it", message_type="success") # Create a new file and load the config with open(configFileName, 'w') as f: json.dump(config, f) filepath = os.path.abspath(f.name) f.close()
#!/usr/bin/env python '''Hello Farmware A simple Farmware example that tells FarmBot to log a new message. ''' from farmware_tools import device device.log(message='Hello Farmware!', message_type='success')
descriptors = np.load(dir_path + '/' + 'all_descriptors.npy') tvec = np.load(dir_path + '/' + 'tvec.npy') rmatrix = np.load(dir_path + '/' + 'rmatrix.npy') intrinsics = np.load(dir_path + '/' + 'nintrinsics.npy') matrix = np.load(dir_path + '/' + 'array1.npy') matrix2 = np.load(dir_path + '/' + 'array2.npy') matrix3 = np.load(dir_path + '/' + 'array3.npy') matrix4 = np.load(dir_path + '/' + 'array4.npy') weeder = (33, 554, -401) gripper_pin = 4 gripper_down = 0 gripper_up = 1 device.set_pin_io_mode(1, gripper_pin) device.log(message='descriptors shape= {}'.format(descriptors.shape), message_type='success') # #MOVEMENTS #capture_pos = device.assemble_coordinate(500,400,0) #device.move_absolute(capture_pos, speed=100, offset=device.assemble_coordinate(0,0,0)) #move_absolute((500,400,0),(0,0,0),100) start_totalproc = time() #OBTAINING THE IMAGE img = usb_camera_photo() #img = cv2.imread(dir_path+'/'+'image_orig3.jpeg',1) #img = cv2.imread(dir_path+'/'+'image_orig3_mod.jpeg',1) """ #PREPROCESSING
#!/usr/bin/env python """Move Relative Farmware""" from farmware_tools import device from farmware_tools import get_config_value # Load inputs from Farmware page widget specified in manifest file x_dist = get_config_value('Move Relative', 'rel_x') y_dist = get_config_value('Move Relative', 'rel_y') z_dist = get_config_value('Move Relative', 'rel_z') device.log('starting! ' + str(x_dist), 'success', ['toast']) device.move_relative(x_dist, y_dist, z_dist, 100) device.log('ending!', 'success', ['toast']) if __name__ == '__main__': farmware_name = 'move_relative'
image[:, :] = (randrange(256), randrange(256), randrange(256)) filename_path = upload_path(image_filename()) # Save the image to file cv2.imwrite(filename_path, image) print('Image saved: {}'.format(filename_path)) device.log('Image saved: {}'.format(filename_path), 'debug') if __name__ == '__main__': X_SIZE = get_config_value('Fake-Camera', 'x_size') Y_SIZE = get_config_value('Fake-Camera', 'y_size') # Verify user inputs if X_SIZE < 1: device.log( 'Width must be positive (used {})! Abort fake camera farmware'. format(X_SIZE), 'error') sys.exit(1) elif Y_SIZE < 1: device.log( 'Height must be positive (used {})! Abort fake camera farmware'. format(Y_SIZE), 'error') sys.exit(1) elif X_SIZE > 4096: # Greater than 4K resolution device.log( 'Width is too big, it\'s not a good idea (used {})! Abort fake camera farmware' .format(X_SIZE), 'error') sys.exit(1) elif Y_SIZE > 4096: # Greater than 4K resolution device.log( 'Height is too big, it\'s not a good idea (used {})! Abort fake camera farmware'
def log(message, message_type): 'Send a log message.' device.log('[take-photo] {}'.format(message), message_type)
#!/usr/bin/env python '''Hello Farmware A simple Farmware example that tells FarmBot to log a new message. ''' from farmware_tools import device from farmware_tools import app '''def keepValues(input): device.log(input) return input.get("value")''' device.log(message='Hello world 21', message_type='success') #res = device.read_pin(59, "Soil sensor", 1) #device.log(message=str(res), message_type="info") res2 = app.get("sensor_readings") #device.log(message=str(res2), message_type="info") tabValues = [] for input in res2: tabValues.append(input.get("value")) #device.log(message=str(input.get("value")), message_type="info") device.log(message=str(tabValues), message_type="info") device.log(message='Fin hello farmware', message_type='success')
#!/usr/bin/env python from farmware_tools import app from farmware_tools import device from farmware_tools import env from farmware_tools import get_config_value try: #device.move_absolute(location=device.assemble_coordinate(100, 50, 0), speed=100, offset=device.assemble_coordinate(0, 0, 0)) device.move_absolute(device.assemble_coordinate(100, 100, 0), 100, device.assemble_coordinate(0, 0, 0)) INPUT_VALUE = get_config_value(farmware_name="Hello Farmware Input", config_name="input", value_type=str) device.log(message="Hello Farmware! Input was: {}".format(INPUT_VALUE), message_type="success") except Exception as error: device.log(repr(error))