/**
         * Caller must ensure timeoutMs is nonzero.
         * @param timeoutMs How long to wait for response.
         * @param handle Handle to CAN Rx Stream.
         * @param paramEnum Parameter to look for.
         * @param valueReceived [out] Value received in response frame, or zero if not received.
         * @return nonzero for error code, zero for OK.
         */
        private ErrorCode WaitForParamResponse(int timeoutMs, uint handle, ParamEnum paramEnum, out int valueReceived)
        {
            ErrorCode status = 0;

            /* init the outputs to default values */
            valueReceived = 0;

            /* loop until timeout or receive if caller wants to check */
            while (timeoutMs > 0)
            {
                /* wait a bit */
                System.Threading.Thread.Sleep(1);

                /* process received param events. Caller should have opened
                 *  the stream already. */
                ProcessStreamMessages(handle);
                /* see if response was received */
                if (0 == PollForParamResponse(paramEnum, out valueReceived))
                {
                    break; /* leave inner loop */
                }
                /* decrement */
                --timeoutMs;
            }
            /* if we get here then we timed out */
            if (timeoutMs == 0)
            {
                status = ErrorCode.SIG_NOT_UPDATED;
            }

            return(status);
        }
        /** private wrapper to avoid specifying ordinal and subvalue */
        ErrorCode ConfigSetWrapper(ParamEnum paramEnum, float value, int timeoutMs)
        {
            byte subValue = 0;
            int  ordinal  = 0;

            return(base.ConfigSetParameter(paramEnum, value, subValue, ordinal, timeoutMs));
        }
Exemple #3
0
        /**
         * Gets a parameter. Generally this is not used.
         * This can be utilized in
         * - Using new features without updating API installation.
         * - Errata workarounds to circumvent API implementation.
         * - Allows for rapid testing / unit testing of firmware.
         *
         * @param param
         *            Parameter enumeration.
         * @param ordinal
         *            Ordinal of parameter.
         * @param timeoutMs
         *            Timeout value in ms. If nonzero, function will wait for
         *            config success and report an error if it times out.
         *            If zero, no blocking or checking is performed.
         * @return Value of parameter.
         */
        public double ConfigGetParameter(ParamEnum param, int ordinal, int timeoutMs)
        {
            int retval;

            _ll.ConfigGetParameter(param, out retval, ordinal, timeoutMs);
            return(retval);
        }
Exemple #4
0
        /**
         * Sets a parameter. Generally this is not used.
         * This can be utilized in
         * - Using new features without updating API installation.
         * - Errata workarounds to circumvent API implementation.
         * - Allows for rapid testing / unit testing of firmware.
         *
         * @param param
         *            Parameter enumeration.
         * @param value
         *            Value of parameter.
         * @param subValue
         *            Subvalue for parameter. Maximum value of 255.
         * @param ordinal
         *            Ordinal of parameter.
         * @param timeoutMs
         *            Timeout value in ms. If nonzero, function will wait for
         *            config success and report an error if it times out.
         *            If zero, no blocking or checking is performed.
         * @return Error Code generated by function. 0 indicates no error.
         */
        public ErrorCode ConfigSetParameter(ParamEnum param, float value, int subValue, int ordinal, int timeoutMs)
        {
            ErrorCode retval = _ll.ConfigSetParameter(param, value, (byte)subValue, ordinal,
                                                      timeoutMs);

            return(retval);
        }
Exemple #5
0
        public ErrorCode ConfigGetParameter(ParamEnum paramEnum, out float value, int ordinal = 0, int timeoutMs = Constants.GetParamTimeoutMs)
        {
            int       valueInt;
            ErrorCode retval = ConfigGetParameter(paramEnum, 0, out valueInt, 0x00, ordinal, timeoutMs);

            /* scaling */
            switch (paramEnum)
            {
            case ParamEnum.eProfileParamSlot_P:     /* 10.22 fixed pt value */
            case ParamEnum.eProfileParamSlot_I:
            case ParamEnum.eProfileParamSlot_D:
            case ParamEnum.eProfileParamSlot_F:
                value = ((float)valueInt) * FXP_TO_FLOAT_10_22;
                break;

            case ParamEnum.eNominalBatteryVoltage:
                value = ((float)valueInt) * FXP_TO_FLOAT_0_8;
                break;

            case ParamEnum.eProfileParamSlot_PeakOutput:
                value = ((float)valueInt) * 1.0f / 1023.0f;
                break;

            case ParamEnum.eSelectedSensorCoefficient:
                value = ((float)valueInt) * 1.0f / 65536.0f;
                break;

            default:     /* everything else is integral */
                value = (float)valueInt;
                break;
            }
            return(retval);
        }
 public Int32 GetParamResponseInt32(ParamEnum paramEnum, out int value)
 {
     float dvalue = 0;
     int retval = GetParamResponse(paramEnum, out dvalue);
     value = (Int32)dvalue;
     return retval;
 }
        //----------------------------------------------------------------------------------------//
        /** private wrapper to avoid specifying ordinal */
        ErrorCode ConfigSetWrapper(ParamEnum paramEnum, TareType tareType, float angleDeg, int timeoutMs)
        {
            byte subValue = (byte)tareType;
            int  ordinal  = 0;

            return(base.ConfigSetParameter(paramEnum, angleDeg, subValue, ordinal, timeoutMs));
        }
Exemple #8
0
                /**
                 * Gets a parameter. Generally this is not used.
                 * This can be utilized in
                 * - Using new features without updating API installation.
                 * - Errata workarounds to circumvent API implementation.
                 * - Allows for rapid testing / unit testing of firmware.
                 *
                 * @param param
                 *            Parameter enumeration.
                 * @param ordinal
                 *            Ordinal of parameter.
                 * @param timeoutMs
                 *            Timeout value in ms. If nonzero, function will wait for
                 *            config success and report an error if it times out.
                 *            If zero, no blocking or checking is performed.
                 * @return Value of parameter.
                 */
                public float ConfigGetParameter(ParamEnum param, int ordinal, int timeoutMs = 0)
                {
                    float retval;

                    _ll.ConfigGetParameter(param, out retval, ordinal, timeoutMs);
                    return(retval);
                }
Exemple #9
0
        /// <summary>
        /// PLC读取
        /// </summary>
        public string OpcSyncRead(ParamEnum p)
        {
            Type type = this.GetType();                                                   //获取类型

            System.Reflection.PropertyInfo propertyInfo = type.GetProperty(p.ToString()); //获取指定名称的属性
            return(propertyInfo.GetValue(this, null).ToString());                         //获取属性值
        }
        //------------------------------------- ConfigSet* interface -----------------------------------------//

        /**
         * Send a one shot frame to set an arbitrary signal.
         * Most signals are in the control frame so avoid using this API unless you have
         * to.
         * Use this api for...
         * -A motor controller profile signal eProfileParam_XXXs.  These are backed up
         * in flash.  If you are gain-scheduling then call this periodically.
         * -Default brake and limit switch signals... eOnBoot_XXXs.  Avoid doing this,
         * use the override signals in the control frame.
         * Talon will automatically send a PARAM_RESPONSE after the set, so
         * GetParamResponse will catch the latest value after a couple ms.
         */
        private ErrorCode ConfigSetParameterRaw(ParamEnum paramEnum, int value, byte subValue, int ordinal = 0, int timeoutMs = 0)
        {
            ErrorCode statusTx = ErrorCode.OK; //!< Status code for transmit set request
            ErrorCode statusRx = ErrorCode.OK; //!< Status code for receive (if timeoutMs is nonzero)
            uint      handle   = 0;            //!< Handle to CAN stream (if timeoutMs is nonzero)

            /* sterilize inputs */
            if ((int)paramEnum > 0xFFF)
            {
                return(ErrorCode.CAN_INVALID_PARAM);
            }
            if (ordinal > 0xF)
            {
                return(ErrorCode.CAN_INVALID_PARAM);
            }


            /* If we need to monitor for response, create rx stream */
            /* wait for response frame */
            if (timeoutMs > 0)
            {
                /* create a session to get filter rx frames. */
                statusRx = OpenSession(ref handle);
                /* remove stale entry if caller wants to wait for response. */
                _sigs_Value.Remove((uint)paramEnum);
                _sigs_SubValue.Remove((uint)paramEnum);
            }

            /* attempt to send request.  Save status code */
            statusTx = RequestOrSetParam(true, paramEnum, value, subValue, ordinal, 5); /* max tries is 5 */

            /* If caller wants to block,  wait for response frame and save status code */
            if (timeoutMs > 0)
            {
                /* caller wants to get response, check our stream health */
                if (statusRx != 0)
                {
                    /* stream could not be allocated, this error code will likely
                     * be passed to caller below (assuming tx was succesful) */
                }
                else
                {
                    /* stream open did not report an error, continue to poll for response */
                    int valueReceived;
                    statusRx = WaitForParamResponse(timeoutMs, handle, paramEnum, out valueReceived);
                }
            }
            /* Close stream */
            if (handle != 0)
            {
                CTRE.Native.CAN.CloseStream(handle);
            }
            /* return the transmit code first, if this fails then nothing else matters  */
            if (statusTx != 0)
            {
                return((ErrorCode)statusTx);
            }
            return((ErrorCode)statusRx);
        }
 /**
  * Asks TALON to immedietely respond with signal value.  This API is only used
  * for signals that are not sent periodically.
  * This can be useful for reading params that rarely change like Limit Switch
  * settings and PIDF values.
   * @param param to request.
  */
 public int RequestParam(ParamEnum paramEnum)
 {
     /* process received param events. We don't expect many since this API is not
      * used often. */
     ProcessStreamMessages();
     int status = CTRE.Native.CAN.Send(PARAM_REQUEST | GetDeviceNumber(), (uint)paramEnum, 1, 0);
     return status;
 }
        public ErrorCode ConfigGetParameter(ParamEnum paramEnum, out float value, int ordinal = 0, int timeoutMs = Constants.GetParamTimeoutMs)
        {
            int       valueInt;
            ErrorCode retval = ConfigGetParameter(paramEnum, 0, out valueInt, 0x00, ordinal, timeoutMs);

            // todo scaling?
            value = (float)valueInt;
            return(retval);
        }
Exemple #13
0
    protected override void _Init()
    {
        this.input             = new ParamConnection("Input", null);
        this.input.description = "The audio signal to process.";
        this.genParams.Add(this.input);

        this.outputType             = new ParamEnum("Mode", "range", outputEnum, enumFull);
        this.outputType.description = "The range of the output.";
        this.genParams.Add(this.outputType);
    }
Exemple #14
0
    protected override void _Init()
    {
        this.input             = new ParamConnection("Input", null);
        this.input.description = "The audio signal that will be clamped.";
        this.genParams.Add(this.input);

        this.clampType             = new ParamEnum("Mode", "direction", clampEnum, enumFull);
        this.clampType.description = "How the audio signal will get clamped.";
        this.genParams.Add(this.clampType);
    }
 public int SetParam(ParamEnum paramEnum, float value, uint timeoutMs = 0)
 {
     Int32 rawbits = 0;
     switch (paramEnum)
     {
         default: /* everything else is integral */
             rawbits = (Int32)value;
             break;
     }
     return SetParamRaw(paramEnum, rawbits, timeoutMs);
 }
        private int ConfigSetParameter(ParamEnum paramEnum, TareType tareType, float angleDeg, uint timeoutMs = 0)
        {
            const float deg_per_canunit = 0.015625f;
            Int32       deg_3B          = ((Int32)(angleDeg / deg_per_canunit));
            long        paramValue;

            paramValue   = (long)deg_3B & 0xFFFFFF;
            paramValue <<= 8;
            paramValue  |= (byte)tareType;
            return(ConfigSetParameter(paramEnum, (float)paramValue));
        }
 public int GetParamResponse(ParamEnum paramEnum, out float value)
 {
     Int32 rawbits = 0;
     int retval = GetParamResponseRaw(paramEnum, out rawbits);
     switch (paramEnum)
     {
         default: /* everything else is integral */
             value = (float)rawbits;
             break;
     }
     return retval;
 }
Exemple #18
0
        //------------------------------------- ConfigGet* interface -----------------------------------------//

        /**
         * Blocking read of a given parameter.  Virtual declared so that child classes can override with float return.
         * Child classes will understand how to decode raw integral type into human readable floating point values.
         * @param paramEnum Enumerated parameter to read.
         * @param paramEnum Enumerated parameter to read.
         *
         */
        /** private get config with all params, status frame requires this */
        private ErrorCode ConfigGetParameter(ParamEnum paramEnum, int valueToSend, out int valueReceived, byte subValue, int ordinal, int timeoutMs)
        {
            ErrorCode err1;
            ErrorCode err2 = ErrorCode.OK;

            if (timeoutMs != 0)
            {
                /* remove stale entry if caller wants to wait for response. */
                _sigs_Value.Remove((uint)paramEnum);
                _sigs_SubValue.Remove((uint)paramEnum);
            }

            /* send request */
            err1 = RequestParam(paramEnum, valueToSend, subValue, ordinal);

            /* initialize outputs */
            valueReceived = 0;

            /* wait for response frame */
            if (timeoutMs > 0)
            {
                /* loop until timeout or receive if caller wants to check */
                while (timeoutMs > 0)
                {
                    /* wait a bit */
                    System.Threading.Thread.Sleep(1);
                    /* see if response was received */
                    if (0 == PollForParamResponse(paramEnum, out valueReceived))
                    {
                        break; /* leave inner loop */
                    }
                    /* decrement */
                    --timeoutMs;
                }
                /* if we get here then we timed out */
                if (timeoutMs == 0)
                {
                    err2 = ErrorCode.SIG_NOT_UPDATED;
                }
            }

            /* return the first one */
            if (err1 == ErrorCode.OK)
            {
                return(err2);
            }
            else
            {
                return(err1);
            }
        }
        //------------------------------------- framing functions -----------------------------------------//

        /**
         * Asks TALON to immedietely respond with signal value.  This API is only used
         * for signals that are not sent periodically.
         * This can be useful for reading params that rarely change like Limit Switch
         * settings and PIDF values.
         * @param paramEnum parameter to request.
         * @param value
         * @param subValue
         * @param ordinal
         */
        private ErrorCode RequestOrSetParam(bool bIsSet, ParamEnum paramEnum, int value, byte subValue, int ordinal, int retryMax)
        {
            if (ordinal < 0x0)
            {
                return(ErrorCode.CAN_INVALID_PARAM);
            }
            if (ordinal > 0xF)
            {
                return(ErrorCode.CAN_INVALID_PARAM);
            }

            byte paramEnum_h8 = (byte)((int)paramEnum >> 4);
            byte paramEnum_l4 = (byte)((int)paramEnum & 0xF);

            ulong frame = 0;

            frame   = subValue;
            frame <<= 8;
            frame  |= 0x00;
            frame <<= 8;
            frame  |= (byte)(value >> 0x00);
            frame <<= 8;
            frame  |= (byte)(value >> 0x08);
            frame <<= 8;
            frame  |= (byte)(value >> 0x10);
            frame <<= 8;
            frame  |= (byte)(value >> 0x18);
            frame <<= 8;
            frame  |= (byte)(ordinal | (paramEnum_l4 << 4));
            frame <<= 8;
            frame  |= (byte)(paramEnum_h8);

            uint baseId = bIsSet ? PARAM_SET : PARAM_REQUEST;

            ErrorCode status = ErrorCode.OK;

            do
            {
                status = (ErrorCode)CTRE.Native.CAN.Send(baseId | GetDeviceNumber(), frame, 8, 0);
                /* If transmit successful, exit while loop */
                if (status == 0)
                {
                    break;
                }

                --retryMax;
            } while (retryMax >= 0);

            return(status);
        }
    public JawsParam()
    {
        Name   = "Jaws";
        Color1 = RndColor();
        Color2 = RndColor();

        paramsList = new List <AParamValue>();
        Teeth      = new ParamEnum()
        {
            FullName  = "Teeth",
            ShortName = "Tth",
            values    = new List <string>
            {
                "grass",
                "all",
                "meat"
            }
        };
        paramsList.Add(Teeth);
        SkinTextureOctave = new ParamValue()
        {
            FullName  = "SkinTextureOctave",
            ShortName = "SkOc",
            Min       = 1f,
            Max       = 3f,
            Step      = 1f,
            Level     = 1,
        };
        paramsList.Add(SkinTextureOctave);
        SkinTextureFreq = new ParamValue()
        {
            FullName  = "SkinTextureFreq",
            ShortName = "SkFr",
            Min       = 0.05f,
            Max       = 0.5f,
            Level     = 6,
            Step      = 1f,
        };
        paramsList.Add(SkinTextureFreq);
        JawsLevel = new ParamValue()
        {
            FullName  = "Jaws Level",
            ShortName = "JwLv",
            Min       = 1f,
            Max       = 2f,
            Step      = 0.5f,
            Level     = 1,
        };
        paramsList.Add(JawsLevel);
    }
Exemple #21
0
    public override PxPre.Phonics.GenBase SpawnGenerator(
        float freq,
        float beatsPerSec,
        int samplesPerSec,
        float amp,
        WiringDocument spawnFrom,
        WiringCollection collection)
    {
        if (this.input.IsConnected() == false)
        {
            return(ZeroGen());
        }

        PxPre.Phonics.GenBase gb =
            this.input.Reference.SpawnGenerator(
                freq,
                beatsPerSec,
                samplesPerSec,
                amp,
                spawnFrom,
                collection);

        float offset = this.offset.GetWavelength(freq, beatsPerSec);
        float record = this.recordAmt.GetWavelength(freq, beatsPerSec);

        PxPre.Phonics.GenCycle.OffsetPass offsetType = PxPre.Phonics.GenCycle.OffsetPass.Pass;
        switch (this.offsetType.value)
        {
        default:
        case (int)PxPre.Phonics.GenCycle.OffsetPass.Pass:
            offsetType = PxPre.Phonics.GenCycle.OffsetPass.Pass;
            break;

        case (int)PxPre.Phonics.GenCycle.OffsetPass.Silent:
            offsetType = PxPre.Phonics.GenCycle.OffsetPass.Silent;
            break;

        case (int)PxPre.Phonics.GenCycle.OffsetPass.Hold:
            offsetType = PxPre.Phonics.GenCycle.OffsetPass.Hold;
            break;
        }

        return
            (new PxPre.Phonics.GenCycle(
                 (int)(offset * samplesPerSec),
                 (int)(record * samplesPerSec),
                 offsetType,
                 gb));
    }
        /*---------------------setters and getters that use the param
         * request/response-------------*/
        /**
         * Send a one shot frame to set an arbitrary signal.
         * Most signals are in the control frame so avoid using this API unless you have
         * to.
         * Use this api for...
         * -A motor controller profile signal eProfileParam_XXXs.  These are backed up
         * in flash.  If you are gain-scheduling then call this periodically.
         * -Default brake and limit switch signals... eOnBoot_XXXs.  Avoid doing this,
         * use the override signals in the control frame.
         * Talon will automatically send a PARAM_RESPONSE after the set, so
         * GetParamResponse will catch the latest value after a couple ms.
         */
        public int SetParamRaw(ParamEnum paramEnum, int rawBits, uint timeoutMs = 0)
        {
            /* caller is using param API.  Open session if it hasn'T been done. */
            if (0 == _can_h)
            {
                OpenSessionIfNeedBe();
            }
            /* wait for response frame */
            if (timeoutMs != 0)
            {
                /* remove stale entry if caller wants to wait for response. */
                _sigs.Remove((uint)paramEnum);
            }
            /* frame set request and send it */
            UInt64 frame = ((UInt64)rawBits) & 0xFFFFFFFF;

            frame <<= 8;
            frame  |= (byte)paramEnum;
            uint arbId  = PARAM_SET | GetDeviceNumber();
            int  status = CTRE.Native.CAN.Send(arbId, frame, 5, 0);

            /* wait for response frame */
            if (timeoutMs > 0)
            {
                int readBits;
                /* loop until timeout or receive if caller wants to check */
                while (timeoutMs > 0)
                {
                    /* wait a bit */
                    System.Threading.Thread.Sleep(1);
                    /* see if response was received */
                    if (0 == GetParamResponseRaw(paramEnum, out readBits))
                    {
                        break; /* leave inner loop */
                    }
                    /* decrement */
                    --timeoutMs;
                }
                /* if we get here then we timed out */
                if (timeoutMs == 0)
                {
                    status = (int)Codes.CTR_SigNotUpdated;
                }
            }
            return(status);
        }
        /**
         * Checks cached CAN frames and updating solicited signals.
         */
        int PollForParamResponse(ParamEnum paramEnum, out Int32 rawBits)
        {
            int retval = 0;

            /* grab the solicited signal value */
            if (_sigs_Value.Contains((uint)paramEnum) == false)
            {
                retval  = (int)ErrorCode.SIG_NOT_UPDATED;
                rawBits = 0; /* default value if signal was not received */
            }
            else
            {
                Object value = _sigs_Value[(uint)paramEnum];
                uint   temp  = (uint)value;
                rawBits = Sterilize(temp);
            }
            return(retval);
        }
Exemple #24
0
    protected override void _Init()
    {
        this.input             = new ParamConnection("Input", null);
        this.input.description = "The audio signal to record and playback.";
        this.genParams.Add(this.input);

        this.offset             = new ParamTimeLen("Offset", 0.0f, ParamTimeLen.TimeLenType.Seconds, ParamTimeLen.WidgetTime);
        this.offset.description = "The amount of time to pass before recording. What kind of behaviour to perform during this time is controlled by the Offset Ty parameter.";
        this.genParams.Add(this.offset);

        this.offsetType             = new ParamEnum("Offset Ty", "Offset Type", offsetEnum, 0);
        this.offsetType.description = "How to process the audio signal while offsetting.";
        this.genParams.Add(this.offsetType);

        this.recordAmt             = new ParamTimeLen("Amount", 1.0f, ParamTimeLen.TimeLenType.Seconds, ParamTimeLen.WidgetTime);
        this.recordAmt.description = "The amount of time to record.";
        this.genParams.Add(this.recordAmt);
    }
 /**
  * Checks cached CAN frames and updating solicited signals.
  */
 public int GetParamResponseRaw(ParamEnum paramEnum, out Int32 rawBits)
 {
     int retval = 0;
     /* process received param events. We don't expect many since this API is not
      * used often. */
     ProcessStreamMessages();
     /* grab the solicited signal value */
     if (_sigs.Contains((uint)paramEnum) == false)
     {
         retval = (int)Codes.CTR_SigNotUpdated;
         rawBits = 0; /* default value if signal was not received */
     }
     else
     {
         Object value = _sigs[(uint)paramEnum];
         uint temp = (uint)value;
         rawBits = (int)temp;
     }
     return retval;
 }
Exemple #26
0
        /**
         * Checks cached CAN frames and updating solicited signals.
         */
        int PollForParamResponse(ParamEnum paramEnum, out Int32 rawBits)
        {
            int retval = 0;

            /* process received param events. We don't expect many since this API is not
             * used often. */
            ProcessStreamMessages();
            /* grab the solicited signal value */
            if (_sigs_Value.Contains((uint)paramEnum) == false)
            {
                retval  = (int)ErrorCode.SIG_NOT_UPDATED;
                rawBits = 0; /* default value if signal was not received */
            }
            else
            {
                Object value = _sigs_Value[(uint)paramEnum];
                uint   temp  = (uint)value;
                rawBits = (int)temp;
            }
            return(retval);
        }
Exemple #27
0
        //------------------------------------- framing functions -----------------------------------------//

        /**
         * Asks TALON to immedietely respond with signal value.  This API is only used
         * for signals that are not sent periodically.
         * This can be useful for reading params that rarely change like Limit Switch
         * settings and PIDF values.
         * @param param to request.
         */
        private ErrorCode RequestParam(ParamEnum paramEnum, int value, byte subValue, int ordinal)
        {
            /* process received param events. We don't expect many since this API is not
             * used often. */
            ProcessStreamMessages();

            if (ordinal < 0x0)
            {
                return(ErrorCode.CAN_INVALID_PARAM);
            }
            if (ordinal > 0xF)
            {
                return(ErrorCode.CAN_INVALID_PARAM);
            }

            byte paramEnum_h8 = (byte)((int)paramEnum >> 4);
            byte paramEnum_l4 = (byte)((int)paramEnum & 0xF);

            ulong frame = 0;

            frame   = subValue;
            frame <<= 8;
            frame  |= 0x00;
            frame <<= 8;
            frame  |= (byte)(value >> 0x00);
            frame <<= 8;
            frame  |= (byte)(value >> 0x08);
            frame <<= 8;
            frame  |= (byte)(value >> 0x10);
            frame <<= 8;
            frame  |= (byte)(value >> 0x18);
            frame <<= 8;
            frame  |= (byte)(ordinal | (paramEnum_l4 << 4));
            frame <<= 8;
            frame  |= (byte)(paramEnum_h8);

            ErrorCode status = (ErrorCode)CTRE.Native.CAN.Send(PARAM_REQUEST | GetDeviceNumber(), frame, 8, 0);

            return(status);
        }
 public int SetParam(ParamEnum paramEnum, float value, uint timeoutMs = 0)
 {
     Int32 rawbits = 0;
     switch (paramEnum)
     {
         case ParamEnum.eProfileParamSlot0_P: /* unsigned 10.22 fixed pt value */
         case ParamEnum.eProfileParamSlot0_I:
         case ParamEnum.eProfileParamSlot0_D:
         case ParamEnum.eProfileParamSlot1_P:
         case ParamEnum.eProfileParamSlot1_I:
         case ParamEnum.eProfileParamSlot1_D:
             {
                 UInt32 urawbits;
                 if (value > 1023) /* bounds check doubles that are outside u10.22 */
                     value = 1023;
                 else if (value < 0)
                     value = 0;
                 urawbits = (UInt32)(value * FLOAT_TO_FXP_10_22); /* perform unsign arithmetic */
                 rawbits = (int)urawbits; /* copy bits over.  SetParamRaw just stuffs into CAN frame with no sense of signedness */
             }
             break;
         case ParamEnum.eProfileParamSlot1_F: /* signed 10.22 fixed pt value */
         case ParamEnum.eProfileParamSlot0_F:
             if (value > 512) /* bounds check doubles that are outside s10.22 */
                 value = 512;
             else if (value < -512)
                 value = -512;
             rawbits = (Int32)(value * FLOAT_TO_FXP_10_22);
             break;
         case ParamEnum.eProfileParamVcompRate: /* unsigned 0.8 fixed pt value volts per ms */
                                                /* within [0,1) volts per ms.
                                                        Slowest ramp is 1/256 VperMilliSec or 3.072 seconds from 0-to-12V.
                                                        Fastest ramp is 255/256 VperMilliSec or 12.1ms from 0-to-12V.
                                                        */
             if (value <= 0)
             {
                 /* negative or zero (disable), send raw value of zero */
                 rawbits = 0;
             }
             else {
                 /* nonzero ramping */
                 rawbits = (int)(value * FLOAT_TO_FXP_0_8);
                 /* since whole part is cleared, cap to just under whole unit */
                 if (rawbits > (FLOAT_TO_FXP_0_8 - 1))
                     rawbits = (int)(FLOAT_TO_FXP_0_8 - 1);
                 /* since ramping is nonzero, cap to smallest ramp rate possible */
                 if (rawbits == 0)
                 {
                     /* caller is providing a nonzero ramp rate that's too small
                             to serialize, so cap to smallest possible */
                     rawbits = 1;
                 }
             }
             break;
         default: /* everything else is integral */
             rawbits = (Int32)value;
             break;
     }
     return SetParamRaw(paramEnum, rawbits, timeoutMs);
 }
 public Int32 GetParamResponseInt32(ParamEnum paramEnum, out int value)
 {
     float dvalue = 0;
     int retval = GetParamResponse(paramEnum, out dvalue);
     value = (Int32)dvalue;
     return retval;
 }
Exemple #30
0
 /// <summary>
 /// Sets a parameter. Generally this is not used.
 /// This can be utilized in
 /// - Using new features without updating API installation.
 /// - Errata workarounds to circumvent API implementation.
 /// - Allows for rapid testing / unit testing of firmware.
 /// </summary>
 /// <param name="param">Parameter enumeration.</param>
 /// <param name="value">Value of parameter.</param>
 /// <param name="subValue">Subvalue for parameter.Maximum value of 255.</param>
 /// <param name="ordinal">Ordinal of parameter.</param>
 /// <param name="timeoutMs">Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.</param>
 /// <returns>Error Code generated by function. 0 indicates no error.</returns>
 public ErrorCode ConfigSetParameter(ParamEnum param, double value, int subValue, int ordinal, int timeoutMs)
 {
     return(ConfigSetParameter((int)param, value, subValue, ordinal, timeoutMs));
 }
Exemple #31
0
 public static void paramMethod(int i, [In] int j, [Out] int k, [Optional] int l, [In, Out] int m, ParamEnum n = ParamEnum.Foo)
 {
 }
Exemple #32
0
 public static void paramMethod(int i, [In] int j, [Out] int k, [Optional] int l, [In, Out] int m, [DefaultParameterValue(ParamEnum.Foo)] ParamEnum n)
 {
 }
 /**
  * Asks TALON to immedietely respond with signal value.  This API is only used
  * for signals that are not sent periodically.
  * This can be useful for reading params that rarely change like Limit Switch
  * settings and PIDF values.
   * @param param to request.
  */
 public int RequestParam(ParamEnum paramEnum)
 {
     /* process received param events. We don't expect many since this API is not
      * used often. */
     ProcessStreamMessages();
     int status = CTRE.Native.CAN.Send(PARAM_REQUEST | GetDeviceNumber(), (uint)paramEnum, 1, 0);
     return status;
 }
 /*---------------------setters and getters that use the param
  * request/response-------------*/
 /**
  * Send a one shot frame to set an arbitrary signal.
  * Most signals are in the control frame so avoid using this API unless you have
  * to.
  * Use this api for...
  * -A motor controller profile signal eProfileParam_XXXs.  These are backed up
  * in flash.  If you are gain-scheduling then call this periodically.
  * -Default brake and limit switch signals... eOnBoot_XXXs.  Avoid doing this,
  * use the override signals in the control frame.
  * Talon will automatically send a PARAM_RESPONSE after the set, so
  * GetParamResponse will catch the latest value after a couple ms.
  */
 public int SetParamRaw(ParamEnum paramEnum, int rawBits, uint timeoutMs = 0)
 {
     /* caller is using param API.  Open session if it hasn'T been done. */
     if (0 == _can_h) OpenSessionIfNeedBe();
     /* wait for response frame */
     if (timeoutMs != 0)
     {
         /* remove stale entry if caller wants to wait for response. */
         _sigs.Remove((uint)paramEnum);
     }
     /* frame set request and send it */
     UInt64 frame = ((UInt64)rawBits) & 0xFFFFFFFF;
     frame <<= 8;
     frame |= (byte)paramEnum;
     uint arbId = PARAM_SET | GetDeviceNumber();
     int status = CTRE.Native.CAN.Send(arbId, frame, 5, 0);
     /* wait for response frame */
     if(timeoutMs > 0)
     {
         int readBits;
         /* loop until timeout or receive if caller wants to check */
         while (timeoutMs > 0)
         {
             /* wait a bit */
             System.Threading.Thread.Sleep(1);
             /* see if response was received */
             if(0 == GetParamResponseRaw(paramEnum, out readBits))
                 break; /* leave inner loop */
             /* decrement */
             --timeoutMs;
         }
         /* if we get here then we timed out */
         if (timeoutMs == 0)
             status = (int)Codes.CTR_SigNotUpdated;
     }
     return status;
 }
 /**
  * Checks cached CAN frames and updating solicited signals.
  */
 public int GetParamResponseRaw(ParamEnum paramEnum, out Int32 rawBits)
 {
     int retval = 0;
     /* process received param events. We don't expect many since this API is not
      * used often. */
     ProcessStreamMessages();
     /* grab the solicited signal value */
     if (_sigs.Contains((uint)paramEnum) == false)
     {
         retval = (int)Codes.CTR_SigNotUpdated;
         rawBits = 0; /* default value if signal was not received */
     }
     else
     {
         Object value = _sigs[(uint)paramEnum];
         uint temp = (uint)value;
         rawBits = (int)temp;
     }
     return retval;
 }
 public int GetParamResponse(ParamEnum paramEnum, out float value)
 {
     Int32 rawbits = 0;
     int retval = GetParamResponseRaw(paramEnum, out rawbits);
     switch (paramEnum)
     {
         case ParamEnum.eProfileParamSlot0_P: /* 10.22 fixed pt value */
         case ParamEnum.eProfileParamSlot0_I:
         case ParamEnum.eProfileParamSlot0_D:
         case ParamEnum.eProfileParamSlot0_F:
         case ParamEnum.eProfileParamSlot1_P:
         case ParamEnum.eProfileParamSlot1_I:
         case ParamEnum.eProfileParamSlot1_D:
         case ParamEnum.eProfileParamSlot1_F:
         case ParamEnum.eCurrent:
         case ParamEnum.eTemp:
         case ParamEnum.eBatteryV:
             value = ((float)rawbits) * FXP_TO_FLOAT_10_22;
             break;
         case ParamEnum.eProfileParamVcompRate:
             value = ((float)rawbits) * FXP_TO_FLOAT_0_8;
             break;
         default: /* everything else is integral */
             value = (float)rawbits;
             break;
     }
     return retval;
 }