Skip to content

Commit 9ba56b1

Browse files
committed
Bug fix twist - 0.9.1
1 parent cb4f8e1 commit 9ba56b1

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

examples/example4_robotRestSDK_threading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def robot_handler(self):
2929
while True:
3030
print(self.get_robot_dict_status())
3131
time.sleep(3)
32-
if self.get_twist() is not None: # ROS like twist object to angular direction and velocity
32+
if self.twist is not None: # ROS like twist object to angular direction and velocity
3333
x = self.twist.linear.x
3434
y = self.twist.linear.y
3535
theta_rad = math.atan2(y, x)

simplepybotsdk/configurations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "0.9.0"
1+
VERSION = "0.9.1"
22
LICENSE = "MIT - Copyright (c) 2021-2022 Alex Vellone"
33
MOTORS_CHECK_PER_SECOND = 20
44
MOTORS_POINT_TO_POINT_CHECK_PER_SECOND = 10

simplepybotsdk/robotRestSDK.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def _rest_robot_go_to_pose(self, root, request):
216216
if result:
217217
return Response(json_body={"detail": "Going to pose {} in {} seconds".format(key, seconds)})
218218
return Response(
219-
json_body={"detail": "Something went wrong. See all available pose with /configuration/"}, status=400)
219+
json_body={"detail": "Something went wrong. See all available pose with /poses/"}, status=400)
220220

221221
def _rest_robot_move_point_to_point(self, root, request):
222222
if request.method == "OPTIONS":
@@ -249,19 +249,23 @@ def _rest_robot_sensors_detail_by_key(self, root, request):
249249
return Response(json_body=dict(s))
250250

251251
def _rest_robot_twist(self, root, request):
252-
return Response(json_body=dict(self.get_twist()))
252+
if self.twist is None:
253+
return Response(json_body={"detail": "Twist not enabled. Add enable_twist_controller in conf"}, status=404)
254+
return Response(json_body=self.get_twist_dict())
253255

254256
def _rest_robot_move_twist(self, root, request):
255257
if request.method == "OPTIONS":
256258
return Response(json_body={})
257259
try:
260+
if self.twist is None:
261+
return Response(json_body={"detail": "Twist not enabled"}, status=404)
258262
self.set_twist(
259263
linear=TwistVector(x=request.json_body["linear"]["x"], y=request.json_body["linear"]["y"],
260264
z=request.json_body["linear"]["z"]),
261265
angular=TwistVector(x=request.json_body["angular"]["x"], y=request.json_body["angular"]["y"],
262266
z=request.json_body["angular"]["z"])
263267
)
264-
return Response(json_body=dict(self.get_twist()))
268+
return Response(json_body=self.get_twist_dict())
265269
except Exception as e:
266270
logger.error("[rest_thread]: _rest_robot_move_twist: {}".format(e))
267271
return Response(json_body={"detail": "Bad request. You need to format the twist properly"}, status=400)

simplepybotsdk/robotSDK.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ def set_twist(self, linear: TwistVector, angular: TwistVector):
218218
self.twist.linear = linear
219219
self.twist.angular = angular
220220

221-
def get_twist(self):
221+
def get_twist_dict(self) -> dict:
222222
"""
223223
:return: dict of twist with linear and angular of None.
224224
"""
225-
return self.twist if self.twist is not None else None
225+
return dict(self.twist) if self.twist is not None else None
226226

227227
def load_motion_from_file(self, path: str):
228228
"""
@@ -457,7 +457,7 @@ def get_robot_dict_status(self, absolute: bool = False) -> dict:
457457
dict_robot = {
458458
"motors": self.get_motors_list_abs_angles() if absolute else self.get_motors_list_relative_angles(),
459459
"sensors": self.get_sensors_list(),
460-
"twist": dict(self.get_twist()),
460+
"twist": self.get_twist_dict(),
461461
"format": "absolute" if absolute else "relative",
462462
"sdk": self.get_sdk_infos(),
463463
"system": self.get_system_infos()

0 commit comments

Comments
 (0)