public static void Main (string[] args) { Motor motor = new Motor(MotorPort.OutA); motor.ResetTacho(); PositionPID PID = new PositionPID(motor, 4000, true, 50, P, I, D, 5000); var waitHandle = PID.Run(); Console.WriteLine("Moving motor A to position 4000"); Console.WriteLine("Waiting for controller to finish"); //Wait for controller to finish - you can do other stuff here waitHandle.WaitOne(); Console.WriteLine("Done"); Console.WriteLine("Motor position: " + motor.GetTachoCount()); }
/// <summary> /// Initializes a new instance of the <see cref="MonoBrickFirmware.IO.Motor"/> class. /// </summary> /// <param name="port">Port.</param> public Motor(MotorPort port) { this.BitField = MotorPortToBitfield(port); Reverse = false; controller = new PositionPID (port, 0, false, 100, standardPValue, standardIValue, standardIValue, controllerSampleTime); }
public void MoveTo(sbyte maxPower, Int32 position, bool brake, float P, float I, float D, bool waitForCompletion = true) { controller.Cancel (); controller = new PositionPID (PortList [0], position, brake, maxPower, P, I, D, controllerSampleTime); controller.Run (waitForCompletion); }
/// <summary> /// Moves the motor to an absolute position /// </summary> /// <param name='maxPower'> /// maxPower of the motor 0 to 100 /// </param> /// <param name='position'> /// Absolute position /// </param> /// <param name='brake'> /// Set to <c>true</c> if the motor should brake when done /// </param> /// <param name='waitForCompletion'> /// Set to <c>true</c> to wait for movement to be completed before returning /// </param> public void MoveTo(sbyte maxPower, Int32 position, bool brake, bool waitForCompletion = true) { var controller = new PositionPID(PortList[0], position, brake, maxPower, 0.1f, 80.1f, 1.05f, 40); controller.Run(true); }