No announcement yet.

Bug report: error in Voltage sensor math

  • Filter
  • Time
  • Show
Clear All
new posts

  • Bug report: error in Voltage sensor math

    The logic in ModernRoboticsUsbDcMotorController that computes the voltages is this:
    public double getVoltage() {
       return 20.4D * ((double)(1023 & TypeConversion.byteArrayToShort(, 2)) >> 6) / 1023.0D);
    The relevant spec is this (this is from the legacy motor controller spec):

    Originally posted by HiTechnic
    The Battery voltage field will return the current battery voltage. The high byte is the upper 8 bits of a 10 bit value. It may be used as an 8 bit representation of the battery voltage in units of 80mV. This provides a measurement range of 0 – 20.4 volts. The low byte has the lower 2 bits at bit locations 0 and 1 in the byte. This increases the measurement resolution to 20mV
    The issue is that the code seems to use the 2 MSB of the second byte instead of the two LSB.

  • #2
    Thank you for this high quality bug report.