Found time today to play. “Interesting” results.
Here is the “minimal” sketch I created for testing:
#include <PololuMaestro.h>
#ifdef SERIAL_PORT_HARDWARE_OPEN
#define maestroSerial SERIAL_PORT_HARDWARE_OPEN
#else
#include <SoftwareSerial.h>
SoftwareSerial maestroSerial(10, 11);
#endif
MicroMaestro maestro(maestroSerial);
const int channel = 5;
void setup() {
// wait for serial monitor to open
while (!Serial);
Serial.println("Test Maestro baud rate");
// Set the serial baud rate for Maestro
maestroSerial.begin(100000);
maestro.setSpeed(channel, 0); // no speed limit
}
void loop() {
Serial.println("Position @ 5000");
maestro.setAcceleration(channel, 100);
maestro.setTarget(channel, 5000);
waitTarget(channel, 5000);
delay(1000);
maestro.setAcceleration(channel, 0); // no acceleration limit
Serial.println("Start loop");
for (int i = 5010; i < 7010; i+=10) {
maestro.setTarget(channel, i);
Serial.println("set target @ " + (String) i);
// waitTarget(channel, i);
waitTarget2();
Serial.println("got target");
delay(20);
}
}
void waitTarget(uint8_t channel, uint16_t target) {
while (maestro.getPosition(channel) != target) {
}
}
void waitTarget2() {
maestro.restartScript(0);
while (!maestro.getScriptStatus()) {
}
}
The interesting area is the for loop in loop(). After setting the target, note the call to either waitTarget() or waitTarget2(). As you can see from the code, waitTarget() uses the get_position command to wait for the servo to reach the target; waitTarget2() uses the restart_script_at_subroutine command to allow the following script (stolen from the User’s Guide) to wait for the servo to reach the target.
sub wait_for_movement_to_end
begin get_moving_state while repeat
quit
In theory, waitTarget() and waitTarget2() should perform exactly the same function.
Note that in the for loop, speed and acceleration are set to 0. As I understand, that means that once the target for servo is set, from the Maestro perspective, the position of the servo is at the target (since there is no feedback, the actual position cannot be determined). That means that both waitTarget() and waitTarget2() should immediately return, so in truth, both are superfluous.
Now, things get interesting. As you can see, I’ve set the Maestro baud rate to 100,000. When I use waitTarget(), the sketch works! But when I use waitTarget2(), the sketch fails after 20 or so iterations of the for loop! From my perspective, the only difference is the behavior of get_position versus restart_script_at_subroutine.
I’m not really sure what this means. Maybe the restart_script_at_subroutine does not work as I interpret the User’s Guide. Maybe I’m doing something else wrong.
I decided to try 200,000 using waitTarget(). Unfortunately, the sketch does not appear to work at all even in this simple scenario. In the serial monitor window, I see “Position @ 5000” and that is all. Apparently even the get_position command does not work (well) at that speed. Again, I am puzzled.
One more thing that I should add. I’ve had this Maestro for a long time. The firmware is at 1.02. Should I update? I am a bit hesitant to do so because I’m running the Control Center in Windows 8.1 in the Parallels desktop on MacOS. Seems like a recipe for disaster.
Thanks again for any insight you can offer.