Пример #1
0
        /// <summary>
        /// "4C 1D"などの外部からサーボの値を入れる
        /// ちなみに4C 1Dが7500です
        /// </summary>
        /// <param name="newValue">"4C 1D"</param>
        public void SetServoValueSafeClamp(string spaceSplitedByteString)
        {
            var aaa      = PreMaidUtility.ConvertEndian(PreMaidUtility.RemoveWhitespace(spaceSplitedByteString));
            int intValue = int.Parse(aaa, System.Globalization.NumberStyles.HexNumber);

            //Debug.Log($"{spaceSplitedByteString} は {intValue} ");

            SetServoValueSafeClamp(intValue);
        }
Пример #2
0
        /// <summary>
        /// 受信時の処理
        /// </summary>
        /// <param name="receivedString"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void OnReceivedFromPreMaidAi(string receivedString)
        {
            //4文字以下なら不正
            if (receivedString.Length < 4)
            {
                return;
            }
            //3-4文字目が命令種類
            string orderKind = receivedString.Substring(2, 2);

            //Debug.Log("orderKind:"+ orderKind);
            switch (orderKind)
            {
            //バッテリー残量
            case "01":
                if (receivedString.Length >= 10)
                {
                    int rawValtageValue =
                        PreMaidUtility.HexStringToInt(PreMaidUtility.ConvertEndian(receivedString.Substring(6, 4)));
                    Debug.Log($"バッテリー残量{rawValtageValue} で電圧は{rawValtageValue / 216f} V");

                    if (rawValtageValue / 216.0f < 9f)
                    {
                        Debug.LogError("バッテリー残量が9V以下です!!!!");
                    }
                }

                break;

            //モーション転送結果
            case "18":
                if (receivedString == "0418001C")
                {
                }
                else
                {
                    Debug.Log("PoseError:" + receivedString);
                }

                break;

            default:
                Debug.Log(receivedString);
                break;
            }
        }
Пример #3
0
        /// <summary>
        /// 7500だったら"4C 1D"が返ってくる
        /// </summary>
        /// <returns></returns>
        public string GetServoValueString()
        {
            var tmp = PreMaidUtility.ConvertEndian(_servoValue.ToString("X2"));

            return($"{tmp[0]}{tmp[1]} {tmp[2]}{tmp[3]}");
        }