Haptic Glove: Difference between revisions
Jump to navigation
Jump to search
| Line 19: | Line 19: | ||
[[Image:HapticGlovev0.jpg|500px]] |
[[Image:HapticGlovev0.jpg|500px]] |
||
==Source code== |
|||
<pre> |
|||
/* |
|||
Haptic Glove |
|||
Reads 15 bytes that encode the level and the delay of the 5 vibration motors connected to the Arduino' PWM pins |
|||
Vibration Motor, sku: ROB-08449 |
|||
http://www.sparkfun.com/products/8449 |
|||
http://www.sparkfun.com/products/8468 |
|||
"With a 2-3.6V operating range, these units shake crazily at 3V" |
|||
Septembre 18, 2011 by Didier Donsez |
|||
This example code is in the public domain. |
|||
Test by sending the following inputs with the serial monitor |
|||
909000000000000 |
|||
000909000000000 |
|||
000000909000000 |
|||
000000000909000 |
|||
000000000000909 |
|||
909909909909909 |
|||
901903905907909 |
|||
*/ |
|||
const int MAXVIB=180; // 180 is 3.6V if Vin is 5V (Arduino Uno) |
|||
const int COEF=100; // Coeficient for delay |
|||
const int NUMVIB=5; // Number of vibration motors (one per finger) |
|||
byte levelVib[NUMVIB]; // Level for vibration |
|||
byte levelEndVib[NUMVIB]; // Level for vibration after the delay |
|||
byte delayVib[NUMVIB]; // Delay for vibration |
|||
byte pinVib[NUMVIB] = {3, 5, 6, 10, 11 }; // Analog output pins that the vibration motors are attached to |
|||
void setup() { |
|||
// initialize serial communications at 9600 bps: |
|||
Serial.begin(9600); |
|||
} |
|||
void loop() { |
|||
// TODO eliminate LF and CR |
|||
if (Serial.available() >=(NUMVIB*3)) { |
|||
for (int i=0; i<NUMVIB; i++) { |
|||
levelVib[i]=convert(Serial.read()); |
|||
if(levelVib[i]>MAXVIB) { |
|||
levelVib[i]=MAXVIB; // protect the motor |
|||
} |
|||
levelEndVib[i]=convert(Serial.read()); |
|||
if(levelEndVib[i]>MAXVIB) { |
|||
levelEndVib[i]=MAXVIB; // protect the motor |
|||
} |
|||
delayVib[i]= Serial.read(); |
|||
if(levelVib[i]==0) { |
|||
delayVib[i]=0; |
|||
} |
|||
} |
|||
//Serial.println("vibrating ..."); |
|||
for (int j=0; j<NUMVIB; j++) { |
|||
// calculate next delay |
|||
byte minDelay=0xFF; |
|||
byte cpt=0; |
|||
for (int i=0; i<NUMVIB; i++) { |
|||
if(delayVib[i]>0 && delayVib[i]<minDelay) { |
|||
minDelay=delayVib[i]; |
|||
cpt++; |
|||
} |
|||
} |
|||
if(cpt==0) { |
|||
return; |
|||
} |
|||
if(j==0){ |
|||
for (int i=0; i<NUMVIB; i++) { |
|||
if(levelVib[i]>0) { |
|||
analogWrite(pinVib[i], levelVib[i]); |
|||
} |
|||
} |
|||
} |
|||
//Serial.print("wait "); Serial.println(minDelay*COEF); |
|||
delay(minDelay*COEF); |
|||
for (int i=0; i<NUMVIB; i++) { |
|||
if(delayVib[i]!=0) { |
|||
delayVib[i]-=minDelay; |
|||
} |
|||
if(delayVib[i]==0 && levelVib[i]>0) { |
|||
analogWrite(pinVib[i], levelEndVib[i]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
byte convert(byte b) { |
|||
if(b>='0' && b<='9') { |
|||
return (b-'0')<<4; |
|||
} else if(b>='A' && b<='F') { |
|||
return (b-'A'+10)<<4; |
|||
} else return 0; |
|||
} |
|||
</pre> |
|||
Revision as of 15:06, 21 September 2011
- UE/Module: Projet IHM Avancé de RICM5
- Enseignant: Didier Donsez
- Elèves RICM4: Christophe Havard (chef de projet), Renaud Collin
Introduction
La perception haptique est désormais présente dans les applications mobiles, ...
Ce projet vise à réaliser un gant à perception haptique pour des applications tactiles (écrans larges, ...)
Objectifs
Matériel
- Arduino Uno ou Lilypad
- 5 Vibration motors
- 1 Flex sensor
Source code
/*
Haptic Glove
Reads 15 bytes that encode the level and the delay of the 5 vibration motors connected to the Arduino' PWM pins
Vibration Motor, sku: ROB-08449
http://www.sparkfun.com/products/8449
http://www.sparkfun.com/products/8468
"With a 2-3.6V operating range, these units shake crazily at 3V"
Septembre 18, 2011 by Didier Donsez
This example code is in the public domain.
Test by sending the following inputs with the serial monitor
909000000000000
000909000000000
000000909000000
000000000909000
000000000000909
909909909909909
901903905907909
*/
const int MAXVIB=180; // 180 is 3.6V if Vin is 5V (Arduino Uno)
const int COEF=100; // Coeficient for delay
const int NUMVIB=5; // Number of vibration motors (one per finger)
byte levelVib[NUMVIB]; // Level for vibration
byte levelEndVib[NUMVIB]; // Level for vibration after the delay
byte delayVib[NUMVIB]; // Delay for vibration
byte pinVib[NUMVIB] = {3, 5, 6, 10, 11 }; // Analog output pins that the vibration motors are attached to
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// TODO eliminate LF and CR
if (Serial.available() >=(NUMVIB*3)) {
for (int i=0; i<NUMVIB; i++) {
levelVib[i]=convert(Serial.read());
if(levelVib[i]>MAXVIB) {
levelVib[i]=MAXVIB; // protect the motor
}
levelEndVib[i]=convert(Serial.read());
if(levelEndVib[i]>MAXVIB) {
levelEndVib[i]=MAXVIB; // protect the motor
}
delayVib[i]= Serial.read();
if(levelVib[i]==0) {
delayVib[i]=0;
}
}
//Serial.println("vibrating ...");
for (int j=0; j<NUMVIB; j++) {
// calculate next delay
byte minDelay=0xFF;
byte cpt=0;
for (int i=0; i<NUMVIB; i++) {
if(delayVib[i]>0 && delayVib[i]<minDelay) {
minDelay=delayVib[i];
cpt++;
}
}
if(cpt==0) {
return;
}
if(j==0){
for (int i=0; i<NUMVIB; i++) {
if(levelVib[i]>0) {
analogWrite(pinVib[i], levelVib[i]);
}
}
}
//Serial.print("wait "); Serial.println(minDelay*COEF);
delay(minDelay*COEF);
for (int i=0; i<NUMVIB; i++) {
if(delayVib[i]!=0) {
delayVib[i]-=minDelay;
}
if(delayVib[i]==0 && levelVib[i]>0) {
analogWrite(pinVib[i], levelEndVib[i]);
}
}
}
}
}
byte convert(byte b) {
if(b>='0' && b<='9') {
return (b-'0')<<4;
} else if(b>='A' && b<='F') {
return (b-'A'+10)<<4;
} else return 0;
}