5
5
from pydantic import BaseModel
6
6
from robot_arm_controller .control .arm_kinematics import ArmPose
7
7
from robot_arm_controller .controller import ArmController
8
+ from robot_arm_controller .utils .algebra import degree2rad
8
9
9
10
from utils .general import controller_dependency
10
11
@@ -23,17 +24,20 @@ class Move(BaseModel):
23
24
pitch : float
24
25
yaw : float
25
26
wait : Optional [bool ] = False
27
+ degrees : Optional [bool ] = True
26
28
27
29
28
30
class Tool (BaseModel ):
29
31
toolValue : float
30
32
wait : Optional [bool ] = False
33
+ degrees : Optional [bool ] = True
31
34
32
35
33
36
class MoveJoint (BaseModel ):
34
37
joint_idx : int
35
38
joint_value : float
36
39
wait : Optional [bool ] = False
40
+ degrees : Optional [bool ] = True
37
41
38
42
39
43
class HomeJoint (BaseModel ):
@@ -44,6 +48,7 @@ class HomeJoint(BaseModel):
44
48
class MoveJoints (BaseModel ):
45
49
joint_values : list
46
50
wait : Optional [bool ] = False
51
+ degrees : Optional [bool ] = True
47
52
48
53
49
54
# --------
@@ -76,8 +81,9 @@ def home_joint(
76
81
def move (move : Move , controller : ArmController = controller_dependency ) -> JSONResponse :
77
82
move_dict = move .model_dump ()
78
83
wait = move_dict .pop ("wait" )
84
+ degrees = move_dict .pop ("degrees" )
79
85
80
- pose = ArmPose (** move_dict )
86
+ pose = ArmPose (** move_dict , degree = degrees )
81
87
82
88
move_is_possible = controller .move_to (pose )
83
89
@@ -95,8 +101,9 @@ def move_relative(
95
101
) -> JSONResponse :
96
102
move_dict = move .model_dump ()
97
103
wait = move_dict .pop ("wait" )
104
+ degrees = move_dict .pop ("degrees" )
98
105
99
- pose = ArmPose (** move_dict )
106
+ pose = ArmPose (** move_dict , degree = degrees )
100
107
101
108
move_is_possible = controller .move_to_relative (pose )
102
109
@@ -114,7 +121,9 @@ def valid_pose(
114
121
) -> JSONResponse :
115
122
move_dict = move .model_dump ()
116
123
move_dict .pop ("wait" )
117
- pose = ArmPose (** move_dict )
124
+ degrees = move_dict .pop ("degrees" )
125
+ pose = ArmPose (** move_dict , degree = degrees )
126
+
118
127
move_is_possible = controller .valid_pose (pose )
119
128
if move_is_possible :
120
129
return JSONResponse (content = {"message" : "Pose is valid" }, status_code = 200 )
@@ -133,9 +142,14 @@ def move_joint(
133
142
) -> Dict [Any , Any ]:
134
143
move_dict = move .model_dump ()
135
144
wait = move_dict .pop ("wait" )
145
+ degrees = move_dict .pop ("degrees" )
136
146
137
147
joint_idx = move_dict .pop ("joint_idx" )
138
148
joint_value = move_dict .pop ("joint_value" )
149
+
150
+ if degrees :
151
+ joint_value = degree2rad (joint_value )
152
+
139
153
controller .move_joint_to (joint_idx , joint_value )
140
154
if wait :
141
155
controller .wait_done_moving ()
@@ -148,9 +162,13 @@ def move_joint_to_relative(
148
162
) -> Dict [Any , Any ]:
149
163
move_dict = move .model_dump ()
150
164
wait = move_dict .pop ("wait" )
165
+ degrees = move_dict .pop ("degrees" )
151
166
152
167
joint_idx = move_dict .pop ("joint_idx" )
153
168
joint_value = move_dict .pop ("joint_value" )
169
+ if degrees :
170
+ joint_value = degree2rad (joint_value )
171
+
154
172
controller .move_joint_to_relative (joint_idx , joint_value )
155
173
if wait :
156
174
controller .wait_done_moving ()
@@ -163,8 +181,12 @@ def move_joints_to_relative(
163
181
) -> Dict [Any , Any ]:
164
182
move_dict = move .model_dump ()
165
183
wait = move_dict .pop ("wait" )
184
+ degrees = move_dict .pop ("degrees" )
166
185
167
186
joint_values = move_dict .pop ("joint_values" )
187
+ if degrees :
188
+ joint_values = [degree2rad (joint_value ) for joint_value in joint_values ]
189
+
168
190
controller .move_joints_to_relative (joint_values )
169
191
if wait :
170
192
controller .wait_done_moving ()
@@ -176,21 +198,42 @@ def move_joints_to_relative(
176
198
# --------
177
199
178
200
179
- @router .post ("/tool/move/ " )
201
+ @router .post ("/tool/" )
180
202
def tool_post (
181
203
tool : Tool , controller : ArmController = controller_dependency
182
204
) -> Dict [Any , Any ]:
183
205
tool_dict = tool .model_dump ()
184
206
tool_value = tool_dict ["toolValue" ]
185
207
wait = tool_dict ["wait" ]
208
+ degrees = tool_dict ["degrees" ]
209
+ if degrees :
210
+ tool_value = degree2rad (tool_value )
211
+
186
212
controller .set_tool_value (tool_value )
187
213
if wait :
188
214
controller .wait_done_moving ()
189
215
return {"message" : "Moved" }
190
216
191
217
218
+ @router .post ("/tool/relative/" )
219
+ def tool_relative (
220
+ tool : Tool , controller : ArmController = controller_dependency
221
+ ) -> Dict [Any , Any ]:
222
+ tool_dict = tool .model_dump ()
223
+ tool_value = tool_dict ["toolValue" ]
224
+ wait = tool_dict ["wait" ]
225
+ degrees = tool_dict ["degrees" ]
226
+ if degrees :
227
+ tool_value = degree2rad (tool_value )
228
+
229
+ print ("\n \n \n tool_value" , tool_value )
230
+ controller .set_tool_value_relative (tool_value )
231
+ if wait :
232
+ controller .wait_done_moving ()
233
+ return {"message" : "Moved" }
234
+
235
+
192
236
@router .get ("/tool/current/" )
193
237
def tool_get (controller : ArmController = controller_dependency ) -> Dict [Any , Any ]:
194
238
tool_value = controller .tool_value
195
-
196
239
return {"toolValue" : tool_value }
0 commit comments