def move_absolute_point(self, point): move_offset_x = (0 if self.config["move_offset_x"] is None else self.config["move_offset_x"]) move_offset_y = (0 if self.config["move_offset_y"] is None else self.config["move_offset_y"]) move_z = 0 if self.config["move_z"] is None else self.config["move_z"] point_desc = ("{} of type {}".format( point["name"], point["pointer_type"]) if "name" in point else "") log( "Move absolute to {} ({}, {}) with offset ({}, {}) and move_z {}". format(point_desc, point["x"], point["y"], move_offset_x, move_offset_y, move_z), title="move_absolute_point", ) if Logger.LOGGER_LEVEL < 2: device.move_absolute( location=device.assemble_coordinate(point["x"], point["y"], move_z), offset=device.assemble_coordinate(move_offset_x, move_offset_y, 0), speed=self.config["move_speed"], )
def moveto_smart(self, target: Union[Coordinate, Tool, Dict[str, int]], speed: int = 100, offset_x: int = 0, offset_y: int = 0, offset_z: int = 0, travel_height: Optional[int] = 0, proximity_range: int = 20) -> Coordinate: """ Perform a smart movement to the given point. :returns The previous position """ position = self.bot_state().location_data.position if not self.debug: if isinstance(target, Tool): target = self.get_toolslots(tool_id=target.id)[0] if not isinstance(target, Coordinate): target = position.merge(target) if (travel_height is not None) and (travel_height > position.z or travel_height > target.z) and ( abs(position.x - target.x) > proximity_range or abs(position.y - target.y) > proximity_range): # travel height must be respected if target.z + offset_z > travel_height: travel_height = target.z + offset_z device.move_relative(0, 0, travel_height - position.z, speed) device.move_absolute(target.merge({'z': travel_height}).to_coordinate(), speed, device.assemble_coordinate(offset_x, offset_y, 0)) if abs((target.z + offset_z) - travel_height) <= 2: return position device.move_absolute(target.to_coordinate(), speed, device.assemble_coordinate(offset_x, offset_y, offset_z)) return position
alternateInBetweenGrid1 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='alternateInBetweenGrid1', value_type=int) startLastRowOfGrid1 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='startLastRowOfGrid1', value_type=int) rowsGrid2 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='rowsGrid2', value_type=int) colsGrid2 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='colsGrid2', value_type=int) spaceBetweenRowsGrid2 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='spaceBetweenRowsGrid2', value_type=float) spaceBetweenColsGrid2 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='spaceBetweenColsGrid2', value_type=float) startXGrid2 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='startXGrid2', value_type=float) startYGrid2 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='startYGrid2', value_type=float) startZGrid2 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='startZGrid2', value_type=float) alternateInBetweenGrid2 = get_config_value(farmware_name='Grid2Grid30Sec', config_name='alternateInBetweenGrid2', value_type=int) device.log(message='Done params', message_type='success') device.move_absolute( device.assemble_coordinate(100, 100, 0), 100, device.assemble_coordinate(0, 0, 0)) # Initialise row (X) and column (Y) indexes for all grids rowGrid1Index = 0 colGrid1Index = 0 rowGrid2Index = 0 colGrid2Index = 0 # Initialise the current Position Found flags to not found currentPositionGrid1Found = False currentPositionGrid2Found = False # Set constant Z positions zPosGrid1 = startZGrid1
def __init__(self, x=0, y=0, z=0, ox=0, oy=0, oz=0, speed=100): self.coordinate_node = device.assemble_coordinate(x, y, z) self.offset_node = device.assemble_coordinate(ox, oy, oz) self.speed = speed
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 Test', config_name='input', value_type=str) device.log(message='Hello Farmware! Test input was: {}'.format( INPUT_VALUE), message_type='success') device.log(message="Message 1 Test", message_type="success") device.log(message="Message 2 Test", message_type="success") device.log(message="Message 3 Test", message_type="success") device.log(message="Message 4 Test", message_type="success") device.log(message="Message 5 Test", message_type="success") zero = device.assemble_coordinate(0, 0, 0) one = device.assemble_coordinate(10, 10, 0) two = device.assemble_coordinate(20, 20, 0) three = device.assemble_coordinate(30, 30, 0) four = device.assemble_coordinate(40, 40, 0) five = device.assemble_coordinate(50, 50, 0) device.move_absolute(one, 100, zero) device.move_absolute(two, 100, zero) device.move_absolute(three, 100, zero) device.move_absolute(four, 100, zero) device.move_absolute(five, 100, zero)
def to_coordinate(self) -> Dict[str, Any]: return device.assemble_coordinate(self.x, self.y, self.z)
#!/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))
def run_tests(TEST, app_login): 'Run device tests.' COORDINATE = device.assemble_coordinate(1, 0, 1) OFFSET = device.assemble_coordinate(0, 0, 0) URL = 'https://raw.githubusercontent.com/FarmBot-Labs/farmware_manifests/' \ 'master/packages/take-photo/manifest.json' app.post('sequences', {'name': 'test', 'body': []}, get_info=app_login) SEQUENCE = app.find_sequence_by_name(name='test', get_info=app_login) TESTS = [ {'command': device.log, 'kwargs': {'message': 'hi'}}, {'command': device.log, 'kwargs': {'message': 'hi', 'channels': ['toast']}}, {'command': device.log, 'kwargs': {'message': 'hi', 'rpc_id': 'abcd'}}, {'command': device.check_updates, 'kwargs': {'package': 'farmbot_os'}}, {'command': device.emergency_lock, 'kwargs': {}, 'expected': {'status': [{ 'keys': ['informational_settings', 'locked'], 'value': True}]}}, {'command': device.emergency_unlock, 'kwargs': {}, 'expected': {'log': ['F09'], 'status': [{ 'keys': ['informational_settings', 'locked'], 'value': False}]}}, {'command': device.execute, 'kwargs': {'sequence_id': SEQUENCE}}, {'command': device.execute_script, 'kwargs': { 'label': 'take-photo', 'inputs': {'input_1': 1, 'take_photo_input_2': 'two'}}}, {'command': device.run_farmware, 'kwargs': {'label': 'take-photo'}}, {'command': device.find_home, 'kwargs': {'axis': 'y'}, 'expected': {'log': ['F12']}}, {'command': device.home, 'kwargs': {'axis': 'z'}, 'expected': {'log': ['G00 Z0']}}, {'command': device.install_farmware, 'kwargs': {'url': URL}}, {'command': device.install_first_party_farmware, 'kwargs': {}}, {'command': device.move_absolute, 'kwargs': {'location': COORDINATE, 'speed': 100, 'offset': OFFSET}, 'expected': {'log': ['G00 X1.0 Y0.0 Z1.0']}}, {'command': device.move_relative, 'kwargs': {'x': -1, 'y': 0, 'z': -1, 'speed': 100}, 'expected': {'log': ['G00 X0.0 Y0.0 Z0.0']}}, {'command': device.read_pin, 'kwargs': {'pin_number': 1, 'label': 'label', 'pin_mode': 0}, 'expected': {'log': ['F42 P1 M0']}}, {'command': device.read_status, 'kwargs': {}}, {'command': device.remove_farmware, 'kwargs': {'package': 'farmware'}}, {'command': device.set_pin_io_mode, 'kwargs': {'pin_io_mode': 0, 'pin_number': 47}, 'expected': {'log': ['F43 P47 M0']}}, {'command': device.set_servo_angle, 'kwargs': {'pin_number': 4, 'pin_value': 1}, 'expected': {'log': ['F61 P4 V1']}}, {'command': device.set_user_env, 'kwargs': {'key': 'test_key', 'value': 1}}, {'command': device.sync, 'kwargs': {}, 'expected': {'status': [{ 'keys': ['informational_settings', 'sync_status'], 'value': 'synced'}]}}, {'command': device.take_photo, 'kwargs': {}}, {'command': device.toggle_pin, 'kwargs': {'pin_number': 1}, 'expected': {'log': ['F41 P1 V']}}, {'command': device.update_farmware, 'kwargs': {'package': 'take-photo'}}, {'command': device.wait, 'kwargs': {'milliseconds': 100}}, {'command': device.write_pin, 'kwargs': {'pin_number': 1, 'pin_value': 1, 'pin_mode': 0}, 'expected': {'log': ['F41 P1 V1 M0'], 'status': [{ 'keys': ['pins', '1', 'value'], 'value': 1}]}}, {'command': device.zero, 'kwargs': {'axis': 'y'}, 'expected': {'log': ['F84 Y1'], 'status': [ {'keys': ['location_data', 'position', 'y'], 'value': 0}, {'keys': ['location_data', 'scaled_encoders', 'y'], 'value': 0} ]}}, ] TEST.setup() for test in TESTS: try: _rpc_id = test['kwargs'].pop('rpc_id') except KeyError: _rpc_id = None print() time.sleep(3) TEST.test(test['command'](**test['kwargs'])['command'], rpc_id=_rpc_id, expected=test.get('expected')) print('=' * 20) TEST.print_elapsed_time() print() TEST.teardown() TEST.print_summary()
def move_absolute(position,offset,speed): as_position= device.assemble_coordinate(position[0],position[1],position[2]) as_offset=device.assemble_coordinate(offset[0],offset[1],offset[2]) device.move_absolute(as_position, speed=speed, offset=as_offset)
#!/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))