13
13
from .broker import BrokerConnect
14
14
from .information import Information
15
15
16
+ AXES = ["x" , "y" , "z" , "all" ]
17
+
18
+ def validate_axis (axis ):
19
+ """Validate axis."""
20
+ if axis not in AXES :
21
+ raise ValueError (f"Invalid axis: { axis } not in { AXES } " )
22
+
16
23
class MovementControls ():
17
24
"""MovementControls class."""
18
25
def __init__ (self , state ):
@@ -22,6 +29,7 @@ def __init__(self, state):
22
29
23
30
def move (self , x , y , z ):
24
31
"""Moves to the specified (x, y, z) coordinate."""
32
+ self .state .print_status (description = f"Moving to ({ x } , { y } , { z } )." )
25
33
26
34
def axis_overwrite (axis , value ):
27
35
return {
@@ -49,11 +57,11 @@ def axis_overwrite(axis, value):
49
57
50
58
self .broker .publish (move_message )
51
59
52
- self .state .print_status (description = f"Moved to coordinates: ({ x } , { y } , { z } )." )
53
- return x , y , z
54
-
55
60
def set_home (self , axis = "all" ):
56
61
"""Sets the current position as the home position for a specific axis."""
62
+ self .state .print_status (description = "Setting home position" )
63
+
64
+ validate_axis (axis )
57
65
58
66
set_home_message = {
59
67
"kind" : "zero" ,
@@ -63,10 +71,11 @@ def set_home(self, axis="all"):
63
71
}
64
72
self .broker .publish (set_home_message )
65
73
66
- self .state .print_status (description = "Updated home coordinate." )
67
-
68
74
def find_home (self , axis = "all" , speed = 100 ):
69
75
"""Moves the device to the home position for a specified axis."""
76
+ self .state .print_status (description = "Finding home position" )
77
+
78
+ validate_axis (axis )
70
79
71
80
if speed > 100 or speed < 1 :
72
81
error = "ERROR: Speed constrained to 1-100."
@@ -83,10 +92,11 @@ def find_home(self, axis="all", speed=100):
83
92
}
84
93
self .broker .publish (message )
85
94
86
- self .state .print_status (description = "Moved to home position." )
87
-
88
95
def find_axis_length (self , axis = "all" ):
89
96
"""Finds the length of a specified axis."""
97
+ self .state .print_status (description = "Finding axis length" )
98
+
99
+ validate_axis (axis )
90
100
91
101
find_axis_length_message = {
92
102
"kind" : "calibrate" ,
@@ -99,6 +109,7 @@ def find_axis_length(self, axis="all"):
99
109
100
110
def get_xyz (self ):
101
111
"""Returns the current (x, y, z) coordinates of the FarmBot."""
112
+ self .state .print_status (description = "Getting current coordinates" )
102
113
103
114
tree_data = self .info .read_status ()
104
115
if tree_data is None :
@@ -112,13 +123,15 @@ def get_xyz(self):
112
123
y_val = position ["y" ]
113
124
z_val = position ["z" ]
114
125
115
- self .state .print_status (description = f"Current coordinate: ( { x_val } , { y_val } , { z_val } )." )
126
+ self .state .print_status (description = f"Current position: { position } ." , update_only = True )
116
127
return position
117
128
118
129
def check_position (self , user_x , user_y , user_z , tolerance ):
119
130
"""Verifies position of the FarmBot within specified tolerance range."""
120
131
121
132
user_values = {'x' : user_x , 'y' : user_y , 'z' : user_z }
133
+ self .state .print_status (description = f"Checking if position is { user_values } with tolerance: { tolerance } ." )
134
+
122
135
actual_vals = self .get_xyz ()
123
136
124
137
if actual_vals is None :
@@ -132,8 +145,12 @@ def check_position(self, user_x, user_y, user_z, tolerance):
132
145
user_value = user_values [axis ]
133
146
actual_value = actual_vals [axis ]
134
147
if not actual_value - tolerance <= user_value <= actual_value + tolerance :
135
- self .state .print_status (description = f"Farmbot is NOT at position\n Current coordinates: ({ x_val } , { y_val } , { z_val } )." )
148
+ self .state .print_status (
149
+ description = f"Farmbot is NOT at position.\n Current position: { actual_vals } ." ,
150
+ update_only = True )
136
151
return False
137
152
138
- self .state .print_status (description = f"Farmbot is at position: ({ x_val } , { y_val } , { z_val } )." )
153
+ self .state .print_status (
154
+ description = f"Farmbot is at position: { actual_vals } ." ,
155
+ update_only = True )
139
156
return True
0 commit comments