Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C Arduino fsr保留价值_C_Arduino_Sensors_Arduino Ide - Fatal编程技术网

C Arduino fsr保留价值

C Arduino fsr保留价值,c,arduino,sensors,arduino-ide,C,Arduino,Sensors,Arduino Ide,嗨,我正在做一个项目,使用arduino uno的力传感器。我遇到的问题是,当我在传感器上施力时,它显示值,但当我停止施力时,它仍然显示相同的值,而不是0。当我用不同的力施加它时,该值将相应地改变,但当我停止施加力时,它仍然不会为0。请帮忙 int iForceSensorReading; // the analog reading from the FSR resistor divider int iForceSensorReading1; int iForce

嗨,我正在做一个项目,使用arduino uno的力传感器。我遇到的问题是,当我在传感器上施力时,它显示值,但当我停止施力时,它仍然显示相同的值,而不是0。当我用不同的力施加它时,该值将相应地改变,但当我停止施加力时,它仍然不会为0。请帮忙

    int iForceSensorReading;     // the analog reading from the FSR resistor divider
    int iForceSensorReading1;
    int iForceSensorReading2;
    int iForceSensorReading3;
    int iForceSensorReading4;
    int iForceSensorVoltage;     // the analog reading converted to voltage
    int iForceSensorVoltage1;
    int iForceSensorVoltage2;
    int iForceSensorVoltage3;
    int iForceSensorVoltage4;
    unsigned long ulForceSensorResistance;// The voltage converted to resistance, can be         very big so make "long"
    unsigned long ulForceSensorResistance1;
    unsigned long ulForceSensorResistance2;
    unsigned long ulForceSensorResistance3;
    unsigned long ulForceSensorResistance4;
    unsigned long ulForceSensorConductance;
    unsigned long ulForceSensorConductance1;
    unsigned long ulForceSensorConductance2;
    unsigned long ulForceSensorConductance3;
    unsigned long ulForceSensorConductance4;
    float FsrForce = 0;       // Resistance converted to force
    float FsrForce1 = 0;
    float FsrForce2 = 0;
    float FsrForce3 = 0; 
    float FsrForce4 = 0;
    void setup(void){
      Serial.begin(9600);   // send debugging information via the Serial monitor
    }
    void loop(void){
      iForceSensorReading = analogRead(A0);//read index finger pressure
      delay(30);
      // analog voltage reading ranges from about 0 to 1023 which maps to 0V to 5V (=         5000mV)
      iForceSensorVoltage = map(iForceSensorReading, 0, 1023, 0, 5000);
      if (iForceSensorVoltage == 0){
        Serial.println("No pressure at index finger");  
      } 
      else{
      ulForceSensorConductance = conductanceFunction(ulForceSensorResistance,         iForceSensorVoltage);
      delay(30);
      } 
      if (ulForceSensorConductance <= 1000){
        FsrForce = ulForceSensorConductance / 80;
        Serial.print("Force applied by index finger in Newtons: ");
        Serial.println(FsrForce, 4);      
        } 
      else{
        FsrForce = ulForceSensorConductance - 1000;
        FsrForce /= 30;
        Serial.print("Force applied by index finger in Newtons: ");
        Serial.println(FsrForce, 4);
        delay(30);
        }
      Serial.println("-------------------------------------------------------");
      iForceSensorReading1 = analogRead(A1);//read middle finger pressure
      delay(30);
      iForceSensorVoltage1 = map(iForceSensorReading1, 0, 1023, 0, 5000);
      if (iForceSensorVoltage1 == 0){
        Serial.println("No pressure at middle finger");  
      } 
      else{
      ulForceSensorConductance1 = conductanceFunction(ulForceSensorResistance1,         iForceSensorVoltage1);
        delay(30);
    }
      if (ulForceSensorConductance1 <= 1000){
        FsrForce1 = ulForceSensorConductance1 / 80;
        Serial.print("Force applied by middle finger in Newtons: ");
        Serial.println(FsrForce1, 4);      
        } 
      else{
       FsrForce1 = ulForceSensorConductance1 - 1000;
       FsrForce1 /= 30;
       Serial.print("Force applied by middle finger in Newtons: ");
       Serial.println(FsrForce1, 4);
      delay(30);     
       }
      Serial.println("-------------------------------------------------------");
      iForceSensorReading2 = analogRead(A2);// read ring finger pressure
      delay(30);
      iForceSensorVoltage2 = map(iForceSensorReading2, 0, 1023, 0, 5000);
      if (iForceSensorVoltage2 == 0){
        Serial.println("No pressure at ring finger");  
      } 
      else{
      ulForceSensorConductance2 = conductanceFunction(ulForceSensorResistance2,         iForceSensorVoltage2);
        delay(30);
      } 
      if (ulForceSensorConductance2 <= 1000){
          FsrForce2 = ulForceSensorConductance2 / 80;
          Serial.print("Force applied by ring finger in Newtons: ");
          Serial.println(FsrForce2, 4);      
      }
      else{
          FsrForce2 = ulForceSensorConductance2 - 1000;
          FsrForce2 /= 30;
          Serial.print("Force applied by ring finger in Newtons: ");
          Serial.println(FsrForce2, 4);
          delay(30);      
      }
      Serial.println("-------------------------------------------------------");
      iForceSensorReading3 = analogRead(A3);//read little finger pressure
      delay(30);
      iForceSensorVoltage3 = map(iForceSensorReading3, 0, 1023, 0, 5000);
      if (iForceSensorVoltage3 == 0) 
      {Serial.println("No pressure at little finger");  
      }else {
      ulForceSensorConductance3 = conductanceFunction(ulForceSensorResistance3,         iForceSensorVoltage3);
        delay(30);
      } 
      if (ulForceSensorConductance3 <= 1000) 
      {FsrForce3 = ulForceSensorConductance3 / 80;
       Serial.print("Force applied by little finger in Newtons: ");
       Serial.println(FsrForce3, 4);      
      }else 
      {
       FsrForce3 = ulForceSensorConductance3 - 1000;
       FsrForce3 /= 30;
       Serial.print("Force applied by little finger in Newtons: ");
       Serial.println(FsrForce3, 4);
       delay(30);      
      }
       Serial.println("-------------------------------------------------------");
      iForceSensorReading4 = analogRead(A4);//read thumb pressure
      delay(30);
      iForceSensorVoltage4 = map(iForceSensorReading4, 0, 1023, 0, 5000);
      if (iForceSensorVoltage4 == 0) 
      {Serial.println("No pressure at thumb");  
      } 
      else 
      {
      ulForceSensorConductance4 = conductanceFunction(ulForceSensorResistance4,         iForceSensorVoltage4);
        delay(30);
      } 
      if (ulForceSensorConductance4 <= 1000) 
      {FsrForce4 = ulForceSensorConductance4 / 80;
       Serial.print("Force applied by thumb in Newtons: ");
       Serial.println(FsrForce4, 4);      
      } 
      else 
      {
       FsrForce4 = ulForceSensorConductance4 - 1000;
       FsrForce4 /= 30;
       Serial.print("Force applied by thumb in Newtons: ");
       Serial.println(FsrForce4, 4);
       delay(30);      
       }
      Serial.println("-------------------------------------------------------");
      float totalForce = FsrForce + FsrForce1 + FsrForce2 + FsrForce3;// total force         applied by hand
      Serial.print("Total force applied by hand: ");
      Serial.println(totalForce, 4);
      delay(30);
      Serial.println("-------------------------------------------------------");
      delay(3000);
    }
    // The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
    // so FSR = ((Vcc - V) * R) / V  
    int conductanceFunction(long x, long y)
    {long result;
     x = 5000 - y; // fsrVoltage is in millivolts so 5V = 5000mV
     x *= 10000; // 10K resistor
     x /= y;
     result = 1000000/x; //ulForceSensorConductance2 = 1000000 measured in micromhos
     return result;
    }
int-iforcessensorreading;//来自FSR电阻分压器的模拟读数
int iForceSensorReading1;
int iForceSensor读数2;
int-IFORCESENSERREADING3;
int IFORCESENSOR读数4;
int iForcessensor电压;//模拟读数转换为电压
int-iForceSensor电压1;
int-iForceSensorVoltage2;
int-iForceSensorVoltage3;
int-iForceSensorVoltage4;
无符号长UlforCeSensor电阻;//转换为电阻的电压可能非常大,因此使“长”
无符号长ULF传感器电阻1;
无符号长ULF传感器电阻2;
无符号长ULF传感器电阻3;
无符号长ULF传感器电阻4;
无符号长ULF传感器电导;
无符号长ULF传感器电导1;
无符号长ULF传感器电导2;
无符号长ULF传感器电导3;
无符号长ULF传感器电导4;
浮点FsrForce=0;//转化为武力的抵抗
浮点数FsrForce1=0;
浮点数FsrForce2=0;
浮点数FsrForce3=0;
浮点数FsrForce4=0;
作废设置(作废){
Serial.begin(9600);//通过串行监视器发送调试信息
}
无效循环(无效){
iForceSensorReading=analogRead(A0);//读取食指压力
延误(30);
//模拟电压读数范围约为0至1023,对应于0V至5V(=5000mV)
IforceSensor电压=map(IforceSensor读数,0,1023,0,5000);
如果(IforceSensor电压==0){
Serial.println(“食指无压力”);
} 
否则{
Ulforcessensor电导=电导函数(Ulforcessensor电阻,Iforcessensor电压);
延误(30);
} 
如果(Ulforcessensor)电导首先:

只有当IforceSensor电压不为零时,才更新UlforceSensor电导。当然,我认为很难得到一个完美的零

  if (iForceSensorVoltage == 0){
    Serial.println("No pressure at index finger");  
  } 
  else{
  ulForceSensorConductance = conductanceFunction(ulForceSensorResistance,         iForceSensorVoltage);
  delay(30);
  } 
第二:

我看到ulForceSensorResistance只被初始化,从未实际使用过赋值,而是作为第一个参数传递到conductanceFunction中

unsigned long ulForceSensorResistance1;
...
ulForceSensorConductance1 = conductanceFunction(ulForceSensorResistance1, iForceSensorVoltage1);
...
int conductanceFunction(long x, long y)
{long result;
 x = 5000 - y; // fsrVoltage is in millivolts so 5V = 5000mV