机器人体验营笔记(三)进阶

举报
zhangrelay 发表于 2021/07/15 04:07:20 2021/07/15
【摘要】 全文内容来源于国外权威资料汇总整理,具体信息请查阅文末参考文献。 For specific information, please refer to the reference at the end of the article. 编程重点 Code Points 协程和异步,Coroutines & Asynchronous 并发和并行,Concurr...

全文内容来源于国外权威资料汇总整理,具体信息请查阅文末参考文献。

For specific information, please refer to the reference at the end of the article.


编程重点 Code Points

协程和异步,Coroutines & Asynchronous

并发和并行,Concurrency & parallelism

asyncio — Asynchronous I/O

思考案例:机器人在本体运动过程中转动摄像头,同时显示表情并发出语音提示。

Problem Case: The robot rotates the camera during the movement of the body, simultaneously displaying the expression and giving a voice prompt.

有限状态机 Finite State Machine(FSM)

状态机广泛用于机器人编程,从LEGO Mindstorms(NXT-G)到ROS(Smach)。State machines are widely used in robot programming, from LEGO Mindstorms (NXT-G) to ROS (Smach).

  • 将控制逻辑(链接)与功能(节点)分开。Separates the control logic (links) from the functionality (nodes).

清洁机器人通过传感器识别地板、瓷砖或地毯,应用不同的清扫策略。The cleaning robot uses sensors to identify floors, tiles or carpets and apply different cleaning strategies.

事件驱动结构,Event-Driven Architecture

花式状态机
cozmo_fsm是一个分层、并行、消息传递状态机形式:

  • 分层:状态机可以嵌套。
  • 并行:可以同时激活多个状态。
  • 消息传递:转换可以将信息传输到其目标节点

Fancy State Machines

cozmo_fsm is a hierarchical, parallel, message passing state machine formalism:

  • Hierarchical: state machines can nest.
  • Parallel: multiple states can be active at the same time.
  • Message passing: transitions can transmit information to their target nodes

机器人前进或转向后,位置的变化数据。The change in position and orientation data is output after the robot moves forward or turns.

案例 demo:


  
  1. """
  2. The BackItUp demo illustrates the use of fork/join to launch
  3. parallel actions and synchronize them again. The fork is performed
  4. by the NullTrans transition with two destinations, while the join is
  5. performed by the CompletionTrans transition with two sources.
  6. Behavior: Cozmo backs up by 100 mm while simultaneously beeping. He
  7. uses DriveForward instead of Forward to avoid conflict with the Say
  8. action. When he's done backing up, he stops beeping and says 'Safety first'.
  9. """
  10. try:
  11. from cozmo_fsm import *
  12. except ImportError:
  13. raise ImportError("Can't find the cozmo_fsm package. Check your search path.")
  14. class BackItUp(StateMachineProgram):
  15. def setup(self):
  16. """
  17. launcher: StateNode() =N=> {driver, speaker}
  18. driver: Forward(-100,10)
  19. speaker: Say('beep',duration_scalar=0.8,abort_on_stop=True) =C=> speaker
  20. {driver,speaker} =C=> finisher: Say('Safety first!')
  21. """
  22. # Code generated by genfsm on Thu Feb 16 23:51:48 2017:
  23. launcher = StateNode() .set_name("launcher") .set_parent(self)
  24. driver = Forward(-100,10) .set_name("driver") .set_parent(self)
  25. speaker = Say('beep',duration_scalar=0.8,abort_on_stop=True) .set_name("speaker") .set_parent(self)
  26. finisher = Say('Safety first!') .set_name("finisher") .set_parent(self)
  27. nulltrans1 = NullTrans() .set_name("nulltrans1")
  28. nulltrans1 .add_sources(launcher) .add_destinations(driver,speaker)
  29. completiontrans1 = CompletionTrans() .set_name("completiontrans1")
  30. completiontrans1 .add_sources(speaker) .add_destinations(speaker)
  31. completiontrans2 = CompletionTrans() .set_name("completiontrans2")
  32. completiontrans2 .add_sources(driver,speaker) .add_destinations(finisher)
  33. return self

particle_fiter_demo:

立方体 cube 

tf:

 


持续更新完善,时间标签:2019-07-26。


参考文献references:

Anki文档:http://cozmosdk.anki.com/docs/
cozmopedia:https://github.com/touretzkyds/cozmopedia/wiki
认知机器人学:https://blog.csdn.net/ZhangRelay/article/details/86736743


 

文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。

原文链接:zhangrelay.blog.csdn.net/article/details/97364546

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。