PWM Motor Controllers in Depth

İpucu

WPILib has extensive support for motor control. There are a number of classes that represent different types of motor controllers and servos. There are currently two classes of motor controllers, PWM based motor controllers and CAN based motor controllers. WPILib also contains composite classes (like DifferentialDrive) which allow you to control multiple motors with a single object. This article will cover the details of PWM motor controllers; CAN controllers and composite classes will be covered in separate articles.

PWM Controllers, brief theory of operation

The acronym PWM stands for Pulse Width Modulation. For motor controllers, PWM can refer to both the input signal and the method the controller uses to control motor speed. To control the speed of the motor the controller must vary the perceived input voltage of the motor. To do this the controller switches the full input voltage on and off very quickly, varying the amount of time it is on based on the control signal. Because of the mechanical and electrical time constants of the types of motors used in FRC® this rapid switching produces an effect equivalent to that of applying a fixed lower voltage (50% switching produces the same effect as applying ~6V).

The PWM signal the controllers use for an input is a little bit different. Even at the bounds of the signal range (max forward or max reverse) the signal never approaches a duty cycle of 0% or 100%. Instead the controllers use a signal with a period of either 5ms or 10ms and a midpoint pulse width of 1.5ms. Many of the controllers use the typical hobby RC controller timing of 1ms to 2ms.

Raw vs Scaled output values

Genellikle WPILib’deki tüm kontrolör sınıfları bir aktüatör çıktısı olarak -1.0 ila 1.0 arasında dereceli bir değer kabul etmektedir. roboRIO üzerindeki FPGA’nın PWM modülü 5, 10 veya 20ms’lik aralıklarla PWM sinyalleri oluşturuabilmekte ve darbe süresini her biri 1us’de 4096 adım olacak şekilde kipleyebilmektedir. Bu modüle gönderilen ham değerler, 0’ın sinyali aşağıda tutan (etkisiz bırakan) özel bir durum olduğu, bu 0-4096 aralığındadır. Her bir motor sınıfının motor kontrolörü, yaygın sınır değerlerinin (min, maks ve ölü bölgenin her iki tarafının) ne olduğu bilgisinin yanı sıra yaygın orta noktanın ne olduğunu içermektedir. WPILib ardıdan bu değerleri, ölçeli değerleri motor kontrolör için uygun bir aralığa atamak için kullanmaktadır. Bu işlem kodun pürüzsüz bir şekilde farklı kontrolör türleri arasında geçiş yapmasına olanak tanımakta ve belirli sinyalleşmenin ayrıntılarını ayırmaktadır.

Calibrating Motor Controllers

So if WPILib handles all this scaling, why would you ever need to calibrate your motor controller? The values WPILib uses for scaling are approximate based on measurement of a number of samples of each controller type. Due to a variety of factors, the timing of an individual motor controller may vary slightly. In order to definitively eliminate “humming” (midpoint signal interpreted as slight movement in one direction) and drive the controller all the way to each extreme, calibrating the controllers is still recommended. In general, the calibration procedure for each controller involves putting the controller into calibration mode then driving the input signal to each extreme, then back to the midpoint. For examples on how to use these motor controllers in your code, see Using Motor Controllers in Code/Using PWM Motor Controllers