脈衝寬度調變(PWM)#

介紹#

脈衝寬度調變 (PWM) 透過 3 線連接埠輸出定時脈衝訊號,使 EXP 大腦能夠透過每 16 毫秒 (ms) 改變脈衝寬度(佔空比)來控制傳統的 馬達控制器或伺服馬達。

注意: Pwm 物件產生原始 RC 型 PWM 波形:

  • 0% 輸出產生 1.5 毫秒的脈衝。

  • 100% 輸出產生 2.0 毫秒的脈衝。

  • -100% 輸出產生 1.0 毫秒的脈衝。

本頁面使用 pwm_a 作為範例 PWM 輸出名稱。您可以根據需要將其替換為您自己配置的名稱。

以下是可用方法清單:

  • value – 傳回 PWM 輸出的目前值。

  • state – 設定 PWM 輸出值。

建構函式 – 手動初始化和配置 PWM 輸出。

  • Pwm – 建立一個 PWM 輸出。

價值#

value 傳回 PWM 輸出值(範圍從 -100 到 100),以百分比表示。

Usage:
pwm_a.value()

參數

描述

此方法沒有參數。

狀態#

state 將 PWM 輸出的狀態設定為百分比。

Usage:
pwm_a.state(value)

參數

描述

value

PWM 輸出值設定範圍為 -100 到 100。

建構函數#

建構函數用於建立 Pwm 對象,這些對像是配置 PWM 輸出所必需的。

Pwm#

Pwm 產生 PWM 輸出。

Usage:
Pwm(port)

範圍

描述

port

The 3-Wire Port that the PWM output is connected to:

  • On the EXP Brain – brain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expander – expander.a where expander is the name of the expander instance.

# Create a PWM output in Port A
pwm_a = Pwm(brain.three_wire_port.a)