cd2025 協同產品設計實習

  • Home
    • SMap
    • reveal
    • blog
  • About
    • Summary
      • Tasks
      • Closing
      • Shooter
    • Product
    • Control
    • CPS
    • AI
    • Project
  • Topics
    • Wink
      • Fossil
    • Topic1
      • w1
      • Portable
      • repo
      • SSH
      • list
      • IPv6
    • Topic2
      • Compile
      • Onshape
    • Topic3
      • Fourbar2
      • boomer
    • Topic4
      • ROS2
  • HW
    • HW1
    • HW2
    • HW3
  • Exam
    • Exam1
    • Exam2
    • Exam3
  • Final
    • Webots
    • Rotate
  • Tutorial
    • Fourbar
      • w10
    • Stage1
      • Tutorial1
      • Tutorial2
    • Stage2
      • Tutorial3
      • Distancesensor
      • Tutorial4
      • Tutorial5
    • Stage3
      • Tutorial6
      • Tutorial7
      • Stream
      • Webots Server
    • Solvespace
      • Learn_Solvs
    • Mecanum
    • Pyslvs-UI
    • PICSimLab
    • Fossil SCM
    • Leo Editor
    • uv
    • Old
  • Brython
Tasks << Previous Next >> Shooter

Closing

在 Webots supervisor 模式下建立 sphere (利用監控模式建立節點):

# 定義一個函數,用於創建球的節點
def create_sphere(supervisor, position):
    def_name = generate_valid_def_name()  # 獲取唯一的 DEF 名稱
    sphere_string = f"""
    DEF {def_name} Solid {{
      translation {position[0]} {position[1]} {position[2]}  # 設置球的初始位置
      children [
        Shape {{
          geometry Sphere {{
            radius {sphere_radius}  # 設置球的半徑
          }}
          appearance Appearance {{
            material Material {{
              diffuseColor 1 0 0  # 設置球的顏色為紅色
            }}
          }}
        }}
      ]
      physics Physics {{
        mass 0.1  # 設置球的質量
      }}
      boundingObject Sphere {{
        radius {sphere_radius}  # 設置碰撞邊界為球形
      }}
    }}
    """
    root = supervisor.getRoot()  # 獲取模擬場景的根節點
    children_field = root.getField("children")  # 獲取根節點的子節點字段
    children_field.importMFNodeFromString(-1, sphere_string)  # 將新創建的球節點加入模擬
    return def_name  # 返回球的 DEF 名稱

在 supervisor 模式移除節點 (remove node):

# 定義一個函數,用於移除球的節點
def remove_object(node):
    node.remove()  # 調用 Webots 的 remove 方法移除節點


Tasks << Previous Next >> Shooter

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