smach_viewer 抛出 KeyError

smach_viewer throws KeyError

我正在尝试使用 SMACH 在 ROS 上实现一个简单的状态机,并使用 smach_viewer 将其可视化。 我使用的系统:

我的 smach 实现如下所示 (test.py):

  #!/usr/bin/env python3

  import smach
  import smach_ros
  import rospy

  class t1(smach.State):
    def __init__(self, outcomes=['successful', 'failed']):
        smach.State.__init__(self, outcomes)

    def execute(self, userdata):
        return 'successful'

  class t2(smach.State):
    def __init__(self, outcomes=['successful']):
        smach.State.__init__(self, outcomes)

    def execute(self, userdata):
        #time.sleep(2)
        return 'successful'

  class t3(smach.State):
    def __init__(self, outcomes=['successful']):
        smach.State.__init__(self, outcomes)

    def execute(self, userdata):
        #time.sleep(2)
        return 'successful'


  if __name__=="__main__":
    rospy.init_node('test_state_machine')

    sm_top = smach.StateMachine(outcomes=['success'])
    with sm_top:
        smach.StateMachine.add('T1', t1(),
                                   transitions={'successful': 'T2', 'failed': 'T3'})
        smach.StateMachine.add('T2', t2(),
                                   transitions={'successful': 'T1'})
        smach.StateMachine.add('T3', t3(),
                                   transitions={'successful': 'success'})

    # Create and start the introspection server
    sis = smach_ros.IntrospectionServer('introspection_server', sm_top, '/SM_ROOT')
    sis.start()
    # Execute SMACH plan
    outcome = sm_top.execute()
    # Wait for ctrl-c to stop the application
    rospy.spin()
    sis.stop()

根据我终端的输出,状态机运行良好。但是当我尝试使用 smach_viewer 可视化 SM 时,smach_viewer 抛出以下错误:

[ERROR] [1599821587.164191]: bad callback: <bound method SmachViewerFrame._status_msg_update of <__main__.SmachViewerFrame; proxy of <Swig Object of type 'wxFrame *' at 0x55616f7eb050> >>
Traceback (most recent call last):
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "/home/faps/catkin_ws/src/executive_smach_visualization/smach_viewer/scripts/smach_viewer.py", line 844, in _status_msg_update
    if container.update_status(msg):
  File "/home/faps/catkin_ws/src/executive_smach_visualization/smach_viewer/scripts/smach_viewer.py", line 185, in update_status
    self._local_data._data = pickle.loads(msg.local_data)
  File "/usr/lib/python2.7/pickle.py", line 1388, in loads
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 864, in load
    dispatch[key](self)
  File "/usr/lib/python2.7/pickle.py", line 1157, in load_get
    self.append(self.memo[self.readline()[:-1]])
KeyError: 'AJ9cQA'

关于可能是什么问题以及如何解决它有什么想法吗?

我确保激活了正确的 b运行ch(在我的例子中是 melodic-devel b运行ch)和 运行

rosdep install smach_viewer

(我之前忘记了)。

这样做,smach_viewer至少可以正确显示状态机。然而,在终端中错误不断出现。

由于至少可视化现在有效,我将其标记为答案。有关详细信息,请查看问题线程 here.