Servos

Servos:

.

servoCenters(); servoCenters(); //sets all 3 servos to default positions

This function sets all 3 servos to the default positions. These default positions are defined in the hardware.h tab as the values SERVO_TILT_CENTER, SERVO_PAN_CENTER, and SERVO_GRIP_STOWE.

The default values used by servoCenters() are as follows:

SERVO_TILT_CENTER = 100 SERVO_PAN_CENTER = 90 SERVO_GRIP_STOWE = 10

.

servoTilt(); servoTilt(position); //sets the tilt servo servoTilt(100); //sets the tilt servo to 100 degrees - facing straight forward servoTilt(30); //sets the tilt servo to 30 degrees - facing downward servoTilt(130); //sets the tilt servo to 130 degrees - facing upward

This function sets position of the Tilt servo. The position is generally given in degrees, with larger numbers tilting upward and smaller numbers tilting downward. The accepted range is from 0 to 180, though the software on the PIC processor does limit this to between 10 and 175 to prevent over-driving the servos.

.

servoPan(); servoPan(position); //sets the pan servo servoPan(90); //sets the pan servo to 90 degrees - facing straight forward servoPan(30); //sets the pan servo to 30 degrees - facing left servoPan(150); //sets the pan servo to 150 degrees - facing right

This function sets position of the Pan servo. The position is generally given in degrees, with smaller numbers facing toward the left and larger numbers facing toward the right. The accepted range is from 0 to 180, though the software on the PIC processor does limit this to between 10 and 170 to prevent over-driving the servos.

.

servoGrip();

WARNING: Be careful to avoid over-driving the grip servo. If an object is grasped and you attempt to close the grip servo more tightly, the servo will bind and will draw excessive current. Some minor binding is probably okay, but avoid attempting to close the servo all the way around an object - the servo is intended to lightly grip an object so it may be dragged around the surface. servoGrip(position); //sets the grip servo servoGrip(10); //sets the grip servo to 10 degrees - grippers fully retracted / stowed servoGrip(125); //sets the grip servo to 125 degrees - grippers fully closed

This function sets position of the Grip servo. The position is generally given in degrees, with smaller numbers retracting the grippers, and larger numbers more fully closing the grippers. The accepted range is from 0 to 180, though the software on the PIC processor does limit this to between 10 and 125 to prevent over-driving the servos.

.

servoSpeed(); servoSpeed(speed); //sets servo speed approximately in degrees per second servoSpeed(3000); //maximum servo speed servoSpeed(20); //slow movement of servos

This function sets the speed at which the servos move, approximately in degrees per second. By setting a high value like 3000 servos will move as fast as they are physically capable. Setting lower values of 20 to 90 create smooth movements. Note that servo speed can be adjusted during a movement. All servo speeds are set to the same value.

.

PIC_ServosInMotion(); PIC_ServosInMotion(); //query to see which servos are in motion servosInMotion; //will be not zero if any servos are in motion servoMotion_Tilt; //will be "1" if Tilt servo is in motion, "0" if Tilt servo is not in motion servoMotion_Pan; //will be "1" if Pan servo is in motion, "0" if Pan servo is not in motion servoMotion_Grip; //will be "1" if Grip servo is in motion, "0" if Grip servo is not in motion

Because servos can be set to move in slow speeds, it may be useful to determine when a given servo has reached its target setpoint. This function can be used for this purpose. After starting a servo movement you can call this function to determine when some or all servos have reached their stopping positions.

Important Notes:

  • This function will indicate the servo has stopped when the PIC processor is sending the signal corresponding to the intended end point, but the servo itself may not have actually physically reached this point yet, especially if servo speed is set high. This function is mainly intended to be used to determine when servos set at slower speeds have reached their stopping positions.

  • Calling PIC functions in very fast loops may cause problems. It is suggested to delay 2 to 5 milliseconds using code like delay(5); between repeated calls to this function.

.

gripGrasp(); gripGrasp(threshold); //Causes grip servo to grasp an object gripGrasp(30); //Very sensitive grasp gripGrasp(250); //Very firm grasp

This is an experimental function intended to cause the gripper to close around an object, and stop moving when the gripper has grasped the object. It generally works okay. A few warnings and explanations will help you use the function. The gripper arms and servo don't have sensors to tell us when they reach an object. However, when the servo does reach an object, it begins to draw much more current because of the resistance. We can measure the current being drawn by the entire robot and look for spikes to this current, and use those spikes to guess whether a servo may have reached an object. But this is easier said than done, as each small movement of the servo does draw a large spike of current. When the servo reaches an object, these spikes will be larger and more consistent. This function attempts to measure this automatically.

  • The threshold value given is the average current increase in milliamps that the function is looking for. Making the threshold very low will cause the grippers to stop moving before touching an object, and making the threshold too high will make the grippers hold too tightly to the object and cause binding of the servo.

  • This function accepts threshold values between 0 and 250.

  • If the grip servo continues to buzz after grabbing an object, you may wish to back off the position some after the grip completes. You can determine the position the servo stopped by reading the global variable servoPos_Grip which will have the last commanded position stored. You can then use code like servoGrip(servoPos_Grip - 2); to cause the grip servo to back off 2 degrees from its last stopping point.

  • This function automatically moves the grip 2 degrees at a time and evaluates the current draw between movements.

  • It is best to run this function with motors stopped and other servos stopped, as the current drain spikes from these other sources may confuse the readings of this function. It is also advised to turn off most or all of the NeoPixels while this function runs. Even NeoPixels turned on a low settings will cause current pulses that may interfere.

  • If you're more advanced - you can find this function in the Hardware tab. Feel free to play with it or use as a basis for your own custom implementation.

.

Servo Trim:

Serovs may differ somewhat and even when properly assembled, you may notice servoCenters() doesn't exactly center some of the servos. For this reason, the PIC processor has a trim setting for each servo, where you can lock in a small offset so the servos center to their correct positions and other relative movements from these positions are more accurate.

The Arduino processor has a small permanent memory called EEPROM where it stores the last trim values used. It is only necessary to set these trim values one time in any of your sketch programs and the trim value will be stored. From that point forward, you can use any skets program and the previously set trim values will still be used.

To adjust the servo trim, edit the trim values. You can find these at the top of the Hardware tab.

volatile signed char servoTrim_Tilt =25 ; //Tilt servo trim (-127 to +127) volatile signed char servoTrim_Pan =0 ; //Pan servo trim (-127 to +127) volatile signed char servoTrim_Grip =-1 ; //Grip servo trim (-127 to +127)

These are the values that set trim for each servo. Setting the value to anything other than zero will cause the value to be stored in memory. This value will remain even after loss of power or re-programming with a new sketch. Do some trial and error with these values until you get your servos trimmed. If you want to zero out the trim, you need to use a value other than actual zero as that value is ignored - instead set a given trim to -1, which is very close to zero and the program will still update it as expected.

To manually set the servo trims, you can call the following functions:

servoTilt_Trim(trimValue); // send trim value for servo servoPan_Trim(trimValue); // send trim value for servo servoGrip_Trim(trimValue); // send trim value for servo

  • These functions accept values between -127 and 127.

  • Calling these functions will not update the EEPROM memory so you can experiment without altering the stored value.

  • If you're more advanced - you can study the function setServoTrim() in the Hardware tab. This function handles the EEPROM storage and query functionality as well.

.

Last updated