This document is Copyright ©2002 by Philip C. Pilgrim. However it may be freely copied and disseminated for non-commercial use. |
The converted X10 “Ninja” pan and tilt mechanism receives commands directly from a PC serial port. It communicates at 4800 baud, 8 bits, 1 stop bit, no parity, and no handshaking. In fact, a connected PC gets no feedback from the Ninja at all. It can only send commands and hope they’re executed.
Each command to the Ninja consists of a single letter (case insensitive), possibly followed by a signed decimal number. Numbers can range from –32768 to 65535 and are interpreted signed or unsigned depending on the command. Numbers outside this range have no real meaning for this application, but they will lead to unspecified behavior, since overflow conditions are not checked for.
Commands are buffered in a 16-byte FIFO buffer and are executed in sequence. In addition, the backspace character (Ctrl-H) and Ctrl-R are special commands that are executed immediately, ahead of all their buffer mates. More on those later.
Commands are executed in streaming mode, and no punctuation is needed between them. Unrecognized commands are simply ignored. The commands are defined as follows:
Set the desired X (azimuth) value to the number following. For example X-900 sets X to –900. X can range from –1800 (far left) to 1800 (far right). Values outside this range will saturate to these limits. The center (home) position is zero. This value is persistent until changed with another X command, except when the I (increment position) command is executed. Setting X (or Y) doesn’t cause any motion to occur. It just tells the Ninja where you will be wanting to go when you eventually tell it to move.
Set the desired Y (altitude) value to the number following. For example Y70 sets Y to 70. Y can range from –1200 (far down) to 550 (far up). Values outside this range will saturate to these limits. The center (home) position is zero (looking straight ahead). This value is persistent until changed with another Y command, except when the I (increment position) command is executed.
Set the desired V (velocity) value to the number following. For example V32 sets V to 32. V can range from 0 (a dead creep) to 63 (maximum slew rate). Values outside this range saturate to 63. This value is persistent until changed. The Ninja uses a non-linear velocity scale. That is to say, a velocity of 48, say, won’t necessarily be twice as fast as 24.
Move at speed V to the absolute position (X,Y) along a smooth, coordinated path.
Slew at top speed to the absolute position (X,Y), irrespective of V, along a smooth, coordinated path. (V isn’t changed; it’s just ignored.)
Increment at speed V to the current position plus (X,Y). X and Y are changed to the new absolute position. For this reason, it’s best always to preface the I command with fresh X and Y commands.
Center the platform to its X = 0 and Y = 0 position. This operation moves one axis at a time and uses the Ninja’s built-in position sensors to determine where center is. This operation is also executed when the Ninja first powers up or is externally reset.
Wait for all motion to cease, then pause for <number> tenths of a second. Pauses can range from 0 to 6553.5 seconds. P100, for example, pauses for ten seconds.
Begin a macro definition. Macros are saved in a 64-byte buffer and can be any sequence of Ninja commands and numerical data. Each command occupies one byte. Each numerical entry occupies two bytes, regardless of its size in ASCII form.
All commands, up to and including a terminating “)”, are simply buffered and not executed.
End the current macro definition, and go back to immediate execution mode.
Run the currently defined macro from the beginning. When the R command is received, the macro will begin at the beginning and run to completion. Note: By putting an R at the end of a macro, you can make the macro repeat itself ad infinitum. This will continue until a <backspace> or <cntl-R> is received from the serial port, at which point, the Ninja enters immediate execution mode.
The backspace (Cntl-H for Halt) immediately stops all motion and exits from a macro if one is running. All uninterpreted data in the serial port’s FIFO buffer is purged. Since the speed is not ramped down prior to a halt, rapid motion may overshoot the internally-stored position by four steps. (See “Motion Dynamics” below.) Otherwise, it remembers where it is, and an S or M command can be used to resume travel to the next chosen position. Any defined macro is preserved and may be restarted from the beginning with the R command. It cannot be resumed where it left off.
The Cntl-R (12H) command immediately resets the Ninja, causing it to reseek its center. Any defined macro is cleared so cannot be restarted.
The stepper motors in the Ninja are run in open loop fashion. This is to say that, other than in the centering operation (which uses position sensors), the Ninja doesn’t know where it is – just where it’s supposed to be. Each motor is operated with two coils always active at once while moving. (The coils are turned off between moves.) The original Ninja program used just one coil at a time. This gives the new configuration considerably more torque and top-end speed than the old one. In order to accommodate the highest speeds, the new program incorporates ramping. This allows the motors to accelerate and decelerate smoothly, thus minimizing cogging (or step errors). Even with ramping, though, the top error-free speed will vary, depending on the load carried on the Ninja’s platform. The higher the load, the lower the top speed (or the more chance for position errors at high speed).
The Ninja is mechanically very sloppy. This is to say it has a lot of backlash in its linkage from motor to platform. Backlash is most noticeable when reversing direction. The motor has to rotate a little before actual motion resumes. This is called taking up the backlash. The new program incorporates backlash compensation. The amount of backlash present on each axis has been characterized, and changes of direction are given that many extra steps to compensate. These extra steps are incorporated into the entire trajectory and will not normally be noticed. Although a better way is to compensate the backlash before beginning the programmed trajectory, thus making the trajectory itself correct from start to finish, the Ninja’s simpler way still allows the endpoints to be correct.
The Y (altitude) backlash cannot be entirely compensated out. The reason is the platform’s high center of gravity. With a moderate to heavy load, the Y axis will appear to have no backlash – until it passes it’s top equilibrium point. There the load will cause the platform to “flop over the center” all at once, then continue with no further backlash in evidence. The Y axis, however, seems to be much tighter than the X axis, so this phenomenon is not very pronounced.