Cozmo人工智慧機器人SDK使用筆記(6)-並行部分Parallel_Action
Cozmo並行動作示例。
此示例演示如何並行(而不是按順序)執行動作。
import sys
import time
try:
from PIL import Image
except ImportError:
sys.exit("Cannot import from PIL: Do `pip3 install --user Pillow` to install")
import cozmo
from cozmo.util import degrees, distance_mm, speed_mmps
# load an image to display on Cozmo's face
face_image = Image.open("../../face_images/cozmosdk.png")
# resize to fit on Cozmo's face screen
face_image = face_image.resize(cozmo.oled_face.dimensions(), Image.BICUBIC)
# convert the image to the format used by the oled screen
face_image = cozmo.oled_face.convert_image_to_screen_data(face_image,
invert_image=True)
def example1_lift_head(robot: cozmo.robot.Robot):
cozmo.logger.info("----------------------------------------")
cozmo.logger.info("Example 1: Move Lift and Head in Parallel")
cozmo.logger.info("First, move the lift and head down, in sequence.")
robot.set_head_angle(cozmo.robot.MIN_HEAD_ANGLE).wait_for_completed()
robot.set_lift_height(0.0).wait_for_completed()
cozmo.logger.info("Now, move the lift and head back up, in parallel "
"- we no longer have to wait for the 1st action to complete "
"before starting the 2nd one because the 2nd action is in_parallel")
action1 = robot.set_head_angle(cozmo.robot.MAX_HEAD_ANGLE)
action2 = robot.set_lift_height(1.0, in_parallel=True)
action1.wait_for_completed()
action2.wait_for_completed()
cozmo.logger.info("action1 = %s", action1)
cozmo.logger.info("action2 = %s", action2)
def example2_conflicting_actions(robot: cozmo.robot.Robot):
cozmo.logger.info("----------------------------------------")
cozmo.logger.info("Example 2: Conflicting actions.")
cozmo.logger.info("Try to drive straight and turn in parallel. This is not "
"allowed, as both actions require use of the wheels, so the 2nd action "
"will report failure due to tracks_locked.")
action1 = robot.drive_straight(distance_mm(50), speed_mmps(25), should_play_anim=False, in_parallel=True)
action2 = robot.turn_in_place(degrees(90), in_parallel=True)
action2.wait_for_completed()
cozmo.logger.info("action2 = %s", action2)
action1.wait_for_completed()
cozmo.logger.info("action1 = %s", action1)
def example3_abort_one_action(robot: cozmo.robot.Robot):
cozmo.logger.info("----------------------------------------")
cozmo.logger.info("Example 3: Abort some parallel actions.")
cozmo.logger.info("Start multiple parallel actions:")
action1 = robot.set_lift_height(0.0, in_parallel=True)
action2 = robot.set_head_angle(cozmo.robot.MIN_HEAD_ANGLE, duration=6.0, in_parallel=True)
action3 = robot.drive_straight(distance_mm(75), speed_mmps(25), should_play_anim=False, in_parallel=True)
action4 = robot.display_oled_face_image(face_image, 30000.0) # Note: face image is in_parallel by default
# Lift-lowering is aborted immediately
action1.abort(log_abort_messages=True)
# Head-lowering is aborted shortly afterwards
time.sleep(0.1)
action2.abort(log_abort_messages=True)
# Image on Cozmo's face is aborted another 2 seconds later
time.sleep(2)
action4.abort(log_abort_messages=True)
# We wait for the one remaining action to complete
action3.wait_for_completed()
# Only action3 should succeed (as long as Cozmo had enough space to drive)
cozmo.logger.info("action1 = %s", action1)
cozmo.logger.info("action2 = %s", action2)
cozmo.logger.info("action3 = %s", action3)
cozmo.logger.info("action4 = %s", action4)
def example4_abort_all_actions(robot: cozmo.robot.Robot):
cozmo.logger.info("----------------------------------------")
cozmo.logger.info("Example 4: Abort all parallel actions.")
cozmo.logger.info("Start multiple parallel actions:")
action1 = robot.set_lift_height(0.0, in_parallel=True, duration=6.0)
action2 = robot.set_head_angle(cozmo.robot.MAX_HEAD_ANGLE, duration=6.0, in_parallel=True)
action3 = robot.drive_straight(distance_mm(75), speed_mmps(25), should_play_anim=False, in_parallel=True)
action4 = robot.display_oled_face_image(face_image, 30000.0) # Note: face image is in_parallel by default
# wait two seconds and abort everything
time.sleep(2)
robot.abort_all_actions(log_abort_messages=True)
# wait for results to come back for all actions
robot.wait_for_all_actions_completed()
# All actions should have aborted
cozmo.logger.info("action1 res = %s", action1)
cozmo.logger.info("action2 res = %s", action2)
cozmo.logger.info("action3 res = %s", action3)
cozmo.logger.info("action4 res = %s", action4)
def cozmo_program(robot: cozmo.robot.Robot):
example1_lift_head(robot)
example2_conflicting_actions(robot)
example3_abort_one_action(robot)
example4_abort_all_actions(robot)
cozmo.logger.info("----------------------------------------")
cozmo.run_program(cozmo_program)
Fin
相關文章
- Cozmo人工智慧機器人SDK使用筆記(1)-基礎部分basics人工智慧機器人筆記
- Cozmo人工智慧機器人SDK使用筆記(3)-視覺部分vision人工智慧機器人筆記視覺
- Cozmo人工智慧機器人SDK使用筆記(2)-顯示部分face人工智慧機器人筆記
- Cozmo人工智慧機器人SDK使用筆記(9)-判斷部分if_this_then_that人工智慧機器人筆記
- Cozmo人工智慧機器人SDK使用筆記(8)-應用部分apps人工智慧機器人筆記APP
- Cozmo人工智慧機器人SDK使用筆記(4)-任務部分cubes_and_objects人工智慧機器人筆記Object
- Cozmo人工智慧機器人SDK使用筆記(5)-時序部分async_sync人工智慧機器人筆記
- Cozmo人工智慧機器人SDK使用筆記(7)-補充說明人工智慧機器人筆記
- Vector人工智慧機器人SDK使用筆記人工智慧機器人筆記
- Cozmo人工智慧機器人SDK使用筆記(X)-總結- |人工智慧基礎(中小學版)實踐平臺|人工智慧機器人筆記
- Anki Cozmo(Vector)人工智慧機器人玩具部分文件人工智慧機器人
- ROS2GO之手機連線Cozmo人工智慧機器人玩具ROSGo人工智慧機器人
- Cozmo機器人使用中文Scratch3程式設計案例(codelab)機器人程式設計
- Tello無人機的使用筆記之dji-sdk/Tello-Python無人機筆記Python
- Cozmo機器人脫離智慧手機使用的不完全攻略機器人
- ROS2GO+Cozmo=口袋機器人之人工智慧模擬和實驗平臺ROSGo機器人人工智慧
- 【機器學習】支援向量機(個人筆記)機器學習筆記
- 2024.11.5人工智慧學記6人工智慧
- 關於聊天機器人的閱讀筆記機器人筆記
- Python機器學習筆記:使用Keras進行迴歸預測Python機器學習筆記Keras
- Cozmo人工智慧機器人玩具/教具完整版中文說明書和介紹(附應用下載連結)人工智慧機器人
- 讀人工智慧時代與人類未來筆記06_機器學習的力量人工智慧筆記機器學習
- 《深入理解Java虛擬機器》個人筆記Java虛擬機筆記
- 讀AI未來進行式筆記04數字醫療與機器人AI筆記機器人
- Git筆記-部分命令Git筆記
- Vector人工智慧情感機器人SDK釋出和說明(ROS2GO 2.0 + Vector 2.0)人工智慧機器人ROSGo
- 人工智慧核心6技術,機遇與挑戰並存人工智慧
- 機器學習筆記機器學習筆記
- Java併發程式設計筆記6:執行緒池的使用Java程式設計筆記執行緒
- Windows sdk程式設計筆記Windows程式設計筆記
- Qt學習筆記-使用QScreen對螢幕進行截圖(可全屏,可部分)QT筆記
- 讀書筆記-2020年6月-《人間值得》筆記
- 使用人工智慧機器人提高農業效率 | 資料標註人工智慧機器人
- 機器人市場機遇和挑戰並存機器人
- 江湖微信公眾號機器人飛單機器人娛樂系統部分原始碼機器人原始碼
- RK3568開發筆記(五):在虛擬機器上使用SDK編譯製作uboot、kernel和ubuntu映象筆記虛擬機編譯bootUbuntu
- RK3568開發筆記(四):在虛擬機器上使用SDK編譯製作uboot、kernel和buildroot映象筆記虛擬機編譯bootUI
- 讀AI新生:破解人機共存密碼筆記12人工智慧辯論AI密碼筆記人工智慧