Polar Bear Motor Controller
The Polar Bear Motor Controller (also called the PiE Motor Controller) is a motor controller board developed in-house by PiE to serve as the primary motor controller board for the 2012 competition. It communicates with the FEZ Panda II via a 3-wire I2C cable and can also interface with an encoder.
Wiring it Up
See the main Wiring Diagram Page.
Using Motor Without Encoder
Using Motor with Encoder
The I2C Address is indicated by a shiny star on the back of the board where red=0x0A, and gold=0x0B, blue=0x0C, silver=0x0D, and green=0x0E. The address 0x0Fis simply written on masking tape on the back of the board as we ran out of colors. Currently, the only way to change the adress is to bring the motor controller in to PiE headquarters (O'Brien). You must use the I2C address when referring to motor controllers in software so that the FEZ Panda knows which board you are referring to. Please note that the address refers to the actual motor, and not the pins the motor signal wires are connected to on the topboard.
How to go About changing the Address
Every board on your robot must have a unique I2C address, so if you have two boards with the same address, exchange the board with a PiE staff member for one with a different address. The PiE staff member may alternately choose to change the address of the controller manually assigning it a new address by uploading new firmware and replacing the sticker. The address that the board uses is hardcoded into the firmware and can only be changed by re-uploading code to the microcontroller.
Please ignore anything written on the bottom of the motor controller. These probably indicate notes made during the manufacturing process. The only important thing on the bottom of the board is the colored star (See the description of the addressing scheme above).
Confused about what the LEDs mean on your robot? This helpful table should let you know what's going on.
These LEDs are located on your motor controller board in the locations shown in the picture
Ex. If both the red and green LED are on the motor controller, then there is an error!
Firmware is available at https://github.com/keeganmann/PiE-Motor-Controller).
See the i2ctester project on GitHub: https://github.com/keeganmann/PiE-Motor-Controller
See the official I2C standard for basic information about the I2C protocol: http://www.nxp.com/documents/user_manual/UM10204.pdf
I2C Device Address
Eventually, we may add the ability to change the device address using I2C, but for the time being it is hard-coded.
Reading and Writing Registers
To write to a series of registers, first write the address pointer byte and then send data bytes. Data will fill up registers one after the other starting at the one specified by the start byte. For each byte sent, the address pointer will increment. Note that by writing a single byte, you can set the address pointer without changing any data.
To read a series of registers, set the address as described above, then read a single byte. Each time a byte is read, the address pointer will increment. Note that although multiple bytes can be written at a time, only a single byte can be read per transaction.
Note: Maximum transaction length is 32 bytes (I don’t anticipate this to be a problem).
NOTE THAT ONLY FEATURES IN BOLD ARE IMPLEMENTED.
||Sets not just the direction, but also the mode of operation. The form A/B indicates the two states between which PWM alternates. The Motor PWM register below determines how long the controller stays in state A relative to state B.|
|0x02||Motor PWM/speed|| 0-255 where:
||Also used to set the amount of braking.|
|0x10-0x11||Motor Feedback||Two-byte unsigned integer||Voltage on the feedback pin of the H-bridge where 0=0V and 1024=5V. To get motor current, use: (Current)=(Feedback Value)*75/4096|
|0x20-0x23||Encoder count||Signed two’s complement 4-byte integer||Number of steps the encoder has moved since the last reset.|
|0x24-0x27||Encoder Loopback Point|| 0=No loopback point,
Otherwise, a positive 4-byte integer
|The maximum value the encoder will get to before resetting to zero. Useful when the number of revolutions is not significant and you only want the angle. Also used by PID. Note, encoder count will never go negative with this set.|
|0x28-0x2B||Encoder Velocity||An IEEE-754 binary32 number||Rate at which the encoder is moving in steps per second|
|0x30-0x33||PID Setpoint||An IEEE-754 binary32 number||Read more about PIDs to understand this|
|0x34-0x37||PID P-Constant||An IEEE-754 binary32 number|
|0x38-0x3B||PID I-Constant||An IEEE-754 binary32 number|
|0x3C-0x3F||PID D-Constant||An IEEE-754 binary32 number|
||Enable PID using current feedback or using the encoder speed (or maybe position too).|
|0x50||I2C Address||0x00-0x7F||Used for resetting the I2C Address|
|0x62-0x6B||Compilation Date|| 11-char ASCII string:
"Feb 12 1996"
|Date when the firmware was compiled.|
|0x6B-0x72||Compilation Time|| 8-char ASCII string:
|Time when the firmware was compiled.|
|????||Cutoff Begin||###-###||When current limiting should kick in.|
|0xA0||Stress Period|| 0=Inactive
1-255=Period in hundredths of a second
|Will toggle the direction between forward and reverse at the specified frequency.|
|0xA1||0=Inactive||Note that this functionality is as of yet unavailable in version 0.5 of the firmware. It is only available in version 0.4.|
Eagle PCB Design Files
The eagle files are available here on google docs: https://docs.google.com/open?id=0B2ZbLCPalrgENkM1akROT3dSQ2kySHBHTVU1dmxCUQ
Sample Code for the FEZ Panda
See I2CMotorController, the class that controls Polar Bear Motor Controllers.