|
Main /
SD-21The SD-21 In our setup, the SD-21 requires two power sources: one for the logic and another for powering the servos. There is a way to bridge the servo power source if need be, but as we are using two power supplies anyway, it works well. A Quick Note About ServosServos are boxes with small motors, a gearbox and a potentiometer inside. This allows the output shaft to be positioned within a 180 degree range of motion with great accuracy. A standard hobby servo produces about 40 oz./in. of torque, which is enough to rotate a head, control steering system, or actuate an arm. Servos have three pins: two provide power (red and black) and the third is the input which tells the servo which position to rotate to. The signal is a continuous series of pulses ranging from 1ms to 2ms, spaced at intervals of ~20ms. A 1ms pulse tells the servo to rotate counter-clockwise 90 degrees from center, 2ms is 90 degrees clockwise from center, and 1.5ms means to return to the center state. The pulses must be continuous, that is if they stop the servo might behave unpredictably. It is a small chore for any microcontroller to send a pule out on an output pin every 20ms in addition to performing other tasks, let alone sending 20 pulses every 20ms! It is for this reason that we abstract this to a servo controller; we can tell the controller to send servo 1 to center position, and forget about it knowing that the controller has it taken care of. Read more about servo theory and how to work with them on Lynxmotion's "what is a servo?" RegistersThe SD-21 shows up as a series of registers that can be read to and written from the I2C bus:
(Table shamelessly copied from robot-electronics.com) You might notice that each channel has three registers associated with it: speed, low byte and high byte. In order to control a servo, you must set the low byte and high byte for the position desired in microseconds. To center a servo, you would send it a 1.5ms pulse, so sending the SD-21 a value of 1500 will do the same thing. A single byte (such as 0xFF) has a resolution of only 255 steps, so in order to get the full range of motion from a servo, the SD-21 requires a low byte and a high byte for each servo. 1500 (decimal) is 0x05DC in hexadecimal. In order to get the low byte, simply AND the value desired with 0xFF; to get the high byte, shift the value right by 8 bits. In C/C++, the code would look something like: int myValue = 1500; int lowByte = myValue & 0xFF; int highByte = myValue >> 8; The speed register for each channel is a way to linearly set the speed at which the servo will be directed to reach the desired position. The default is 0, full speed ahead. The speed is reset to 0 every time the power is cycled on the SD-21, so be sure to set it to the desired value every time your robot restarts. The equation for the speed is: That is, if you have a servo at position 2000 and you want to move it to position 1000 (180 degrees), and the speed register is set to 5 then it would take 4 seconds to complete the rotation. Battery CheckingRegister 65 on the SD-21 is a live readout of the current battery voltage updated every 20ms whether it is checked or not. It is measured in 39mV units, so a typical 7.2V battery should give a reading of 184.6 when full. The equation is simply |