Exemplo n.º 1
0
        internal static void TestADC()
        {
            BBBPinManager.AddMappingADC(BBBPin.P9_36);
            BBBPinManager.ApplyPinSettings(RoverMain.ApplyDevTree);
            IAnalogueIn Input = new AnalogueInBBB(BBBPin.P9_36);

            for (int i = 0; i < 200; i++)
            {
                Log.Output(Log.Severity.DEBUG, Log.Source.HARDWAREIO, "ADC Input: " + Input.GetInput() + " (Raw: " + Input.GetRawInput() + ")");
                Thread.Sleep(100);
            }
        }
Exemplo n.º 2
0
        public ArmMotorController()
        {
            Scarlet.Utilities.StateStore.Start("ARM");

            BBBPinManager.AddMappingPWM(ShoulderPin);
            BBBPinManager.AddMappingPWM(ElbowPin);
            BBBPinManager.AddMappingPWM(WristPin1);
            BBBPinManager.AddMappingPWM(WristPin2);
            BBBPinManager.AddMappingGPIO(WristDirectionPin1, true, ResistorState.PULL_UP);
            BBBPinManager.AddMappingGPIO(WristDirectionPin2, true, ResistorState.PULL_UP);

            BBBPinManager.AddMappingADC(ShoulderPotPin);
            BBBPinManager.AddMappingADC(ElbowPotPin);
            BBBPinManager.AddMappingADC(WristPotPin);
            BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_IF_NONE);
            BeagleBone.Initialize(SystemMode.DEFAULT, true);

            const double DegToRad = Math.PI / 180.0;

            a = new Arm((0, 0, Math.PI / 2, Math.PI / 2, 0, 0, 6.8),
                        (0, 0, -76 * DegToRad, 100 * DegToRad, 0, 0, 28.0),
                        (0, 0, -168.51 * DegToRad, -10 * DegToRad, 0, 0, 28.0),
                        (-2 * Math.PI, 2 * Math.PI, -Math.PI / 2, Math.PI / 2, 0, 0, 12.75));
            //(0, 12.75, -Math.PI / 2, Math.PI / 2));

            LowPass <float> ShoulderFilter = new LowPass <float>();
            LowPass <float> ElbowFilter    = new LowPass <float>();

            ShoulderPWM = PWMBBB.PWMDevice1.OutputB;
            ElbowPWM    = PWMBBB.PWMDevice1.OutputA;
            IPWMOutput WristPWM1 = PWMBBB.PWMDevice2.OutputB;
            IPWMOutput WristPWM2 = PWMBBB.PWMDevice2.OutputA;

            IDigitalOut WristDirectionGPIO1 = new DigitalOutBBB(WristDirectionPin1);
            IDigitalOut WristDirectionGPIO2 = new DigitalOutBBB(WristDirectionPin2);
            IAnalogueIn ShoulderADC         = new AnalogueInBBB(ShoulderPotPin);
            IAnalogueIn ElbowADC            = new AnalogueInBBB(ElbowPotPin);
            IAnalogueIn WristADC            = new AnalogueInBBB(WristPotPin);

            Shoulder = new TalonMC(ShoulderPWM, 0.2f, ShoulderFilter);
            Elbow    = new TalonMC(ElbowPWM, 0.2f, ElbowFilter);
            Wrist1   = new CytronMD30C(WristPWM1, WristDirectionGPIO1, 0.3f);
            Wrist2   = new CytronMD30C(WristPWM2, WristDirectionGPIO2, 0.3f);

            ShoulderPot = new Potentiometer(ShoulderADC, 300);
            ElbowPot    = new Potentiometer(ElbowADC, 300);
            WristPot    = new Potentiometer(WristADC, 300);
        }
Exemplo n.º 3
0
        public static void Start(string[] args)
        {
            if (args.Length < 3)
            {
                TestMain.ErrorExit("io bbb command requires functionality to test.");
            }
            BeagleBone.Initialize(SystemMode.DEFAULT, true);

            switch (args[2].ToLower())
            {
            case "digin":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb digin command requires pin to test.");
                }
                BBBPin InputPin = StringToPin(args[3]);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital input on BBB pin " + InputPin.ToString());
                BBBPinManager.AddMappingGPIO(InputPin, false, ResistorState.PULL_DOWN);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IDigitalIn Input = new DigitalInBBB(InputPin);
                while (true)
                {
                    Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Current pin state: " + (Input.GetInput() ? "HIGH" : "LOW"));
                    Thread.Sleep(250);
                }
            }

            case "digout":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb digout command requires pin to test.");
                }
                BBBPin OutputPin = StringToPin(args[3]);
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("io bbb digout command requires output mode (high/low/blink).");
                }
                if (args[4] != "high" && args[4] != "low" && args[4] != "blink")
                {
                    TestMain.ErrorExit("Invalid digout test mode supplied.");
                }
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital output on BBB pin " + OutputPin.ToString());
                BBBPinManager.AddMappingGPIO(OutputPin, true, ResistorState.PULL_DOWN);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IDigitalOut Output = new DigitalOutBBB(OutputPin);
                if (args[4] == "high")
                {
                    Output.SetOutput(true);
                }
                else if (args[4] == "low")
                {
                    Output.SetOutput(false);
                }
                else
                {
                    bool Out = false;
                    while (true)
                    {
                        Output.SetOutput(Out);
                        Out = !Out;
                        Thread.Sleep(250);
                    }
                }
                break;
            }

            case "pwm":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb pwm command requires pin to test.");
                }
                BBBPin OutputPin = StringToPin(args[3]);
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("io bbb pwm command requires frequency.");
                }
                int Frequency = int.Parse(args[4]);
                if (args.Length < 6)
                {
                    TestMain.ErrorExit("io bbb pwm command requires output mode.");
                }
                if (args[5] != "per" && args[5] != "sine")
                {
                    TestMain.ErrorExit("io bbb pwm command invalid (per/sine).");
                }
                if (args[5] == "per" && args.Length < 7)
                {
                    TestMain.ErrorExit("io bbb pwm per must be provided duty cycle.");
                }
                BBBPinManager.AddMappingPWM(OutputPin);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IPWMOutput Output = PWMBBB.GetFromPin(OutputPin);
                Output.SetFrequency(Frequency);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing PWM output on BBB pin " + OutputPin.ToString() + " at " + Frequency + "Hz.");
                if (args[5] == "per")
                {
                    Output.SetOutput(int.Parse(args[6]) / 100F);
                    Output.SetEnabled(true);
                    Thread.Sleep(15000);     // Not sure if it stops outputting when the program exits.
                }
                else
                {
                    int Cycle = 0;
                    while (true)
                    {
                        float Val = (float)((Math.Sin(Cycle * Math.PI / 180.000D) + 1) / 2);
                        Output.SetOutput(Val);
                        Thread.Sleep(50);
                        Cycle += 20;
                    }
                }
                break;
            }

            case "adc":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb adc command requires pin to test.");
                }
                BBBPin InputPin = StringToPin(args[3]);
                BBBPinManager.AddMappingADC(InputPin);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IAnalogueIn Input = new AnalogueInBBB(InputPin);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing analogue input on BBB pin " + InputPin.ToString());
                while (true)
                {
                    Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "ADC Input: " + Input.GetInput() + " (Raw: " + Input.GetRawInput() + ")");
                    Thread.Sleep(250);
                }
            }

            case "int":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb int command requires pin to test.");
                }
                BBBPin InputPin = StringToPin(args[3]);
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("io bbb int command requires interrupt mode (rise/fall/both).");
                }
                if (args[4] != "rise" && args[4] != "fall" && args[4] != "both")
                {
                    TestMain.ErrorExit("Invalid interrupt mode supplied.");
                }

                BBBPinManager.AddMappingGPIO(InputPin, true, ResistorState.PULL_DOWN);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IDigitalIn Input = new DigitalInBBB(InputPin);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing interrupts on BBB pin " + InputPin.ToString());
                switch (args[4])
                {
                case "rise": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.RISING_EDGE); break;

                case "fall": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.FALLING_EDGE); break;

                case "both": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.ANY_EDGE); break;
                }
                while (true)
                {
                    Thread.Sleep(50);
                }                                     // Program needs to be running to receive.
            }

            case "mtk3339":
            {
                BBBPinManager.AddMappingUART(BBBPin.P9_24);
                BBBPinManager.AddMappingUART(BBBPin.P9_26);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IUARTBus UART = UARTBBB.UARTBus1;
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Press any key to stop.");
                while (Console.KeyAvailable)
                {
                    Console.ReadKey();
                }
                byte[] Buffer = new byte[32];
                while (true)
                {
                    Thread.Sleep(10);
                    if (UART.BytesAvailable() > 0)
                    {
                        int Count = UART.Read(32, Buffer);
                        Console.Write(System.Text.Encoding.ASCII.GetString(UtilMain.SubArray(Buffer, 0, Count)));
                    }
                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                }
                break;
            }
            }
        }