VB: Pololu Controller
| VB: Pololu Controller |
Pololu sells an excellent serial servo controller. However there is no test software that comes with it, so I wrote this one in Visual Basic 6.
pololu_controller.frm - The VB form
pololu_controller.vbp - The VB project
pololu_controller.exe - The compiled EXE
pololu_controller.zip - The above files in a zip file
How it Works
Each channel is a slider, the numbers at the bottom are the absolute pololu value, and the percentage +-100.
Pololu Specific Code
We're using Pololu Mode 4, which means we're sending the absolute position of the servo that we want to set it to. The range is 500-5500 and the format has some quirks.
| Byte | Value | Title | Description |
| 1 | 0x80 | start byte | constant |
| 2 | 0x01 | Device ID | constant |
| 3 | 0x04 | Command | we want command 4: Set Position, Absolute (2 data bytes) |
| 4 | 0x00-0x07 | Servo num | The servo number we want |
| 5 | 0x00-0xef | MSB (7bit) | The msb is the upper seven bits of the value |
| 6 | 0x00-0xef | LSB (7bit) | The lsb is the lower seven bits of the value |
cmd = Chr(&H80)
cmd = cmd & Chr(&H1)
cmd = cmd & Chr(&H4)
cmd = cmd & Chr(num)
' Since pololu packets are 7-bit, we have to do some VB wrangling to convert our integers into 7-bit bytes:
' Convert from decimal to binary string, and pad in a bunch of zeros
strbinary = "0000000000000000" & dec2bin(value)
' Grab the last 7 bits as the lsb
lsb = "0" & Mid(strbinary, Len(strbinary) - 6)
' And the first 7 as the msb.
msb = "0" & Mid(strbinary, Len(strbinary) - 12, 6)
' Convert them back into decimal and add them onto the command string to send
cmd = cmd & Chr(bin2dec(msb))
cmd = cmd & Chr(bin2dec(lsb))
' Write the output to the serial port
MSComm1.Output = cmd & vbNewLine
' We need to delay a bit (60ms) to give the device time to respond
Sleep 60
|
|