Skip to content

Commit 5456a47

Browse files
Juliana MashonJuliana Mashon
Juliana Mashon
authored and
Juliana Mashon
committed
Bookmark
1 parent 292ea5f commit 5456a47

File tree

3 files changed

+102
-40
lines changed

3 files changed

+102
-40
lines changed

api_functions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def __init__(self):
88
self.echo = True
99
self.verbose = True
1010

11-
def return_config(self, return_value):
11+
def return_config(self, return_value): # TODO: which functions return json()
1212
"""Configure echo and verbosity of function returns."""
1313

1414
if self.echo is True and self.verbose is True:

broker_functions.py

+101-36
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self):
2121
self.echo = True
2222
self.verbose = True
2323

24-
def return_config(self, return_value):
24+
def return_config(self, return_value): # TODO: which functions return json()
2525
"""Configure echo and verbosity of function returns."""
2626

2727
if self.echo is True and self.verbose is True:
@@ -369,6 +369,104 @@ def off(self, id):
369369
self.control_peripheral(id, 0)
370370
# return ...
371371

372+
## RESOURCES
373+
374+
# TODO: sort(points, method) --> API? --> order group of points according to chosen method
375+
376+
# def sort(tray, tray_cell):
377+
# cell = tray_cell.upper()
378+
# seeder_needle_offset = 17.5
379+
# cell_spacing = 12.5
380+
381+
# cells = {
382+
# "A1": {"label": "A1", "x": 0, "y": 0},
383+
# "A2": {"label": "A2", "x": 0, "y": 1},
384+
# "A3": {"label": "A3", "x": 0, "y": 2},
385+
# "A4": {"label": "A4", "x": 0, "y": 3},
386+
# "B1": {"label": "B1", "x": -1, "y": 0},
387+
# "B2": {"label": "B2", "x": -1, "y": 1},
388+
# "B3": {"label": "B3", "x": -1, "y": 2},
389+
# "B4": {"label": "B4", "x": -1, "y": 3},
390+
# "C1": {"label": "C1", "x": -2, "y": 0},
391+
# "C2": {"label": "C2", "x": -2, "y": 1},
392+
# "C3": {"label": "C3", "x": -2, "y": 2},
393+
# "C4": {"label": "C4", "x": -2, "y": 3},
394+
# "D1": {"label": "D1", "x": -3, "y": 0},
395+
# "D2": {"label": "D2", "x": -3, "y": 1},
396+
# "D3": {"label": "D3", "x": -3, "y": 2},
397+
# "D4": {"label": "D4", "x": -3, "y": 3}
398+
# }
399+
400+
# # Checks
401+
# if tray["pointer_type"] != "ToolSlot":
402+
# print("Error: Seed Tray variable must be a seed tray in a slot")
403+
# return
404+
# elif cell not in cells:
405+
# print("Error: Seed Tray Cell must be one of **A1** through **D4**")
406+
# return
407+
408+
# # Flip X offsets depending on pullout direction
409+
# flip = 1
410+
# if tray["pullout_direction"] == 1:
411+
# flip = 1
412+
# elif tray["pullout_direction"] == 2:
413+
# flip = -1
414+
# else:
415+
# print("Error: Seed Tray **SLOT DIRECTION** must be `Positive X` or `Negative X`")
416+
# return
417+
418+
# # A1 coordinates
419+
# A1 = {
420+
# "x": tray["x"] - seeder_needle_offset + (1.5 * cell_spacing * flip),
421+
# "y": tray["y"] - (1.5 * cell_spacing * flip),
422+
# "z": tray["z"]
423+
# }
424+
425+
# # Cell offset from A1
426+
# offset = {
427+
# "x": cell_spacing * cells[cell]["x"] * flip,
428+
# "y": cell_spacing * cells[cell]["y"] * flip
429+
# }
430+
431+
# # Return cell coordinates
432+
# return {
433+
# "x": A1["x"] + offset["x"],
434+
# "y": A1["y"] + offset["y"],
435+
# "z": A1["z"]
436+
# }
437+
438+
def soil_height(self):
439+
"""Execute script to check soil height via message broker."""
440+
441+
soil_height_message = {
442+
**RPC_REQUEST,
443+
"body": {
444+
"kind": "execute_script",
445+
"args": {
446+
"label": "Measure Soil Height"
447+
}
448+
}
449+
}
450+
451+
self.broker_connect.publish(soil_height_message)
452+
# return ...
453+
454+
def detect_weeds(self):
455+
"""Execute script to detect weeds via message broker."""
456+
457+
detect_weeds_message = {
458+
**RPC_REQUEST,
459+
"body": {
460+
"kind": "execute_script",
461+
"args": {
462+
"label": "plant-detection"
463+
}
464+
}
465+
}
466+
467+
self.broker_connect.publish(detect_weeds_message)
468+
# return ...
469+
372470
## OTHER FUNCTIONS
373471

374472
def calibrate_camera(self): # TODO: fix "sequence_id"
@@ -438,38 +536,6 @@ def take_photo(self):
438536
self.broker_connect.publish(take_photo_message)
439537
# return ...
440538

441-
def soil_height(self):
442-
"""Execute script to check soil height via message broker."""
443-
444-
soil_height_message = {
445-
**RPC_REQUEST,
446-
"body": {
447-
"kind": "execute_script",
448-
"args": {
449-
"label": "Measure Soil Height"
450-
}
451-
}
452-
}
453-
454-
self.broker_connect.publish(soil_height_message)
455-
# return ...
456-
457-
def detect_weeds(self):
458-
"""Execute script to detect weeds via message broker."""
459-
460-
detect_weeds_message = {
461-
**RPC_REQUEST,
462-
"body": {
463-
"kind": "execute_script",
464-
"args": {
465-
"label": "plant-detection"
466-
}
467-
}
468-
}
469-
470-
self.broker_connect.publish(detect_weeds_message)
471-
# return ...
472-
473539
def mark_coord(self, x, y, z, property, mark_as): # TODO: Fix "label"
474540
mark_coord_message = {
475541
**RPC_REQUEST,
@@ -527,9 +593,8 @@ def mark_coord(self, x, y, z, property, mark_as): # TODO: Fix "label"
527593
# TODO: water() --> all or single coords
528594
# TODO: dispense() --> single coords?
529595

530-
# TODO: sequence()
531-
# TODO: get_seed_tray_call(tray, cell)
532-
# TODO: sort(points, method) --> API?
596+
# TODO: sequence() --> execute a sequence by ID
597+
# TODO: get_seed_tray_call(tray, cell) --> get coordinates of cell in seed tray by passing tool object and cell id, eg B3
533598

534599
# TODO: get_job() --> access status tree --> fetch all or single by name
535600
# TODO: set_job() --> access status tree --> inject(?) new or edit single by name

main.py

-3
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,5 @@ def soil_height(self):
144144
def detect_weeds(self):
145145
return self.broker.detect_weeds()
146146

147-
def mount_tool(self, x, y, z):
148-
return self.broker.mount_tool(x, y, z)
149-
150147
def assertion(self, code, as_type, id=''):
151148
return self.broker.assertion(code, as_type, id)

0 commit comments

Comments
 (0)