38 OutputMode, OUT_MODE_MOTORON | OUT_MODE_BRAKE,
40 UpdateFlags, UF_UPDATE_MODE | UF_UPDATE_SPEED | UF_UPDATE_RESET_BLOCK_COUNT,
41 RunState, OUT_RUNSTATE_RUNNING);
50 OutputMode, OUT_MODE_BRAKE,
52 UpdateFlags, UF_UPDATE_MODE | UF_UPDATE_SPEED,
53 RunState, OUT_RUNSTATE_IDLE);
61 SetOutput(motor, Power, power, UpdateFlags, UF_UPDATE_SPEED);
74 ArrayBuild(motors, motor1, motor2);
77 OutputMode, OUT_MODE_MOTORON | OUT_MODE_BRAKE | OUT_MODE_REGULATED,
80 RegMode, OUT_REGMODE_SYNC,
81 UpdateFlags, UF_UPDATE_MODE | UF_UPDATE_SPEED | UF_UPDATE_RESET_BLOCK_COUNT,
82 RunState, OUT_RUNSTATE_RUNNING);
91 ArrayBuild(motors, motor1, motor2);
93 OutputMode, OUT_MODE_BRAKE,
95 UpdateFlags, UF_UPDATE_MODE | UF_UPDATE_SPEED,
96 RunState, OUT_RUNSTATE_IDLE);
105 ArrayBuild(motors, motor1, motor2);
106 SetOutput(motors, Power, power, UpdateFlags, UF_UPDATE_SPEED);
116 ArrayBuild(motors, motor1, motor2);
117 SetOutput(motors, TurnRatio, turnRatio);
127 ArrayBuild(motors, motor1, motor2);
128 SetOutput(motors, TurnRatio, turnRatio, Power, power, UpdateFlags, UF_UPDATE_SPEED);
136 long PValue,
long IValue,
long DValue)
138 int samplingPeriod = 20;
139 long motorTacho, output, lastError;
158 motorTacho = GetOutput(motor, BlockTachoCount);
161 Wait(samplingPeriod);
174 long PValue,
long IValue,
long DValue)
176 int samplingPeriod = 20;
177 long motorTacho, output, lastError;
196 motorTacho = GetOutput(motor1, BlockTachoCount);
199 Wait(samplingPeriod);
212 long PValue,
long IValue,
long DValue)
214 int samplingPeriod = 20;
215 long motorTacho, output, lastError;
240 motorTacho = GetOutput(motor1, BlockTachoCount);
248 Wait(samplingPeriod);
258 #define TEST_ANGLE 180
260 task TestMotorRotate ()
265 task TestMotorRotateSync ()
270 task TestMotorRotateDiff ()
280 PlotterInit(pe, PLOT_TYPE_LINE, 0, 100, -180, 180);
283 start TestMotorRotateSync;
288 int error = (TEST_ANGLE - GetOutput(OUT_B, TachoCount)) * 32 / TEST_ANGLE;
314 start TestMotorRotateDiff;
long PIDControlStep(PIDControl &pidControl, long currentPoint)
Steps the PID controller. currentPoint is the current state of the system. The return value is the ou...
void MotorStartSync(int motor1, int motor2, int power)
Starts the given 2 motors in synchronous mode with with the given initial power.
void MotorStart(int motor, int power)
Starts the given motor with the given power.
void MotorSetPowerSync(int motor1, int motor2, int power)
Sets the power of the given motor pair.
void MotorSetTurnRatio(int motor1, int motor2, int turnRatio)
Sets the turn ratio of the given motor pair running in synchronous mode.
void PlotterPlot(Plotter &plotter, long x, long y)
Plots the given point using the plotter on screen.
void MotorSetPower(int motor, int power)
Set the power of given motor.
void PIDControlInit(PIDControl &pidControl, long PIDScale, long PValue, long IValue, long DValue, int steadyStateCountThreshold, long outputGain, long absMaxOutput)
Initializes a PID controller with the given P, I and D values, output parameters. ...
bool PIDControlCheckEnd(PIDControl &pidControl)
Checks if the PID controller has ended.
void PlotterInit(Plotter &plotter, int plotType, long minX, long maxX, long minY, long maxY)
Initializes a plotter. There can be multiple plotters (for each graph) active simultaneous to draw on...
void MotorStopSync(int motor1, int motor2)
Stops the given two motor pair.
int MotorRotateAngleDiff(int motor1, int motor2, int power, long angle, long PValue, long IValue, long DValue)
Rotates the given pair of motors differentially (that is they rotate at the same pace in opposite dir...
Generic PID controller implementation.
void MotorStop(int motor)
Stops the given motor.
void PIDControlSetIntegralLimit(PIDControl &pidControl, long absIntegralLimit)
Sets integral output absolute maximum used to prevent integral windup. The default is set to absMaxOu...
int MotorRotateAngle(int motor, int power, long angle, long PValue, long IValue, long DValue)
Rotates the given motor by given angle using the specified P, I and D gain values. The power is the maximum power to use for rotation.
void PIDControlSetPoint(PIDControl &pidControl, long setPoint)
Sets a new set point for the controller. The controller state is reset and the new target is pursued...
long PIDControlGetLastError(PIDControl &pidControl)
Gets the error from the last step.
void MotorSetTurnRatioPower(int motor1, int motor2, int turnRatio, int power)
Sets the turn ratio and power at the same time of the given motor pair running in synchronous mode...
Display functions for text and graphs.
int MotorRotateAngleSync(int motor1, int motor2, int power, long angle, long PValue, long IValue, long DValue)
Rotates the given pair of motors synchromously (that is they rotate at the same pace) by given angle ...