cad2025 電腦輔助設計與實習

  • Home
    • SMap
    • reveal
    • blog
  • About
    • Mind-Map
    • AI
      • Teams
      • Prompts
    • Homework
      • HW2
      • Plotter
  • Topics
    • Network
    • ICMP
    • IPv6
    • DNS
    • Proxy
    • Web
      • Codespaces
  • Software
    • Git
    • CMSiMDE
      • Flask
    • Solvespace
      • Compile
    • NX2312
      • License
    • Onshape
    • Webots
      • Fourbar
      • TimeStep
      • Clouds
      • Talks
      • Blender
      • Ardupilot
  • Tutorial
    • Stage1
      • Tutorial1
      • Tutorial2
    • Stage2
      • Tutorial3
      • Distancesensor
      • Tutorial4
      • Tutorial5
    • Stage3
      • Tutorial6
      • Tutorial7
      • Stream
      • Webots Server
  • Projects
    • Control
    • Printer
    • Otto
    • Otto_ninja-1
      • Simplify
    • OpenDuck
    • Pupper
    • JetAcker
  • Brython
  • Ref
    • Reeborg
      • ex1
      • Otto_ninja-2
    • Pyodide
    • Pyodide_ex
    • Pyodide2
      • robot.py
      • Example2
    • Pyodide3
      • png_files
      • Harvest
robot.py << Previous Next >> Pyodide3

Example2

自行定義機器人右轉的非同步執行函式:

執行 turn_right 程式範例。

import robot
import asyncio

# 定義右轉的非同步函式
async def turn_right(bot):
    for _ in range(3):
        await bot.turn_left()

async def main():
    world, bot = await robot.init(10, 10, 1, 1)
    print("機器人開始行動")
    await bot.turn_left()
    await bot.walk(9)
    await turn_right(bot) 
    print("機器人完成行動")

# main() 讓出執行控制權,由頁面中的 even loop 決定何時執行 main()
await main()

robot.py << Previous Next >> Pyodide3

Copyright © All rights reserved | This template is made with by Colorlib