public static void Main(string[] args) { ButtonEvents buts = new ButtonEvents(); bool run = true; buts.EscapePressed += () => { run = false; }; MotorSync motori = new MotorSync(MotorPort.OutB, MotorPort.OutD); EV3IRSensor ir = new EV3IRSensor(SensorPort.In3, IRMode.Proximity); Thread bg = new Thread(Scan); bg.Start(); while (run && ir.Read() > 80) { LcdConsole.WriteLine(ir.Read().ToString()); Thread.Sleep(200); } bg.Abort(); motori.Brake(); motori.Off(); }
private void Move(sbyte speed, uint steps) { var motorSync = new MotorSync(Constants.MOTOR_LEFT_PORT, Constants.MOTOR_RIGHT_PORT); WaitHandle waitHandle = motorSync.StepSync(speed, 0, steps, true); waitHandle.WaitOne(); motorSync.Off(); Thread.Sleep(100); }
public static void Main(string[] args) { Buttons btns = new Buttons(); Motor motor = new Motor(MotorPort.OutA); MotorSync motorSync = new MotorSync(MotorPort.OutA, MotorPort.OutD); LcdConsole.WriteLine("Use Motor on A"); LcdConsole.WriteLine("Use Motor on D"); LcdConsole.WriteLine("Press Ent. to start"); btns.GetKeypress(); motor.ResetTacho(); LcdConsole.WriteLine("Running forward with 20"); motor.On(20); System.Threading.Thread.Sleep(2500); LcdConsole.WriteLine("Printing motor speed: " + motor.GetSpeed()); System.Threading.Thread.Sleep(2500); LcdConsole.WriteLine("Running backwards with 70"); motor.On(-70); System.Threading.Thread.Sleep(3000); LcdConsole.WriteLine("Reverse direction"); motor.Reverse = true; System.Threading.Thread.Sleep(3000); LcdConsole.WriteLine("Brake"); motor.Reverse = false; motor.Brake(); System.Threading.Thread.Sleep(3000); LcdConsole.WriteLine("Off"); motor.Off(); System.Threading.Thread.Sleep(3000); LcdConsole.WriteLine("Move to zero"); motor.MoveTo(40, 0, true); LcdConsole.WriteLine("Motor at position: " + motor.GetTachoCount()); System.Threading.Thread.Sleep(2000); LcdConsole.WriteLine("Creating a step profile"); motor.SpeedProfileStep(40, 100, 1500, 100, true); motor.Off(); LcdConsole.WriteLine("Motor at position: " + motor.GetTachoCount()); System.Threading.Thread.Sleep(2000); LcdConsole.WriteLine("Motor " + motorSync.BitField + " synchronised forward for 2500 steps"); motorSync.On(50, 0, 2500, true); motorSync.Off(); LcdConsole.WriteLine("Motor " + motorSync.BitField + " synchronised with second motor moving at half speed"); motorSync.On(-20, 50, 2500, false); //coast when done LcdConsole.WriteLine("Done executing motor test"); }
public static void Main(string[] args) { try { ButtonEvents buts = new ButtonEvents(); buts.EscapePressed += () => { throw new Exception("Escape gumb je stisnut!"); }; ArmCalibrate(); ArmMove(ArmPosition.Closed); color.Mode = ColorMode.Reflection; while (true) { if (Search()) { Pickup(); Carry(); Dropoff(); } else { LcdConsole.WriteLine("Ceo sto je ociscen!"); Carry(); break; } } } catch (Exception ex) { InfoDialog d = new InfoDialog(ex.Message, "Exception"); d.Show(); Thread.Sleep(2000); } finally { motors.Off(); armMotor.Off(); Thread.Sleep(500); } }
public void Off() { Log.Debug("motors off"); sync.Off(); }
public static void Main(string[] args) { Motor motorA = new Motor(MotorPort.OutA); Motor motorD = new Motor(MotorPort.OutD); WaitHandle motorWaitHandle; motorA.Off(); motorD.Off(); //Power control LcdConsole.WriteLine("Set power to 50"); motorA.SetPower(50); Thread.Sleep(3000); LcdConsole.WriteLine("Break"); motorA.Brake(); //Speed control LcdConsole.WriteLine("Set speed to 50"); motorA.SetSpeed(50); Thread.Sleep(1000); LcdConsole.WriteLine("Speed: " + motorA.GetSpeed()); Thread.Sleep(2000); LcdConsole.WriteLine("Break"); motorA.Brake(); //Position control of single motor Thread.Sleep(3000); motorA.ResetTacho(); LcdConsole.WriteLine("Moving motor A to 2000 "); motorWaitHandle = motorA.SpeedProfile(50, 200, 1600, 200, true); //you could do something else here LcdConsole.WriteLine("Waiting for motor A to stop"); motorWaitHandle.WaitOne(); LcdConsole.WriteLine("Done moving motor"); LcdConsole.WriteLine("Position A: " + motorA.GetTachoCount()); //Individual position control of both motors Thread.Sleep(3000); motorA.ResetTacho(); motorD.ResetTacho(); LcdConsole.WriteLine("Moving motors A to 2000"); LcdConsole.WriteLine("Moving motor B to 1000"); WaitHandle[] handles = new WaitHandle[2]; handles[0] = motorA.SpeedProfile(50, 200, 1600, 200, true); handles[1] = motorD.SpeedProfile(50, 200, 600, 200, true); //you could do something else here LcdConsole.WriteLine("Waiting for both motors to stop"); WaitHandle.WaitAll(handles); LcdConsole.WriteLine("Done moving both motors"); LcdConsole.WriteLine("Position A: " + motorA.GetTachoCount()); LcdConsole.WriteLine("Position D: " + motorD.GetTachoCount()); motorA.Off(); motorD.Off(); //Motor synchronisation position control Thread.Sleep(3000); motorA.ResetTacho(); motorD.ResetTacho(); MotorSync sync = new MotorSync(MotorPort.OutA, MotorPort.OutD); LcdConsole.WriteLine("Sync motors to move 3000 steps forward"); motorWaitHandle = sync.StepSync(40, 0, 3000, true); //you could do something else here LcdConsole.WriteLine("Waiting for sync to stop"); motorWaitHandle.WaitOne(); LcdConsole.WriteLine("Done sync moving both motors"); LcdConsole.WriteLine("Position A: " + motorA.GetTachoCount()); LcdConsole.WriteLine("Position D: " + motorD.GetTachoCount()); sync.Off(); }