Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions pyniryo/api/tcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ def __transform_to_type(self, value, type_):
except ValueError:
self.__raise_exception_expected_type(type_.__name__, value)

def __str_to_bool(self, data):
if data == "True":
return True
elif data == "False":
return False
else:
self.__raise_exception("Expected data to be either 'True' or 'False'")

# Error Handlers
def __raise_exception_expected_choice(self, expected_choice, given):
raise TcpCommandException("Expected one of the following: {}.\nGiven: {}".format(expected_choice, given))
Expand Down Expand Up @@ -386,7 +394,7 @@ def get_learning_mode(self):
:return: ``True`` if learning mode is on
:rtype: bool
"""
return eval(self.__send_n_receive(Command.GET_LEARNING_MODE))
return self.__str_to_bool(self.__send_n_receive(Command.GET_LEARNING_MODE))

@learning_mode.setter
def learning_mode(self, value):
Expand Down Expand Up @@ -459,7 +467,7 @@ def collision_detected(self):

:type: bool
"""
return eval(self.__send_n_receive(Command.GET_COLLISION_DETECTED))
return self.__str_to_bool(self.__send_n_receive(Command.GET_COLLISION_DETECTED))

def clear_collision_detected(self):
"""
Expand Down Expand Up @@ -1517,10 +1525,10 @@ def get_hardware_status(self):

rpi_temperature = float(data[0])
hardware_version = data[1]
connection_up = eval(data[2])
connection_up = self.__str_to_bool(data[2])
error_message = data[3]
calibration_needed = eval(data[4])
calibration_in_progress = eval(data[5])
calibration_needed = self.__str_to_bool(data[4])
calibration_in_progress = self.__str_to_bool(data[5])

motor_names = data[6]
motor_types = data[7]
Expand Down Expand Up @@ -1646,7 +1654,7 @@ def get_conveyors_feedback(self):
for i in range(len(conveyors_feedback)):
conveyors_feedback[i]['conveyor_id'] = ConveyorID[conveyors_feedback[i]['conveyor_id']]
conveyors_feedback[i]['direction'] = ConveyorDirection(conveyors_feedback[i]['direction'])
conveyors_feedback[i]['connection_state'] = eval(conveyors_feedback[i]['connection_state'])
conveyors_feedback[i]['connection_state'] = self.__str_to_bool(conveyors_feedback[i]['connection_state'])

return conveyors_feedback

Expand Down Expand Up @@ -1784,7 +1792,7 @@ def get_target_pose_from_cam(self, workspace_name, height_offset=0.0, shape=Obje
height_offset,
shape,
color)
obj_found = eval(data_array[0])
obj_found = self.__str_to_bool(data_array[0])
if obj_found:
pose_object = PoseObject(*data_array[1])
shape_ret = data_array[2]
Expand All @@ -1803,7 +1811,7 @@ def __move_with_vision(self, command, workspace_name, height_offset, shape, colo

data_array = self.__send_n_receive(command, workspace_name, height_offset, shape, color, **kwargs)

obj_found = eval(data_array[0])
obj_found = self.__str_to_bool(data_array[0])
if obj_found is True:
shape_ret = data_array[1]
color_ret = data_array[2]
Expand Down Expand Up @@ -1892,7 +1900,7 @@ def detect_object(self, workspace_name, shape=ObjectShape.ANY, color=ObjectColor
self.__check_enum_belonging(color, ObjectColor)

data_array = self.__send_n_receive(Command.DETECT_OBJECT, workspace_name, shape, color)
obj_found = eval(data_array[0])
obj_found = self.__str_to_bool(data_array[0])
if not obj_found:
rel_pose_array = 3 * [0.0]
shape = "ANY"
Expand Down
Loading