---
# System prepended metadata

title: Motor Control in Depth==More Motor Control==
tags: [程式組教程]

---

###### tags: `程式組教程`

# Motor Control in Depth==More Motor Control==

## Mecanum Drive
:::spoiler How its wheels look like

![](https://i.imgur.com/Pb6Eywa.png)

:::

:::spoiler thoery

麥克納姆輪的設計原理是在車輪的外環中安裝了與軸心成45度角排列的輥子與地面接觸，轉動時摩擦力會產生與輪軸呈45度的反推力，這個斜向推力可以被分為縱向和橫向兩個向量。整個車體由兩對擁有輥子鏡像排列的麥克納姆輪所驅動，每個車輪各自會產生相應的向量，這些向量的合力決定了車體最終的活動狀態。通過調節各個車輪獨自的轉向和轉速，可以實現整個車體前行、橫移、斜行、旋轉及其組合等運動方式。

麥克納姆輪的優點在於結構緊湊、運動靈活，非常適合空間狹窄有限、直角彎偏多的作業環境。缺點是因為各個輪子產生的向量會相互抵消，因此同樣轉矩產生的淨推力效率較低。同時輥輪結構較為複雜，成本也較高，抗磨損能力也遠遠遜於普通的單向輪胎，只適合比較平滑的陸面，遭遇粗糙複雜的地形時耐久性要大打折扣。

![](https://i.imgur.com/JAlNEfD.png)

:::

::: spoiler code
``` java
    public void robotInit() {
    PWMSparkMax frontLeft = new PWMSparkMax(kFrontLeftChannel);
    PWMSparkMax rearLeft = new PWMSparkMax(kRearLeftChannel);
    PWMSparkMax frontRight = new PWMSparkMax(kFrontRightChannel);
    PWMSparkMax rearRight = new PWMSparkMax(kRearRightChannel);

    
    frontRight.setInverted(true);
    rearRight.setInverted(true);

    m_robotDrive = new MecanumDrive(frontLeft, rearLeft, frontRight, rearRight);

    m_stick = new Joystick(kJoystickChannel);
  }
```
``` java
    public void teleopPeriodic() {
    m_robotDrive.driveCartesian(-m_stick.getY(), m_stick.getX(), m_stick.getZ());
    m_robotDrive.drivePolar(-m_stick.getY(), m_stick.getX(), m_stick.getZ());
}
/// choose one
```
**driveCartesian** : Angles are measured clockwise from the positive X axis. The robot’s speed is independent from its angle or rotation rate.

:::
