Python-learning-SMACH-QA

本文解决了使用ROS SMACH框架时遇到的多个常见错误,包括找不到rospkg模块、Graphview无法显示状态图、状态机构造错误、状态机一致性检查失败及无效用户代码错误等问题,并提供了详细的解决方案。
  • Question

    /usr/bin/python3.4 /home/evan/PycharmProjects/smach_projects/GettingStarted.py
Traceback (most recent call last):
  File "/home/evan/PycharmProjects/smach_projects/GettingStarted.py", line 2, in <module>
    import roslib;roslib.load_manifest('smach_projects')
  File "/opt/ros/indigo/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest
  File "/opt/ros/indigo/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
ImportError: No module named 'rospkg'

Process finished with exit code 1


  • Answer

Because we didnot install python3.4 package in the ros folder(/opt/ros/indigo/lib) , we just installed rospkg for python 2.7.6 so can not find the rospkg for python 3.4. We can manually install rospkg for python 3.4 but notice that only one rospkg can be installed that means we can not install rospkg for both python 2.7 and python 3.4.


  • Question
  • Question
    [ERROR] [WallTime: 1496741655.591969] Error raised during SMACH container construction:
    Traceback (most recent call last):

      File "/home/evan/workspace/roboware/my_catkin_ws/src/smach_package/src/cleanContainer.py", line 123, in main
        smach.StateMachine.add('find_area', State_find_area(),

      File "/home/evan/workspace/roboware/my_catkin_ws/src/smach_package/src/cleanContainer.py", line 63, in __init__
        result_cb = self.cb_result)

      File "/home/evan/workspace/roboware/my_catkin_ws/src/smach_package/src/cleanContainer.py", line 37, in __init__
        smach_ros.SimpleActionState.__init__(self,action_name,action_spec,goal,goal_key,goal_slots,goal_cb,goal_cb_args
    , result_key,result_slots,result_cb,result_cb_args,result_cb_kwargs,input_keys,output_keys,outcomes, exec_timeout,p
    reempt_timeout,server_wait_timeout)

      File "/opt/ros/indigo/lib/python2.7/dist-packages/smach_ros/simple_action_state.py", line 173, in __init__
        if not all([s in action_spec().action_result.result.__slots__ for s in result_slots]):

    TypeError: 'instancemethod' object is not iterable

    Traceback (most recent call last):
      File "/home/evan/workspace/roboware/my_catkin_ws/src/smach_package/src/cleanContainer.py", line 135, in <module>
        main()
      File "/home/evan/workspace/roboware/my_catkin_ws/src/smach_package/src/cleanContainer.py", line 123, in main
        smach.StateMachine.add('find_area', State_find_area(),
      File "/home/evan/workspace/roboware/my_catkin_ws/src/smach_package/src/cleanContainer.py", line 63, in __init__
        result_cb = self.cb_result)
      File "/home/evan/workspace/roboware/my_catkin_ws/src/smach_package/src/cleanContainer.py", line 37, in __init__
        smach_ros.SimpleActionState.__init__(self,action_name,action_spec,goal,goal_key,goal_slots,goal_cb,goal_cb_args
    , result_key,result_slots,result_cb,result_cb_args,result_cb_kwargs,input_keys,output_keys,outcomes, exec_timeout,p
    reempt_timeout,server_wait_timeout)
      File "/opt/ros/indigo/lib/python2.7/dist-packages/smach_ros/simple_action_state.py", line 173, in __init__
        if not all([s in action_spec().action_result.result.__slots__ for s in result_slots]):
    TypeError: 'instancemethod' object is not iterable
    • Answer
           def   __init__ ( self # Action info
                   action_name  =  'default_action' ,
                   action_spec  = defaultAction,
                   # Default goal 
                   goal  =  None ,
                   goal_key  =  None ,
                   goal_slots  = [],
                   goal_cb  =  None ,
                   goal_cb_args  = [],
                   goal_cb_kwargs  = {},
                   # Result modes
                   result_key  =  None ,
                   result_slots  = [],
                   result_cb  =  None ,
                   result_cb_args  = [],
                   result_cb_kwargs  = {},
                   # Keys
                   input_keys  = [],
                   output_keys  = [],
                   outcomes  = [],
                   # Timeouts
                   exec_timeout  =  None ,
                   preempt_timeout  = rospy.Duration( 60.0 ),
                   server_wait_timeout  = rospy.Duration( 60.0 )):
              smach_ros.SimpleActionState. __init__ ( self ,action_name,action_spec,goal,goal_key,goal_slots,goal_cb,goal_cb_args,goal_cb_kwargs(forget adding this param to cause the wrong param order), result_key,result_slots,result_cb,result_cb_args,result_cb_kwargs,input_keys,output_keys,outcomes, exec_timeout,preempt_timeout,server_wait_timeout)

  • Question
    [ERROR] [WallTime: 1496742757.805075] InvalidTransitionError: State machine failed consistency check:
            State 'find_area' references unregistered outcomes: ['preempted', 'aborted']

            Available states: ['finish', 'BAR', 'find_area']
    [ERROR] [WallTime: 1496742757.805399] Container consistency check failed.

    • Answer
      smach.StateMachine.add( 'find_area' , State_find_area(), 
                                      transitions ={ 'succeeded' : 'finish'
                                                   'fail' : 'find_area' ,
                                                  'aborted':'aborted',
                                                  'preempted':'aborted' },#forget adding these two lines,so the state machine can not form complete outcome diagram.
                                      remapping ={ 'find_wall_area' : 'area' })

  • Question
    [ERROR] [WallTime: 1496743305.298023] InvalidUserCodeError: Reading from SMACH userdata key 'find_wall_area' but the only keys that were declare
    d as input to this state were: (). This key needs to be declaread as input to this state.
    [ERROR] [WallTime: 1496743305.298158] State 'find_area' failed to execute.

    • Answer
      smach.StateMachine.add( 'find_area' , State_find_area(), 
                                      transitions ={ 'succeeded' : 'plan_path'
                                                   'fail' : 'find_area' ,
                                                   'aborted' : 'aborted' ,
                                                   'preempted' : 'aborted' },
                                      remapping ={ 'find_wall_area' : 'area' ,#This line for input_key named 'find_wall_area'
                                                   'find_wall_area' : 'area' })#This line for output_key named 'find_wall_area'
  • Question
    When adding a new action file area.action , there is an error happened when building.
     Generating .msg files for action smach_package/area /home/evan/workspace/roboware/my_catkin_ws/src/smach_package/action/area.action
    Traceback (most recent call last):
      File "/opt/ros/indigo/share/actionlib_msgs/cmake/../../../lib/actionlib_msgs/genaction.py", line 136, in <module>
        if __name__ == '__main__': main()
      File "/opt/ros/indigo/share/actionlib_msgs/cmake/../../../lib/actionlib_msgs/genaction.py", line 97, in main
        raise ActionSpecException("%s: wrong number of pieces, %d"%(filename,len(pieces)))
    __main__.ActionSpecException: /home/evan/workspace/roboware/my_catkin_ws/src/smach_package/action/area.action: wrong number of pieces, 1
    Generating for action area
    CMake Error at /opt/ros/indigo/share/catkin/cmake/safe_execute_process.cmake:11 (message):
    • Answer
      #goal definition
      geometry_msgs::PointStamped  origin

      #result definition
      geometry_msgs::PolygonStamped area

      #feedback definition
      geometry_msgs::PolygonStamped area
      replace the double comma to reverse slash and add two seperators
      #goal definition
      geometry_msgs/PointStamped  origin
      ---
      #result definition
      geometry_msgs/PolygonStamped area
      ---
      #feedback definition
      geometry_msgs/PolygonStamped area
    • if there is another error occurring
      CMake Error at /home/evan/workspace/roboware/my_catkin_ws/build/smach_package/cmake/smach_package-genmsg.cmake:3 (message):
        Could not find messages which
        '/home/evan/workspace/roboware/my_catkin_ws/devel/share/smach_package/msg/areaAction.msg'
        depends on.  Did you forget to specify generate_messages(DEPENDENCIES ...)?

        Cannot locate message [PointStamped]: unknown package [geometry_msgs] on
        search path [{{'smach_package':
        ['/home/evan/workspace/roboware/my_catkin_ws/devel/share/smach_package/msg'],
        'actionlib_msgs': ['/opt/ros/indigo/share/actionlib_msgs/cmake/../msg'],
        'std_msgs': ['/opt/ros/indigo/share/std_msgs/cmake/../msg']}}]
      • Answer
        ## Generate added messages and services with any dependencies listed here
        generate_messages(DEPENDENCIES
          actionlib_msgs
          geometry_msgs   ## Add this line for support the geometry_msgs/polygonStamped message
          std_msgs
        )
        find_package (catkin REQUIRED COMPONENTS
          actionlib_msgs
          message_generation
          rospy
          std_msgs
          geometry_msgs  ## Add this line when using geometry_msgs to generate messages
        )
  • Question
    e_action_server.py", line 289, in executeLoop
        self.execute_callback(goal)
      File "/home/evan/catkin_ws/src/sim_platform/src/path_planner.py",
     line 99, in execute_cb
        self._sas.set_succeeded(result)
      File "/opt/ros/indigo/lib/python2.7/dist-packages/actionlib/simpl
    e_action_server.py", line 162, in set_succeeded
        self.current_goal.set_succeeded(result, text)
      File "/opt/ros/indigo/lib/python2.7/dist-packages/actionlib/serve
    r_goal_handle.py", line 195, in set_succeeded
        self.action_server.publish_result(self.status_tracker.status, r
    esult)
      File "/opt/ros/indigo/lib/python2.7/dist-packages/actionlib/actio
    n_server.py", line 182, in publish_result
        self.result_pub.publish(ar)
      File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py
    ", line 856, in publish
        raise ROSSerializationException(str(e))
    ROSSerializationException: <class 'struct.error'>: 'required argume
    nt is not a float' when writing 'x: 0
    y:
      - 0.208178028592
      - -0.0186330676772
      - 0
    z: 0.0'
    • Answer
      for  index,waypoint in  enumerate ( self .path):  ## forget add index ,enumerate will firstly set index .Otherwise waypoint[0] will be set as index.

内容概要:本文介绍了一个关于超声谐波成像中幅度调制聚焦超声所引起全场位移和应变的分析模型,并提供了基于Matlab的代码实现。该模型旨在精确模拟和分析在超声谐波成像过程中,由于幅度调制聚焦超声作用于生物组织时产生的力学效应,包括全场的位移与应变分布,从而为医学成像和治疗提供理论支持和技术超声谐波成像中幅度调制聚焦超声引起的全场位移和应变的分析模型(Matlab代码实现)手段。文中详细阐述了模型构建的物理基础、数学推导过程以及Matlab仿真流程,具有较强的理论深度与工程应用价值。; 适合人群:具备一定声学、生物医学工程或力学背景,熟悉Matlab编程,从事医学成像、超声技术或相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于超声弹性成像中的力学建模与仿真分析;②支持高强度聚焦超声(HIFU)治疗中的组织响应预测;③作为教学案例帮助理解超声与组织相互作用的物理机制;④为相关科研项目提供可复用的Matlab代码框架。; 阅读建议:建议读者结合超声物理和连续介质力学基础知识进行学习,重点关注模型假设、偏微分方程的数值求解方法及Matlab实现细节,建议动手运行并修改代码以加深理解,同时可拓展应用于其他超声成像或治疗场景的仿真研究。
### 关于PAT Basic Level Practice的测试点及题目解析 #### 题目难度分级 PAT(Programming Ability Test)是由浙江大学举办的计算机程序设计能力考试,分为不同级别。其中乙级即Basic Level主要面向初学者,考察基本编程技能[^1]。 #### 测试点特点 对于PAT Basic Level中的某些特定题目而言,其测试点设置较为严格。例如,在处理字符串匹配类问题时,需要注意算法逻辑中何时应当终止循环以防止不必要的重复计算;而在涉及数值运算的问题里,则可能因为边界条件而增加复杂度[^3]。 #### 编程语言的选择影响 值得注意的是,尽管大部分简单题目可以作为学习某种新语言的良好实践材料,但在实际操作过程中可能会遇到由于所选语言特性而导致难以通过全部测试点的情况。比如Java在面对部分效率敏感型试题时表现不佳,这可能是由于该语言本身的执行速度相对较慢以及内存管理方式等因素造成的。因此有时不得不转而采用其他更适合解决此类问题的语言版本来完成解答[^2]。 ```cpp #include<bits/stdc++.h> using namespace std; int a[100000]; int c=1; void getPrime(){ int flag=0; for(int i=2;i<105000;i++){ flag=1; for(int j=2;j<=sqrt(i);j++){ if(i%j==0){ flag=0; break; } } if(flag==1) a[c++]=i; } } int main(){ int m,n,i,t=1; scanf("%d %d",&m,&n); getPrime(); for(i=m;i<=n;i++){ if(t%10==1){ printf("%d",a[i]); t++; }else{ printf(" %d",a[i]); t++; } if((t-1)%10==0) printf("\n"); } return 0; } ``` 上述C++代码展示了如何实现一个简单的质数打印功能,并且针对输出格式进行了特殊处理以满足特定要求。这段代码很好地体现了编写高效解决方案的重要性,尤其是在应对像PAT这样的在线评测系统时[^4]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值