admin管理员组文章数量:1572325
ros_demo系列——smach
此文章用来记录在学习roswiki上smach剩下的坑,后续有机会解决并修改。另外smach是一个功能强大且可扩展的基于python的分层状态机库,其不依赖ros,但是executive_smach提供了很好的ros支持,包括actionlib与Smach viewer 的整合,为机器人任务级的决策的提供了一个比较好的开发工具。
参考资料:
- http://wiki.ros/smach/Tutorials
- https://www.ncnynl/archives/201807/2506.html
#提供一个关于movebase的示例程序
import rospy
from smach import StateMachine
from smach_ros import SimpleActionState
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
waypoints =[
['one', (6.575, 3.962), (0.0,0.0,6.575, 3.962)],
['two', (3.190, 3.132), (0.000, 0.000, 0.921, -0.389)],
['three', (1.692, 1.433), (0.000, 0.000, -0.536, 0.844)],
['four', (3.153, -4.076), (0.000, 0.000, 0.121, 0.993)]
]
if __name__ == '__main__':
rospy.init_node('patrol')
patrol = StateMachine(['succeeded','aborted','preempted'])
with patrol:
for i,w in enumerate(waypoints):
goal_pose = MoveBaseGoal()
goal_pose.target_pose.header.frame_id = 'map'
goal_pose.target_pose.pose.position.x = w[1][0]
goal_pose.target_pose.pose.position.y = w[1][1]
goal_pose.target_pose.pose.position.z = 0.0
goal_pose.target_pose.pose.orientation.x = w[2][0]
goal_pose.target_pose.pose.orientation.y = w[2][1]
goal_pose.target_pose.pose.orientation.z = w[2][2]
goal_pose.target_pose.pose.orientation.w = w[2][3]
StateMachine.add(
w[0],
SimpleActionState('move_base', MoveBaseAction, goal=goal_pose),
transitions={'succeeded':waypoints[(i + 1) % len(waypoints)][0]}
)
patrol.execute()
暂时的坑:
- Smach viewer的配置环境问题
- 后续再更新一些更实用的demo
版权声明:本文标题:ros_demo系列——smach 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1727724677a1127083.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论