예제 #1
0
 public static void PrintData(WiiChuck wii)
 {
     Debug.Print(
         "joy:" + wii.RawAnalogX + "," + wii.RawAnalogY +
         " -> " + wii.AnalogX.ToString("n2") + "," + wii.AnalogY.ToString("n2") + " \t" +
         "acc:" + wii.RawAccelerationX + "," + wii.RawAccelerationY + "," + wii.RawAccelerationZ +
         " -> " + wii.AccelerationXGs + "," + wii.AccelerationYGs + "," + wii.AccelerationZGs + " \t" +
         "but:" + wii.ZButtonDown + "," + wii.CButtonDown);
 }
예제 #2
0
 public void Run()
 {
     while (Debugger.IsAttached)
     {
         // try to read the data from nunchucku
         if (wiiChuck.GetData())
         {
             WiiChuck.PrintData(wiiChuck);
         }
     }
 }
예제 #3
0
        public static void Main()
        {
            statusLed = new OutputPort(Pins.ONBOARD_LED, false);

            // setup output port
            serbSerial = new SerialPort(SerialPorts.COM1, 115200);
            serbSerial.Open();

            // initialize wii chuck
            wiiChuck = new WiiChuck(true);

            Debug.Print("SERB WiiRemote - Ready");

            while (true)
            {
                // try to read the data from nunchucku
                if (wiiChuck.GetData() == false)
                {
                    continue;
                }

#if DEBUG
                WiiChuck.PrintData(wiiChuck);
#endif

                // signal data read
                statusLed.Write(true);

                float posX, posY;
                if (wiiChuck.ZButtonDown)
                {
                    // if Z-button is pressed take vales form acclerometer
                    posX = InRange(wiiChuck.AccelerationXGs * 1.25f, -1.0f, 1.0f);
                    posY = InRange(wiiChuck.AccelerationYGs * 1.5f, -1.0f, 1.0f);
                }
                else
                {
                    // otherwise take values from analog joystick
                    posX = wiiChuck.AnalogX;
                    posY = wiiChuck.AnalogY;
                }

                // send values to robot
                MoveDifferential((int)(posY * 100f), (int)(posX * 100f));

                statusLed.Write(false);

                // wait a little
                Thread.Sleep(20);
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: coolkev/Netduino
        //public static void Main()
        //{
        //    using (var a1 = new AnalogInput(Cpu.AnalogChannel.ANALOG_1))
        //    {
        //        var last = 0.0d;
        //        while (Debugger.IsAttached)
        //        {
        //            var reading = a1.Read();
        //            if (reading != last)
        //            {
        //                Debug.Print(reading.ToString());
        //                last = reading;
        //            }
        //        }
        //    }
        //}
        public static void Main()
        {
            var wiiChuck = new WiiChuck(true);
            var debugMode = Debugger.IsAttached;

            _redLed = new OutputPort(Pins.GPIO_PIN_D13, false);
            _greenLed = new OutputPort(Pins.GPIO_PIN_A0, false);

            _pot = new AnalogInput(Cpu.AnalogChannel.ANALOG_1);

            //_speaker = new PWM(Pins.GPIO_PIN_D9);

            //_speakerThread = new Thread(PlaySound);
            //_speakerThread.Start();
            //_servo1 = new ServoController(Mshield.Servo1, 600, 2400, startDegree: 90);
            _robot = new TankRobot();

            while (!debugMode || Debugger.IsAttached)
            {
                // try to read the data from nunchucku
                if (wiiChuck.GetData())
                {

                    CheckButtons(wiiChuck.CButtonDown, wiiChuck.ZButtonDown);

                    if (Recording)
                    {
                        _iteration++;
                        SetMotorSpeed(_robot, wiiChuck);

                    }
                    else if (PlayingBack)
                    {

                        if (_currentPlaybackIndex >= _record.Count)
                        {
                            PlayingBack = false;
                            _currentPlaybackIndex = 0;

                        }
                        else
                        {
                            _iteration++;

                            var record = (DataPoint) _record[_currentPlaybackIndex];

                            if (record.Iterations == _iteration)
                            {
                                _currentPlaybackIndex++;
                                _robot.Move(record.LeftSpeed, record.RightSpeed);

                            }
                        }

                    }
                    else
                    {
                        SetMotorSpeed(_robot, wiiChuck);
                    }
                    //var degrees = ((int) (90+(-90*wiiChuck.AccelerationXGs))/2)*2;

                    //if (degrees < 0)
                    //    degrees = 0;
                    //else if (degrees > 180)
                    //    degrees = 180;

                    //_servo1.Rotate(degrees);
                    //Debug.Print("AccelX = " + wiiChuck.AccelerationXGs + "   AccelY=" + wiiChuck.AccelerationYGs);
                }
            }

            wiiChuck.Dispose();

            _robot.Dispose();

            //_speaker.Dispose();
            //_speaker = null;

            //_servo1.Dispose();

            _redLed.Dispose();
            _greenLed.Dispose();

            _pot.Dispose();
        }
예제 #5
0
파일: Program.cs 프로젝트: coolkev/Netduino
        private static void SetMotorSpeed(TankRobot robot, WiiChuck wiiChuck)
        {
            var y = (int)(wiiChuck.AnalogY * 100);

            if (System.Math.Abs(y) < 10)
                y = 0;

            var x = (int)(wiiChuck.AnalogX * 100);

            if (System.Math.Abs(x) < 10)
                x = 0;

            var leftSpeed = y;
            var rightSpeed = y;

            leftSpeed += (int)(x * (1 - (y / 200f)));
            rightSpeed -= (int)(x * (1 - (y / 200f)));

            if (leftSpeed > 100)
                leftSpeed = 100;

            if (rightSpeed > 100)
                rightSpeed = 100;
            if (x != lastX || y != lastY)
            //if (leftSpeed != _lastDataPoint.LeftSpeed || rightSpeed != _lastDataPoint.RightSpeed)
            {
                Debug.Print("X,Y = " + x + "," + y + " \t L,R = " + leftSpeed + "," + rightSpeed);
                lastX = x;
                lastY = y;

                robot.Move(leftSpeed, rightSpeed);

                if (Recording)
                    RecordData(leftSpeed, rightSpeed);

            }
        }
예제 #6
0
 public WiiChuckTest()
 {
     wiiChuck = new WiiChuck(true);
 }
예제 #7
0
 public static void PrintData(WiiChuck wii)
 {
     Debug.Print(
         "joy:" + wii.RawAnalogX + "," + wii.RawAnalogY +
         " -> " + wii.AnalogX.ToString("n2") + "," + wii.AnalogY.ToString("n2") + " \t" +
         "acc:" + wii.RawAccelerationX + "," + wii.RawAccelerationY + "," + wii.RawAccelerationZ +
         " -> " + wii.AccelerationXGs + "," + wii.AccelerationYGs + "," + wii.AccelerationZGs + " \t" +
         "but:" + wii.ZButtonDown + "," + wii.CButtonDown);
 }
예제 #8
0
 public WiiChuckTest()
 {
     wiiChuck = new WiiChuck(true);
 }