Wednesday, November 27, 2013

Preliminary tests of Parallax Servos and Glove-Mounted Flex Sensors

5 Parallax standard servos arrived today in the mail. They are quite large compared to the servos that came with the Sparkfun kit:

Left: Parallax servo; Right: SparkFun servo
The servo is both larger and stronger, with a torque about 2 to 3 times that of the SparkFun servo, so it should meet our needs nicely.

http://parallax.com/product/900-00005

I began to hook it up to the breadboard to begin testing them but ran into a bit of a snag. For whatever reason, the servos weren't working. I had the 5V and GND from the Arduino hooked up into the positive and negative rails of the breadboard, respectively. Then I attached the red, white, and black leads of the servo (just like the ones in the Sparkfun kits) to the power rail, ground rail, and digital PWM pin-out.

Next I tried plugging the servo directly into the 5V and GND pin of the Arduino. This worked! However, the problem it posed was that only one Arduino could power one servo motor at a time.

I spent the next hour or so troubleshooting and scouring the internet for answers. No luck. At last, I tried using hookup wire instead of the breadboard wires that came with the Sparkfun kit. This finally worked. I was even able to run two servos at once from the same power/ground rail with more hookup wire.

After this debacle, I wrote some quick code to test out the flex sensor's ability to rotate the servo when mounted on the glove. The servos get jittery once more than one servo is powered and grounded to the same rail, but overall, they are able to run independently. One discovery I made was that the 600-900 analog value for the flex sensors that was recommended in the SIK Guide code isn't far too much. What ended up happening was that the flex sensor was only bouncing between 690 and 800, which when mapped to a servo's angle position of 0 to 180, would only give me from about 70 to 110. I wanted full rotation, so what I did instead was have the "map" function convert flex sensor values from around 675 to 800 to the servo angles of 0 to 180. This way, I got a much broader angular range for the servo. I've included the code to show what I mean:

// Dat Le - Team Master Hand
// Code for testing two servos with glove-mounted flex sensors
#include <Servo.h> // Include the Arduino Servo library
// ===================================================
// ===================================================
// Global Variables
Servo servo1; // Name two servos
Servo servo2;
const int flex1Pin = 0; // Analog input pins 0 and 1 used for the flex sensors
const int flex2Pin = 1;
const int servo1Pin = 9; // Digital PWM pins 9 and 10 used for the servos
const int servo2Pin = 10;
int flex1Val = 0; // Variables to store flex sensor value
int flex2Val = 0;
int servo1Val = 0; // Variables to store servo angle value
int servo2Val = 0;
// ===================================================
// ===================================================
// Setup
void setup()
{
servo1.attach(servo1Pin); // Attach servos to the digital PWM pins
servo2.attach(servo2Pin);
pinMode(flex1Pin, INPUT); // Establish analog pins for flex sensors
pinMode(flex2Pin, INPUT); // as inputs
Serial.begin(9600); // Set up the serial monitor for debugging
}
// ===================================================
// ===================================================
// Loop
void loop()
{
flex1Val = analogRead(flex1Pin); // Read the value of the flex sensor
flex2Val = analogRead(flex2Pin); // into the respective variables
servo1Val = map(flex1Val, 675, 800, 0, 180); // Map the flex sensor value
servo2Val = map(flex2Val, 675, 800, 0, 180); // to a servo angle
servo1.write(servo1Val); // Tell the servo to move to that position
servo2.write(servo2Val);
delay(100); // Add a delay
Serial.print("Flex 1: "); // Print the individual flex sensor and
Serial.print(flex1Val); // servo angle values in the monitor
Serial.print(" Servo 1: ");
Serial.print(servo1Val);
Serial.print(" Flex 2: ");
Serial.print(flex2Val);
Serial.print(" Servo 2: ");
Serial.println(servo2Val);
}

Perhaps more quality flex sensors would utilize the entire 600 to 900 range, but that's not the case with these flex sensors. Adjusting the range to 675 to 800 will allow for much greater range of motion for the servo. The video shown below uses this updated range for the flex sensor mapping to the servo angle, in addition to using the flex sensor on the glove mount for one servo.


Of course, this is with the flex sensor and the servo attached to the same breadboard and Arduino. Our challenge arises in separating this system into two by utilizing the RF transmitter and receiver, which is the last big challenge for this project.

-Dat

No comments:

Post a Comment