Exemplo n.º 1
0
Arquivo: Jrk.cs Projeto: lukazikus/mmc
        private void setParameter(jrkParameter parameterId, uint value)
        {
            Range range = parameterId.range();

            requireArgumentRange(value, range.minimumValue, range.maximumValue, parameterId.ToString());

            try
            {
                if (range.bytes == 1)
                {
                    setRequestU8(jrkRequest.REQUEST_SET_PARAMETER, (Byte)parameterId, (Byte)value);
                }
                else if (range.bytes == 2)
                {
                    setRequestU16(jrkRequest.REQUEST_SET_PARAMETER, (Byte)parameterId, (UInt16)value);
                }
                else
                {
                    throw new NotImplementedException("Byte count " + range.bytes + " is not implemented yet.");
                }
            }
            catch (Exception exception)
            {
                throw new Exception("There was an error setting " + parameterId.ToString() + ".", exception);
            }
        }
Exemplo n.º 2
0
Arquivo: Jrk.cs Projeto: lukazikus/mmc
 /// <summary>
 /// sets the parameter on the device.  The only parameter modified before setting is the
 /// serial fixed baud rate, which is converted to the PIC's SPBRG setting.
 /// </summary>
 /// <param name="parameterId"></param>
 /// <param name="value"></param>
 public void setJrkParameter(jrkParameter parameterId, uint value)
 {
     if (parameterId == jrkParameter.PARAMETER_SERIAL_FIXED_BAUD_RATE)
     {
         value = convertBpsToSpbrg(value);
     }
     setParameter(parameterId, value);
 }
Exemplo n.º 3
0
Arquivo: Jrk.cs Projeto: lukazikus/mmc
        /// <summary>
        /// Gets the jrk parameter.  The only one that is modified by this function relative to
        /// what is actually on the device is the serial baud rate.
        /// </summary>
        /// <param name="parameterId"></param>
        /// <returns></returns>
        public uint getJrkParameter(jrkParameter parameterId)
        {
            uint value = getParameter(parameterId);

            if (parameterId == jrkParameter.PARAMETER_SERIAL_FIXED_BAUD_RATE)
            {
                return(convertSpbrgToBps((ushort)value));
            }

            return(value);
        }
Exemplo n.º 4
0
Arquivo: Jrk.cs Projeto: lukazikus/mmc
        private unsafe uint getParameter(jrkParameter parameterId)
        {
            Range range = parameterId.range();

            try
            {
                return(getRequest(jrkRequest.REQUEST_GET_PARAMETER, (UInt16)parameterId, range.bytes));
            }
            catch (Exception exception)
            {
                throw new Exception("There was an error reading " + parameterId.ToString() + " from the device.", exception);
            }
        }
Exemplo n.º 5
0
        private void setParameter(jrkParameter parameterId, uint value)
        {
            Range range = parameterId.range();
            requireArgumentRange(value, range.minimumValue, range.maximumValue, parameterId.ToString());

            try
            {
                if (range.bytes == 1)
                {
                    setRequestU8(jrkRequest.REQUEST_SET_PARAMETER, (Byte)parameterId, (Byte)value);
                }
                else if (range.bytes == 2)
                {
                    setRequestU16(jrkRequest.REQUEST_SET_PARAMETER, (Byte)parameterId, (UInt16)value);
                }
                else
                {
                    throw new NotImplementedException("Byte count " + range.bytes + " is not implemented yet.");
                }
            }
            catch (Exception exception)
            {
                throw new Exception("There was an error setting " + parameterId.ToString() + ".", exception);
            }
        }
Exemplo n.º 6
0
        private unsafe uint getParameter(jrkParameter parameterId)
        {
            Range range = parameterId.range();

            try
            {
                return getRequest(jrkRequest.REQUEST_GET_PARAMETER, (UInt16)parameterId, range.bytes);
            }
            catch (Exception exception)
            {
                throw new Exception("There was an error reading " + parameterId.ToString() + " from the device.", exception);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// sets the parameter on the device.  The only parameter modified before setting is the
 /// serial fixed baud rate, which is converted to the PIC's SPBRG setting.
 /// </summary>
 /// <param name="parameterId"></param>
 /// <param name="value"></param>
 public void setJrkParameter(jrkParameter parameterId, uint value)
 {
     if (parameterId == jrkParameter.PARAMETER_SERIAL_FIXED_BAUD_RATE)
     {
         value = convertBpsToSpbrg(value);
     }
     setParameter(parameterId, value);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the jrk parameter.  The only one that is modified by this function relative to
        /// what is actually on the device is the serial baud rate.
        /// </summary>
        /// <param name="parameterId"></param>
        /// <returns></returns>
        public uint getJrkParameter(jrkParameter parameterId)
        {
            uint value = getParameter(parameterId);
            if (parameterId == jrkParameter.PARAMETER_SERIAL_FIXED_BAUD_RATE)
            {
                return convertSpbrgToBps((ushort)value);
            }

            return value;
        }
Exemplo n.º 9
0
Arquivo: Jrk.cs Projeto: lukazikus/mmc
        public static Range range(this jrkParameter parameterId)
        {
            switch (parameterId)
            {
            default:
                throw new ArgumentException("Invalid parameterId " + parameterId.ToString() + ", can not determine the range of this parameter.");

            case jrkParameter.PARAMETER_INITIALIZED: return(new Range(1, 0, 255));

            case jrkParameter.PARAMETER_INPUT_MODE: return(new Range(1, 0, 2));  // enum

            case jrkParameter.PARAMETER_INPUT_MINIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_INPUT_MAXIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_OUTPUT_MINIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_OUTPUT_NEUTRAL: return(Range.u12);

            case jrkParameter.PARAMETER_OUTPUT_MAXIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_INPUT_INVERT: return(Range.boolean);

            case jrkParameter.PARAMETER_INPUT_SCALING_DEGREE: return(Range.u8);     // But anything over 4 is crazy

            case jrkParameter.PARAMETER_INPUT_POWER_WITH_AUX: return(Range.boolean);

            case jrkParameter.PARAMETER_FEEDBACK_DEAD_ZONE: return(Range.u8);

            case jrkParameter.PARAMETER_INPUT_ANALOG_SAMPLES_EXPONENT: return(new Range(1, 0, 8));

            case jrkParameter.PARAMETER_INPUT_DISCONNECT_MAXIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_INPUT_DISCONNECT_MINIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_INPUT_NEUTRAL_MAXIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_INPUT_NEUTRAL_MINIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_SERIAL_MODE: return(new Range(1, 0, 3));

            case jrkParameter.PARAMETER_SERIAL_FIXED_BAUD_RATE: return(Range.u16);

            case jrkParameter.PARAMETER_SERIAL_TIMEOUT: return(Range.u16);

            case jrkParameter.PARAMETER_SERIAL_ENABLE_CRC: return(Range.boolean);

            case jrkParameter.PARAMETER_SERIAL_NEVER_SUSPEND: return(Range.boolean);

            case jrkParameter.PARAMETER_SERIAL_DEVICE_NUMBER: return(new Range(1, 0, 127));

            case jrkParameter.PARAMETER_FEEDBACK_MODE: return(new Range(1, 0, 5));   // enum

            case jrkParameter.PARAMETER_FEEDBACK_MINIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_FEEDBACK_MAXIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_FEEDBACK_INVERT: return(Range.boolean);

            case jrkParameter.PARAMETER_FEEDBACK_POWER_WITH_AUX: return(Range.boolean);

            case jrkParameter.PARAMETER_FEEDBACK_DISCONNECT_MAXIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_FEEDBACK_DISCONNECT_MINIMUM: return(Range.u12);

            case jrkParameter.PARAMETER_FEEDBACK_ANALOG_SAMPLES_EXPONENT: return(new Range(1, 0, 8));

            case jrkParameter.PARAMETER_PROPORTIONAL_MULTIPLIER: return(Range.u10);

            case jrkParameter.PARAMETER_PROPORTIONAL_EXPONENT: return(new Range(1, 0, 15));

            case jrkParameter.PARAMETER_INTEGRAL_MULTIPLIER: return(Range.u10);

            case jrkParameter.PARAMETER_INTEGRAL_EXPONENT: return(new Range(1, 0, 15));

            case jrkParameter.PARAMETER_DERIVATIVE_MULTIPLIER: return(Range.u10);

            case jrkParameter.PARAMETER_DERIVATIVE_EXPONENT: return(new Range(1, 0, 15));

            case jrkParameter.PARAMETER_PID_PERIOD: return(new Range(2, 1, 8191));

            case jrkParameter.PARAMETER_PID_INTEGRAL_LIMIT: return(new Range(2, 0, 32767));

            case jrkParameter.PARAMETER_PID_RESET_INTEGRAL: return(Range.boolean);

            case jrkParameter.PARAMETER_MOTOR_PWM_FREQUENCY: return(new Range(1, 0, 2));  // enum

            case jrkParameter.PARAMETER_MOTOR_INVERT: return(Range.boolean);

            case jrkParameter.PARAMETER_MOTOR_MAX_ACCELERATION_FORWARD: return(new Range(2, 1, 600));

            case jrkParameter.PARAMETER_MOTOR_MAX_ACCELERATION_REVERSE: return(new Range(2, 1, 600));

            case jrkParameter.PARAMETER_MOTOR_MAX_DUTY_CYCLE_FORWARD: return(new Range(2, 0, 600));

            case jrkParameter.PARAMETER_MOTOR_MAX_DUTY_CYCLE_REVERSE: return(new Range(2, 0, 600));

            case jrkParameter.PARAMETER_MOTOR_MAX_CURRENT_FORWARD: return(new Range(1, 0, 255));

            case jrkParameter.PARAMETER_MOTOR_MAX_CURRENT_REVERSE: return(new Range(1, 0, 255));

            case jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_FORWARD: return(new Range(1, 0, 255));

            case jrkParameter.PARAMETER_MOTOR_CURRENT_CALIBRATION_REVERSE: return(new Range(1, 0, 255));

            case jrkParameter.PARAMETER_MOTOR_BRAKE_DURATION_FORWARD: return(new Range(1, 0, 255));

            case jrkParameter.PARAMETER_MOTOR_BRAKE_DURATION_REVERSE: return(new Range(1, 0, 255));

            case jrkParameter.PARAMETER_MOTOR_COAST_WHEN_OFF: return(Range.boolean);

            case jrkParameter.PARAMETER_MOTOR_MAX_DUTY_CYCLE_WHILE_FEEDBACK_OUT_OF_RANGE: return(new Range(2, 1, 600));

            case jrkParameter.PARAMETER_ERROR_ENABLE: return(Range.u16);

            case jrkParameter.PARAMETER_ERROR_LATCH: return(Range.u16);
            }
        }