Hello --
I have a SM23165DT motor that I'm trying to program with SMIEngine and Java. So far, I am able to control the motor by using the Serial Commands. For example, I can home the motor to zero by the following sequence:
// send to all motors myPort.write(0x80); // configure environment myPort.write("AMPS=" + str(pow) + " "); myPort.write("VT=" + str(vel) + " "); myPort.write("ADT=" + str(acc) + " "); // reset position myPort.write("PT=" + str(0.0) + " "); myPort.write("G ");
Similarly, I can continually update the motor's position by looping:
myPort.write(0x80); float velocity = someValue; myPort.write("VT=" + str(int(velocity)) + " "); float position = someOtherValue; myPort.write("PT=" + str(int(position)) + " "); myPort.write("G ");
However, this isn't ideal because writing position data frame-by-frame results in chunky motion, as the motor moves, stops, waits, and then moves to the next point the next frame. I'd like to use the Serial Interpolation features in order to smoothly move to the next position with a specific time delta.
However, I've tried to use the following code:
myPort.write(0x80); myPort.write(0xFB); // command 0xFB: Write Time Delta myPort.write(0xFF); // LSB: 0xFF myPort.write(0xFF); // MSB: 0xFF -- total is 0xFFFF (65,535); should be about 8 seconds myPort.write(0x20); // terminator byte myPort.write(0xFA); // command 0xFA: Write Position Data myPort.write(0x00); // LSB myPort.write(0x00); myPort.write(0x00); myPort.write(0x00); // MSB; total is 0x00000000 (0.0) myPort.write(0x20); // terminator byte myPort.write("G ");
And this has no effect. No motion in the motor, not even at a specific speed.
How can I program the motor to move smoothly to the next position at a specific time?
thanks!
There is an example program provided in the SMI Engine help file. This is included when you download SMI. The path on my machine is...
C > Program Files (x86) > Animatics > SMIEngine.
In the help file, see Serial Interpolation > Host Mode Example
You likely need to give the MD, MDCFG commands before
You're right; I do. I've reviewed the sample code, but it's a bit obtuse when I already have another library that's able to send multi-byte packets.
I've tried adding the MD and MDCFG commands:
myPort.write(0x81); myPort.write("MD" + " "); myPort.write("MDCFG(3)" + " "); // tell motor 1 to be the master clock and use spline mode myPort.write(0xFB); // command 0xFB: Write Time Delta myPort.write(0xFF); // LSB: 0xFF myPort.write(0xFF); // MSB: 0xFF -- total is 0xFFFF (65,535) myPort.write(0x20); // terminator byte myPort.write(0xFA); // command 0xFA: Write Position Data myPort.write(0x00); // LSB myPort.write(0x00); myPort.write(0x00); myPort.write(0x00); // MSB; total is 0x00000000 (0.0) myPort.write(0x20); // terminator byte myPort.write("G ");
but the motor doesn't move when I run this short program.
You're right -- I forgot to include those commands! Unfortuantely, even when they are included, I have no action from the motor. The program I've been trying is:
myPort.write(0x81); myPort.write("MD" + " "); myPort.write("MDCFG(3)" + " "); // tell motor 1 to be the master clock and use spline mode myPort.write(0xFB); // command 0xFB: Write Time Delta myPort.write(0xFF); // LSB: 0xFF myPort.write(0xFF); // MSB: 0xFF -- total is 0xFFFF (65,535) myPort.write(0x20); // terminator byte myPort.write(0xFA); // command 0xFA: Write Position Data myPort.write(0x00); // LSB myPort.write(0x00); myPort.write(0x00); myPort.write(0x00); // MSB; total is 0x00000000 (0.0) myPort.write(0x20); // terminator byte myPort.write("G ");
I've browsed through the example; it's a bit confusing as it contains many more wrapper functions C++-specific code than is strictly necessary for me to simply send bytes over RS-232. However, looking at the example, it doesn't look like I'm missing any commands.
I would recommend writing more positions before issuing a go command.
Also, do not use the terminator bytes after non-ASCII commands. See code:
buf[0] = 0x81; buf[1] = 0x20; WriteFile(Port,buf,2,&BytesWritten,0) command.Format(_T("EIGN(2) ")); WriteFile(Port,command,8,&BytesWritten,0) command.Format(_T("EIGN(3) ")); WriteFile(Port,command,8,&BytesWritten,0) command.Format(_T("ZS ")); WriteFile(Port,command,3,&BytesWritten,0) command.Format(_T("MD ")); WriteFile(Port,command,3,&BytesWritten,0) command.Format(_T("MDCFG(1) ")); WriteFile(Port,command,9,&BytesWritten,0) buf[0] = 0xFB; buf[1] = 0x40; buf[2] = 0x1f; // 0x1f40 = 1 sec, 0x3e80 = 2sec, 0xfa00 = 8sec WriteFile(Port,buf,3,&BytesWritten,0) buf[0] = 0xFA; buf[1] = 0x00; buf[2] = 0x00; buf[3] = 0x00; buf[4] = 0x00; WriteFile(Port,buf,5,&BytesWritten,0) WriteFile(Port,buf,5,&BytesWritten,0) command.Format(_T("G ")); WriteFile(Port,command,2,&BytesWritten,0)