I retired last year and needed something to keep me busy (or my wife was going to divorce me). Thinking they would be interesting to play with I purchased some robotic items at an auction. I was able to learn enough to use some of the parts to make an animated Halloween display using an Arduino for control. This took a long time since I had no mechanical experience, my electronics knowledge is limited and the last programming I had done was in the mid 1970's using assembly on an 8080 based system.
Among the items were 2 arms that use Robotis Dynamixel MX servos. These servos are different since they are controlled by sending commands via the serial (COM) port and the status can be obtained by reading the port. I did some testing and I am able to send the command to set the speed to 40 by using the following code:
Code: Select all
Port$ = "COM4"
If OpenSerialPort(0, Port$, 57600, NoParity, 8, 1, NoHandshake, 1024, 1024)
MessageRequester("Information", Port$+" opened.")
Else
MessageRequester("Error", "Can't open "+Port$+". Ending program.")
End
EndIf
OpenConsole()
PrintN("Press return to continue.")
Input()
; Set speed to 40
SetSpd:
Dim sendBuffer.a(8)
sendBuffer(0) = $FF
sendBuffer(1) = $FF
sendBuffer(2) = $01
sendBuffer(3) = $05
sendBuffer(4) = $03
sendBuffer(5) = $20
sendBuffer(6) = $28
sendBuffer(7) = $00
sendBuffer(8) = $AE
WriteSerialPortData(COM4, @sendBuffer(), 9)This works, but I thought there might be a more efficient way. The problem I am seeing is that the motors expect the HEX value, but other than what I show above, everything I have tried converts this the to the ASCII value for each element. For example $FF is 11111111, but the output I see is the ASCII representation of FF 00011111 00011111. Other than writing each command in the format above, Is there a better / more efficient way of coding this?
Thank you in advance for any assistance. And please take it easy on this old man since I am new at this.



