Class SpeedController4DCMotor
- java.lang.Object
-
- org.deepjava.runtime.zynq7000.sysp.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!).
-
-
Field Summary
Fields Modifier and Type Field Description FlinkCounter
enc
-
Fields inherited from interface org.deepjava.flink.core.FlinkDefinitions
ANALOG_INPUT_INTERFACE_ID, ANALOG_OUTPUT_INTERFACE_ID, CHANNEL_OFFSET, COUNTER_INTERFACE_ID, GPIO_INTERFACE_ID, HEADER_SIZE, INFO_DEVICE_ID, INFO_DEVICE_SIZE, INTERFACE_TYPE_MASK, MOD_CONF_OFFSET, MOD_STATUS_OFFSET, PPWA_INTERFACE_ID, PWM_INTERFACE_ID, REGISTER_WIDTH, REGISTER_WIDTH_BIT, SIZE_OFFSET, SUBHEADER_SIZE, TOTAL_HEADER_SIZE, TYPE_OFFSET, UART_INTERFACE_ID, UNIQUE_ID_OFFSET, WD_INTERFACE_ID
-
-
Constructor Summary
Constructors Constructor Description 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.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description float
getPosition()
Returns the current absolute position.float
getSpeed()
Returns the current speed.void
run()
Controller task method.void
setPwmFreq(int f)
Set desired PWM frequency.void
setSpeed(float v)
Set desired speed.
-
-
-
Field Detail
-
enc
public FlinkCounter enc
-
-
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
-
-