1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from typing import List , Callable , Float
15+ from typing import List , Callable
1616from copy import deepcopy
1717from threading import Thread , Lock , Event
1818
@@ -41,6 +41,7 @@ def __init__(self, ip_address: str):
4141 self ._joint_feedback_ex : JointFeedbackEx = None
4242 self ._robot_status : RobotStatus = None
4343 self ._initial_response : Event = Event ()
44+ self ._stop : Event = Event ()
4445 self ._lock : Lock = Lock ()
4546
4647 self ._joint_feedback_callbacks : List [Callable ] = []
@@ -67,10 +68,11 @@ def add_joint_feedback_msg_callback(self, callback: Callable):
6768 def add_joint_feedback_ex_msg_callback (self , callback : Callable ):
6869 self ._joint_feedback_ex_callbacks .append (callback )
6970
70- def start (self , timeout : Float = 5.0 ) -> None :
71+ def start (self , timeout : float = 5.0 ) -> None :
7172 self ._tcp_client .connect ()
7273 self ._worker_thread .start ()
7374 if not self ._initial_response .wait (timeout ):
75+ self ._stop .set ()
7476 raise TimeoutError (
7577 "Did not receive at least one of each message before timeout"
7678 " occured. Try increasing the timeout period. "
@@ -81,7 +83,7 @@ def stop(self) -> None:
8183 pass
8284
8385 def _worker (self ) -> None :
84- while True :
86+ while True and not self . _stop . is_set () :
8587 msg : SimpleMessage = self .recv ()
8688 if msg .header .msg_type == MsgType .JOINT_FEEDBACK :
8789 with self ._lock :
@@ -100,9 +102,8 @@ def _worker(self) -> None:
100102 self ._robot_status = deepcopy (msg .body )
101103
102104 if not self ._initial_response .is_set () and (
103- self .robot_status is not None
104- and self . _joint_feedback is not None
105- and self .joint_feedback_ex is not None
105+ isinstance ( self .robot_status (), RobotStatus )
106+ and any ( isinstance ( elem , JointFeedback ) for elem in self . _joint_feedback )
107+ and isinstance ( self .joint_feedback_ex (), JointFeedbackEx )
106108 ):
107- print ("At least one message of every time has been received." )
108109 self ._initial_response .set ()
0 commit comments