Skip to content

Instantly share code, notes, and snippets.

@blueintegral
Created August 18, 2013 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blueintegral/6263391 to your computer and use it in GitHub Desktop.
Save blueintegral/6263391 to your computer and use it in GitHub Desktop.
Hardcoded value version of DIY CyberGlove Arduino code
float analog0;
float analog1;
float analog2;
float analog3;
float analog0_close;
float analog1_close;
float analog2_close;
float analog3_close;
float analog0_open;
float analog1_open;
float analog2_open;
float analog3_open;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Using hardcoded max and min");
}
// the loop routine runs over and over again forever:
void loop() {
analog0 = analogRead(A0);
analog1 = analogRead(A1);
analog2 = analogRead(A2);
analog3 = analogRead(A3);
//Scale the values to a range of [0,1]
float scaled_thumb = (analog0 - 854.00)/(920.00 - 854.00);
float scaled_point = (analog1 - 860.00)/(923.00 - 860.00);
float scaled_middle = (analog2 - 862.00)/(913.00 - 862.00);
float scaled_ring = (analog3 - 848.00)/(902.00 - 848.00);
if(scaled_thumb < 0.00){
scaled_thumb = 0.00;
}
if(scaled_point < 0.00){
scaled_point = 0.00;
}
if(scaled_middle < 0.00){
scaled_middle = 0.00;
}
if(scaled_ring < 0.00){
scaled_ring = 0.00;
}
// Serial.print("Thumb: ");
// Serial.print(scaled_thumb);
// Serial.print(" Point: ");
// Serial.print(scaled_point);
// Serial.print(" Middle: ");
// Serial.print(scaled_middle);
// Serial.print(" Ring: ");
// Serial.println(scaled_ring);
//Print the grasp command
Serial.print("rosservice call /sandia_hands/l_hand/simple_grasp ' { grasp: { name: \"spherical\", closed_amount: ");
Serial.print(scaled_point);
Serial.println("} }'");
//Right now, this just uses the pointer to control the amount that the grasp moves. There exists a path for doing indivudual finger control, but I can't
//get ros to behave enough to let me use that yet.
delay(2000); // 2 second delay between commands so we don't flood the robot with requests. My computer will die...
// delay(1); // delay in between reads for stability. Use this for debugging
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment