Super-cool panorama Phil! I bet a lot of people would be interested in your project just as a way to make such nice panoramas with an ordinary camera. What software did you use to do the stitching?
Anyway, as I said, I rewrite these functions from some Windows code I wrote, and I didn’t actually test my speed function on an Arduino (or otherwise, for which there is no excuse!), and while it does technically work as written, there are a couple of minor things wrong with it.
First off, I do have the speed settings backwards in my comments. 0 is no speed limiting, but 1 is the slowest possible servo motion, with 127 being the fastest. Something to keep in mind is that most servos won’t be able to keep up with the faster speeds anyway. I’m testing this on an old junker Hobbico servo, and it maxes out at about 45, so any setting above 45 just moves at the servo’s max speed.
You’re using those Servo City down-gearing boxes, so your max speed is going to be even lower than with just the servo alone. Maybe in the 1-10 range. Now, you thought you were using the slowest speed, but the last command in your test code loop ends by putting the servo back to 5000 at speed 127, the fastest limited speed possible. When the loop repeats, your first command drives the servo to 5000 at speed 10, which you might actually be able to see, but the servo is already at position 5000 so it doesn’t go anywhere!
I also do a check to clear the highest bit of the input number, just in case you try to put in like 255 or something, but the code as written doesn’t actually use that new variable! Come to think of it, I have a lot of variables declared as integers, when they really only need to be characters, and sending the commands byte by byte the buffers are really unnecessary (It made much more sense to write it this way in Windows). Also, I’m compiling this in Arduino for the first time, and “speed” seems to be some sort of reserved variable name (it turns maroon in the editor). I don’t know what it does, and while it seems to work, I should name it something else just to be on the safe side.
So, the Arduino-safe (and now tested!), and less memory hogging servo control functions would look like this:
void put(unsigned char servo, unsigned int angle){
//servo is the servo number (typically 0-7)
//angle is the absolute position from 500 to 5500
//Send a Pololu Protocol command
Serial.print(0x80,BYTE); //start byte
Serial.print(0x01,BYTE); //device id
Serial.print(0x04,BYTE); //command number
Serial.print(servo,BYTE); //servo number
//Convert the angle data into two 7-bit bytes
Serial.print(((angle>>7)&0x3f),BYTE); //data1
Serial.print((angle&0x7f),BYTE); //data2
}
void servoOff(unsigned char servo){//turns off a servo
//(servo will go limp until next position command)
//servo is the servo number (typically 0-7)
//Send a Pololu Protocol command
Serial.print(0x80,BYTE);//start byte
Serial.print(0x01,BYTE);//device id
Serial.print(0x00,BYTE);//command number
Serial.print(servo,BYTE);//servo number
Serial.print(0x0f,BYTE);//data1 (turn servo off, keep full range)
}
void servoSetSpeed(unsigned char servo, unsigned char speedcmd){
//servo is the servo number (typically 0-7)
//speed is servo speed (1=slowest, 127=fastest)
//set speed to zero to turn off speed limiting
speedcmd=speedcmd&0x7f;//take only lower 7 bits of the speed
//Send a Pololu Protocol command
Serial.print(0x80,BYTE);//start byte
Serial.print(0x01,BYTE);//device id
Serial.print(0x01,BYTE);//command number
Serial.print(servo,BYTE);//servo number
Serial.print(speedcmd,BYTE);//data1
}
I hope Zagrophyte is still watching this thread!
-Adam
P.S. Aptly named, and intentionally or not, Arduino is Italian, and translates as “a little arduous.” Only a little! Actually I’m not sure that it’s proper to apply the -ino suffix to an adjective, like arduo, but it is funny!