
| Home | Order | Product Design / Help |
In the Micro Serial Servo Controller Users Guide you'll see that there are several modes you can work in. You'll want Pololu Mode and Command 4.
Command 4: Set Position, Absolute (2 data bytes)
This mode allows the most precision for the servo position, with 5,000 allowable values. The problem is that it's 500-5500, and has to be converted to 7-bit values.
bool SetServo(int servo_number, double percent) {
char binary[80]; // for debugging
unsigned char out[6];
out[0] = 0x80; // start byte
out[1] = 0x01; // deviceid (1=servo)
out[2] = 0x04; // 0x04 = 2byte absolute position
out[3] = servo_number;
// min: 0x0374 max: 0x4a7c (884, 19,068, not inclusive)
// adjust the percent to be from 0x0374 to 0x4a7c which is the pololu limits
long val = (long)(0x0374 + (0x4a7c - 0x0374) * percent);
char lsb = val & 0x7f; // 0000 0000 0111 1111
val >>= 7; // shift bits
char msb = val & 0x7f; // 0000 0000 0111 1111
out[4] = msb;
out[5] = lsb;
serial_send(out, 6);
}
Private Function SendPololu(servo_number As Integer, value As Integer)
Dim cmd As String
Dim strbinary As String
Dim lsb As String
Dim msb As String
cmd = Chr(&H80) ' start byte - 0x80 ' always
cmd = cmd & Chr(&H1) ' Device ID - 0x01 ' always
cmd = cmd & Chr(&H4) ' command - 0x04 ' we want command 4: Set Position, Absolute (2 data bytes)
cmd = cmd & Chr(servo_number) ' servo servo_number - 0x.. ' 00-07
' data1 - 0x.. ' upper 7 bits - range is 500 through 5500
' data2 - 0x.. ' lower 7 bits
strbinary = "0000000000000000" & dec2bin(value)
lsb = "0" & Mid(strbinary, Len(strbinary) - 6)
msb = "0" & Mid(strbinary, Len(strbinary) - 12, 6)
cmd = cmd & Chr(bin2dec(msb))
cmd = cmd & Chr(bin2dec(lsb))
serial_send cmd
End Function
For general inquiries, contact support@robotairsoft.com