FRC1076 / RobotKitLib

Robotpy-WPILIB equivalent for raspberry pi robot kit
1 stars 1 forks source link

Figure out (and rewrite) the ADC (Analog to Digital Converter) to monitor battery voltage. Document the other ADC inputs so we can use them. #22

Open mcolinj opened 3 years ago

mcolinj commented 3 years ago

Server/ADC.py is an interface to an analog to digital converter. See if you can figure out what it is wired to, and what things can be read from the robot. The raspberry pi does not have any analog pins that it can read. It has to use the I2C bus to read analog values determined my another chip.

I know that it is used to implement the POWER command.

In Server/server.py, there is this code:

`

elif cmd.CMD_POWER in data:

                    ADC_Power=self.adc.recvADC(2)*3

                    try:

                        self.send(cmd.CMD_POWER+'#'+str(ADC_Power)+'\n')

                    except:

                        pass

` You could look in the client code and see what it does with it. (maybe just displays it?)

It could be accessing the voltage reading of the battery, which would be very useful.

Note: You can also look at the Freenove documentation to see if it explains the POWER command output.

See if you can figure out if there are other ADC channels we could use to read some other analog values on the robot.

mcolinj commented 3 years ago

Actually, it does look like it might read battery voltage (I'm wondering what other channels might be able to read?)

In Server/server.py, there is this function. See if you can figure out what it does (and when).

` def Power(self):

    while True:

        ADC_Power=self.adc.recvADC(2)*3

        time.sleep(3)

        if ADC_Power < 6.8:

          for i in range(4):

                self.buzzer.run('1')

                time.sleep(0.1)

                self.buzzer.run('0')

                time.sleep(0.1)

        elif ADC_Power< 7:

            for i in range(2):

                self.buzzer.run('1')

                time.sleep(0.1)

                self.buzzer.run('0')

                time.sleep(0.1)

        else:

            self.buzzer.run('0')

`

mcolinj commented 3 years ago

Note that the wpilib interface to an analog electrical value is called AnalogInput

see: https://github.com/robotpy/robotpy-wpilib/blob/2019/wpilib/wpilib/analoginput.py