Class SpeedController4DCMotor

  • All Implemented Interfaces:
    FlinkDefinitions

    public class SpeedController4DCMotor
    extends Object
    implements FlinkDefinitions
    Speed controller (PI control) for DC motor.
    This controller can work with two pwm channels operating in sign-magnitude mode or it can work with one pwm channel operating in locked-antiphase mode.
    IMPORTANT: The motor and the encoder have to be connected carefully. A positive speed control must lead to a positive speed reading. If this is not the case you have to change either the connections to the motor or the signals of the encoder (but not both!).
    • Constructor Detail

      • SpeedController4DCMotor

        public SpeedController4DCMotor​(float ts,
                                       int pwmChannel1,
                                       int pwmChannel2,
                                       int encChannel,
                                       int encTPR,
                                       float umax,
                                       float i,
                                       float kp,
                                       float tn)
        Create a new speed controller for a DC motor. The controller works in sign-magnitude mode using two PWM signals.
        Parameters:
        ts - task period in seconds [s]
        pwmChannel1 - channel for the first PWM signal.
        pwmChannel2 - channel for the second PWM signal.
        encChannel - channel for the encoder signal. Connect both A and B to the associated pins.
        encTPR - impulse/ticks per rotation of the encoder.
        umax - maximum output voltage of set value.
        i - gear transmission ratio.
        kp - controller gain factor. For experimental evaluating the controller parameters, begin with kp = 1.
        tn - time constant of the controller. For experimental evaluating the controller parameters, set tn to the mechanical time constant of your axis. If the motor has a gear it's assumed that the torque of inertia of the rotor is dominant. That means you can set tn equals to the mechanical time constant of your motor.
      • SpeedController4DCMotor

        public SpeedController4DCMotor​(float ts,
                                       int pwmChannel,
                                       int encChannel,
                                       int encTPR,
                                       float umax,
                                       float i,
                                       float kp,
                                       float tn)
        Create a new speed controller for a DC motor. The controller works in locked-antiphase mode using a single PWM signal.
        Parameters:
        ts - task period in seconds [s]
        pwmChannel - channel for the PWM signal.
        encChannel - channel for the encoder signal. Connect both A and B to the associated pins.
        encTPR - impulse/ticks per rotation of the encoder.
        umax - maximum output voltage of set value.
        i - gear transmission ratio.
        kp - controller gain factor. For experimental evaluating the controller parameters, begin with kp = 1.
        tn - time constant of the controller. For experimental evaluating the controller parameters, set tn to the mechanical time constant of your axis. If the motor has a gear it's assumed that the torque of inertia of the rotor is dominant. That means you can set tn equals to the mechanical time constant of your motor.
    • Method Detail

      • run

        public void run()
        Controller task method. Call this method periodically with the given period time (ts)!
      • setSpeed

        public void setSpeed​(float v)
        Set desired speed.
        Parameters:
        v - desired speed in radian per second [1/s]
      • setPwmFreq

        public void setPwmFreq​(int f)
        Set desired PWM frequency. Default is 20000Hz.
        Parameters:
        f - frequency of the pwm control signal in Hz
      • getSpeed

        public float getSpeed()
        Returns the current speed.
        Returns:
        current speed in radian per second [1/s]
      • getPosition

        public float getPosition()
        Returns the current absolute position.
        Returns:
        absolute position in radian