コード例 #1
0
        private void _gamepad_ValueComposed(object sender, Footbot e)
        {
            //Range_1
            //0...20
            //Range_2
            //0...50
            //Range_3
            //0...100

            if (Range1)
            {
                e.SpeedX = (e.SpeedX * 20) / 100;
                e.SpeedY = (e.SpeedY * 20) / 100;
                e.SpeedR = (e.SpeedR * 20) / 100;
            }

            if (Range2)
            {
                e.SpeedX = (e.SpeedX * 50) / 100;
                e.SpeedY = (e.SpeedY * 50) / 100;
                e.SpeedR = (e.SpeedR * 50) / 100;
            }
            SpeedXVal             = e.SpeedX;
            SpeedYVal             = e.SpeedY;
            SpeedRVal             = e.SpeedR;
            SpeedDribblerVal      = e.SpeedDribbler;
            DribblerEnableVal     = e.DribblerEnable;
            KickerVoltageLevelVal = e.KickerVoltageLevel;
            KickerChargeEnableVal = e.KickerChargeEnable;
            KickUpVal             = e.KickUp;
            KickForwardVal        = e.KickForward;
            var message = e.getBytes();

            Send(message);
        }
コード例 #2
0
    public static Footbot getStruct(byte[] data)
    {
        var calcCrc    = Crc32(data, Crc32Index);
        var messageCrc = GetIUint32(data, Crc32Index);

        if (calcCrc != messageCrc)
        {
            return(null);
        }
        var result = new Footbot
        {
            BarrierState       = data[BarrierStateIndex],
            Q0                 = GetIUint32(data, Q0Index),
            Q1                 = GetIUint32(data, Q1Index),
            Q2                 = GetIUint32(data, Q2Index),
            Q3                 = GetIUint32(data, Q3Index),
            KickerChargeStatus = data[KickerChargeStatusIndex],
            Voltage            = GetIUint32(data, VoltageIndex),
            Ip                 = GetIUint32(data, IpIndex),
            LeftX              = GetIUint32(data, LeftXIndex),
            LeftY              = GetIUint32(data, LeftYIndex),
            RightX             = GetIUint32(data, RightXIndex),
            RightY             = GetIUint32(data, RightYIndex),
        };

        return(result);
    }
コード例 #3
0
        private void RefreshState()
        {
            while (true)
            {
                _state = _joystick.GetCurrentState();

                if (_isimeToExit == true)
                {
                    _joystick.Unacquire();
                    _joystick.Dispose();
                    return;
                }

                var btns = _state.GetButtons();
                if (_isXBoxGamePad == false)
                {
                    _speedX = Convert(_state.RotationZ, true);
                    _speedY = Convert(_state.Z, false);
                }
                else
                {
                    _speedX = Convert(_state.RotationX);
                    _speedY = Convert(_state.RotationY, true);
                }
                _kickUp.SetState(btns[_kickUpIndex]);
                _kickForward.SetState(btns[_kickForwardIndex]);
                _kickerEnable.SetFixationState(btns[_kickerEnableIndex]);
                _dribbler.SetFixationState(btns[_dribblerIndex]);
                setPovButtons();
                _speedR = Convert(_state.X);

                var footBot = new Footbot()
                {
                    SpeedX             = _speedX,
                    SpeedY             = _speedY,
                    SpeedR             = -_speedR,
                    SpeedDribbler      = _speedDribbler,
                    DribblerEnable     = _dribbler.GetState(),
                    KickerVoltageLevel = _voltageLevel,
                    KickerChargeEnable = _kickerEnable.GetState(),
                    KickUp             = _kickUp.GetState(),
                    KickForward        = _kickForward.GetState()
                };
                ValueComposed?.Invoke(this, footBot);
                Thread.Sleep(100);
            }
        }
コード例 #4
0
 private void Receiver()
 {
     try
     {
         var localPort = int.Parse(LocalPort);
         _receivingUdpClient = new UdpClient(localPort);
         IPEndPoint remoteIpEndPoint = null;
         while (true)
         {
             if (_isTimeToExit)
             {
                 return;
             }
             byte[] receiveBytes = _receivingUdpClient?.Receive(ref remoteIpEndPoint);
             if (receiveBytes != null && ContainHead(receiveBytes, out int index))
             {
                 if (receiveBytes.Length >= Footbot.MaxIncomePacketLenght)
                 {
                     _receiveTimeout.Restart();
                     byte[] incomeData = new byte[Footbot.MaxIncomePacketLenght];
                     Array.Copy(receiveBytes, index, incomeData, 0, incomeData.Length);
                     var incomeValues = Footbot.getStruct(incomeData);
                     BarrierState       = incomeValues.BarrierState;
                     Q0                 = incomeValues.Q0;
                     Q1                 = incomeValues.Q1;
                     Q2                 = incomeValues.Q2;
                     Q3                 = incomeValues.Q3;
                     Ip                 = incomeValues.Ip;
                     Voltage            = incomeValues.Voltage;
                     LeftX              = incomeValues.LeftX;
                     LeftY              = incomeValues.LeftY;
                     RightX             = incomeValues.RightX;
                     RightY             = incomeValues.RightY;
                     KickerChargeStatus = incomeValues.KickerChargeStatus;
                 }
             }
             Thread.Sleep(10);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Возникло исключение: " + ex.ToString() + "\n  " + ex.Message);
     }
 }