private void InitializeDcMotor() { dcMotor = new DcMotor(pwmDriver); // Set default speed Speed = 1000; // DC motor test. Uncomment the following line to run DC1 motor for 5 seconds without using UI. // DcMotorTest(DcMotorIndex.DC1, MotorDirection.Backward, speed); }
private void InitializeDcMotor() { var pcaPwmControllerProvider = PcaPwmControllerProvider.GetDefault(); dcMotor = new DcMotor(pcaPwmControllerProvider); // 기본 속도 설정 Speed = 1000; // 다음 줄의 주석을 해제하면, UI를 사용하지 않고 DC1 모터를 5초 동안 실행한다. // DcMotorTest(DcMotorIndex.DC1, MotorDirection.Backward, speed); }
public void Init() { Servo = new ServoMotor(PwmDevice, PwmChannel.C1, 150, 600); DcMotor = new DcMotor(PwmDevice, PwmChannel.C4, PwmChannel.C5); Stepper = new StepperMotor( PwmDevice , PwmChannel.C11 , PwmChannel.C10 , PwmChannel.C9 , PwmChannel.C8); Stepper.RotationCompleted += OnStepperCompleted; Led0 = new Led(PwmDevice, PwmChannel.C0); }
public static void Main() { // shield-specific setup. Uncomment one of the shield #define lines above. #if UseOnboardLedForDiagnostics Led = new OutputPort(Pins.ONBOARD_LED, false); #endif HBridge bridge1; HBridge bridge2; #if AdafruitV1Shield var shield = new AdafruitV1MotorShield(); shield.InitializeShield(); bridge1 = shield.GetDcMotor(1); bridge2 = shield.GetDcMotor(2); #elif AdafruitV2Shield var shield = new AdafruitV2MotorShield(); shield.InitializeShield(); bridge1 = shield.GetDcMotor(1); bridge2 = shield.GetDcMotor(2); #elif SparkfunArduMotoShield var shield = new SparkfunArdumoto(); shield.InitializeShield(); bridge1 = shield.GetHBridge(Connector.A, TargetDevice.Netduino); bridge2 = shield.GetHBridge(Connector.B, TargetDevice.Netduino); #elif LedSimulatorShield bridge1 = LedMotorSimulator.GetDcMotor(Pins.GPIO_PIN_D0, PWMChannels.PWM_ONBOARD_LED); bridge2 = LedMotorSimulator.GetDcMotor(Pins.GPIO_PIN_D1, PWMChannels.PWM_PIN_D6); #else throw new ApplicationException("Uncomment one of the shield #define statements"); #endif // Create the stepper motor axes and link them to the Adafruit driver. var motor1 = new DcMotor(bridge1); var motor2 = new DcMotor(bridge2); while (true) { var targetSpeed1 = randomGenerator.NextDouble() / 2.0 + 0.5; // range -1.0 to +1.0 var targetSpeed2 = randomGenerator.NextDouble() * 2.0 - 1.0; // range -1.0 to +1.0 motor1.AccelerateToVelocity(targetSpeed1); motor2.AccelerateToVelocity(targetSpeed2); Thread.Sleep(6000); } }
public void Command(PwmCommand pwmCommand) { Log.DebugFormat("PwmCommand received({0})!", pwmCommand); switch (pwmCommand.Channel) { case DeviceChannel.DcMotor: var percent = pwmCommand.DutyCyclePercent; var direction = percent > 0 ? MotorDirection.Forward : MotorDirection.Reverse; DcMotor.Go(Math.Abs(percent), direction); break; case DeviceChannel.Led: Led0.On(pwmCommand.DutyCyclePercent); break; case DeviceChannel.Servo: Servo.MoveTo(pwmCommand.DutyCyclePercent); break; } }
public void AllStop() { Log.Info("All stop"); Led0.Off(); DcMotor.Stop(); }