Beispiel #1
0
        public static void Main()
        {
            // This pin-layout counts for the Sparkfun Ardubot Kit:
            HBridge MotorDriver = new HBridge(new Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D3, new Netduino.PWM(Pins.GPIO_PIN_D9), Pins.GPIO_PIN_D6);

            // Motor 1 half speed backward
            MotorDriver.SetState(HBridge.Motors.Motor1, -50);
            // Motor 2 half speed forward
            MotorDriver.SetState(HBridge.Motors.Motor2, 50);

            // Lets run for 5 seconds
            Thread.Sleep(5000);

            // Motor 1 full speed backward
            MotorDriver.SetState(HBridge.Motors.Motor1, -100);
            // Motor 2 full speed forward
            MotorDriver.SetState(HBridge.Motors.Motor2, 100);

            // Lets run for 5 seconds
            Thread.Sleep(5000);

            // Stops both motors
            MotorDriver.SetState(HBridge.Motors.Motor1, 0);
            MotorDriver.SetState(HBridge.Motors.Motor2, 0);
        }
Beispiel #2
0
        public static void Main()
        {
            // This pin-layout counts for the following DFRobot Motorshields:
            // - Arduino Motor Shield (L298N)
            // - Arduino Motor Shield (L293)
            HBridge MotorDriver = new HBridge(new Netduino.PWM(Pins.GPIO_PIN_D6), Pins.GPIO_PIN_D7, new Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D4);
            // Older versions of the L293 use pin 8 instead of 4. If that's the case, use the line below
            // HBridge MotorDriver = new HBridge(new Netduino.PWM(Pins.GPIO_PIN_D6), Pins.GPIO_PIN_D7, new Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D8);

            // Motor 1 half speed backward
            MotorDriver.SetState(HBridge.Motors.Motor1, -50);
            // Motor 2 half speed forward
            MotorDriver.SetState(HBridge.Motors.Motor2, 50);

            // Lets run for 5 seconds
            Thread.Sleep(5000);

            // Motor 1 full speed backward
            MotorDriver.SetState(HBridge.Motors.Motor1, -100);
            // Motor 2 full speed forward
            MotorDriver.SetState(HBridge.Motors.Motor2, 100);

            // Lets run for 5 seconds
            Thread.Sleep(5000);

            // Stops both motors
            MotorDriver.SetState(HBridge.Motors.Motor1, 0);
            MotorDriver.SetState(HBridge.Motors.Motor2, 0);
        }
Beispiel #3
0
        public static void Main()
        {
            // Defines the H-Bridge IC on the correct pins
            HBridge MotorDriver = new HBridge(new Netduino.PWM(Pins.GPIO_PIN_D6), Pins.GPIO_PIN_D7, new Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D4);

            // Motor 1 half speed backward
            MotorDriver.SetState(HBridge.Motors.Motor1, -50);
            // Motor 2 half speed forward
            MotorDriver.SetState(HBridge.Motors.Motor2, 50);

            // Lets run for 5 seconds
            Thread.Sleep(5000);

            // Motor 1 full speed backward
            MotorDriver.SetState(HBridge.Motors.Motor1, -100);
            // Motor 2 full speed forward
            MotorDriver.SetState(HBridge.Motors.Motor2, 100);

            // Lets run for 5 seconds
            Thread.Sleep(5000);

            // Stops both motors
            MotorDriver.SetState(HBridge.Motors.Motor1, 0);
            MotorDriver.SetState(HBridge.Motors.Motor2, 0);
        }
        public static void Main()
        {
            //distance sensor
            //triger (12), echo (13), 5V + G
            HC_SR04 sensor = new HC_SR04(Pins.GPIO_PIN_D12, Pins.GPIO_PIN_D13);
            //buzzer
            OutputPort Klakson = new OutputPort(Pins.GPIO_PIN_D0, false);
            //motor driver
            HBridge MotorDriver = new HBridge(SecretLabs.NETMF.Hardware.Netduino.PWMChannels.PWM_PIN_D5, Pins.GPIO_PIN_D4, SecretLabs.NETMF.Hardware.Netduino.PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D7);
            //led indicator if there is an object in the front of robot
            OutputPort WarningLed = new OutputPort(Pins.GPIO_PIN_D1, false);
            OutputPort GoLed = new OutputPort(Pins.GPIO_PIN_D2, false);
   
            //waiting till connect...
            if (!Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IsDhcpEnabled)
            {
                // using static IP
                while (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) ; // wait for network connectivity
            }
            else
            {
                // using DHCP
                while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any) ; // wait for DHCP-allocated IP address
            }
            //Debug print our IP address
            Debug.Print("Device IP: " + Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);

            // create mqtt client instance 
            client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS));
            string clientId = Guid.NewGuid().ToString();
            client.Connect(clientId);
            SubscribeMessage();
            PublishMessage("/robot/state", "ONLINE");
            while (true)
            {
                long ticks = sensor.Ping();
                if (ticks > 0L)
                {
                    double inches = sensor.TicksToInches(ticks);
                    Debug.Print("jarak ke object :" + inches);

                    if (inches < 4)
                    {
                        jalan = Arah.Berhenti;
                        Klakson.Write(true);
                        WarningLed.Write(true);
                        GoLed.Write(false);
                        PublishMessage("/robot/status", "Watchout there is an object in the front of robot!");
                    }
                    else
                    {
                        Klakson.Write(false);
                        WarningLed.Write(false);
                        GoLed.Write(true);
                    }
                }
                //stop first before change direction or turn
                if (lastDirection != jalan)
                {
                    //stop before start new direction
                    MotorDriver.SetState(HBridge.Motors.Motor1, 0);
                    MotorDriver.SetState(HBridge.Motors.Motor2, 0);
                }
              
                switch (jalan)
                {
                    case Arah.Maju:
                        MotorDriver.SetState(HBridge.Motors.Motor1, Speed);
                        MotorDriver.SetState(HBridge.Motors.Motor2, Speed);
                        break;
                    case Arah.Mundur:
                        MotorDriver.SetState(HBridge.Motors.Motor1,(sbyte)(-Speed));
                        MotorDriver.SetState(HBridge.Motors.Motor2, (sbyte)(-Speed));
                        break;
                    case Arah.Kiri:
                        MotorDriver.SetState(HBridge.Motors.Motor1, -50);
                        MotorDriver.SetState(HBridge.Motors.Motor2, 50);
                        break;
                    case Arah.Kanan:
                        MotorDriver.SetState(HBridge.Motors.Motor1, 50);
                        MotorDriver.SetState(HBridge.Motors.Motor2, -50);
                        break;
                    case Arah.Berhenti:
                        MotorDriver.SetState(HBridge.Motors.Motor1, 0);
                        MotorDriver.SetState(HBridge.Motors.Motor2, 0);
                        break;
                }
                lastDirection = jalan;
            }

        }