Changeset 14778 for firmware


Ignore:
Timestamp:
01/17/13 16:54:13 (12 years ago)
Author:
boccone
Message:
trying to release current and position contrain to solve the non-closing issue of the last days
File:
1 edited

Legend:

Unmodified
Added
Removed
  • firmware/ShutterController/ShutterController.ino

    r14359 r14778  
    2323// Define MAC and IP addresses
    2424byte _mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x5C, 0x91 };
    25 
     25//byte _mac[] = { 0x80, 0x49, 0x71, 0x0f, 0x80, 0xd0 };
    2626#if !defined USE_DHCP_FOR_IP_ADDRESS
    2727// ip represents the fixed IP address to use if DHCP is disabled.
     
    3434// pushing coefficient ~100 Kg/A
    3535const double _ZeroCurrent         PROGMEM = 0.25; // [A]
    36 const double _CurrentPushingLimit PROGMEM = 0.70; // 0.7-0.5 = 0.2 -> 20  +/- 5 kg
     36const double _CurrentPushingLimit PROGMEM = 0.75; // 0.7-0.5 = 0.2 -> 20  +/- 5 kg
    3737const double _OverCurrent         PROGMEM = 1.50; // 1.5-0.5 = 1   -> 100 +/- 5 kg
    3838
     
    4040const int _StartPointLimit =    70;
    4141const int _EndPoint        =  1024;
    42 const int _EndPointLimit   =   740;
     42const int _EndPointLimit   =   775; // This must me 740 for the mockup and >770 for the FACT shutter
    4343
    4444// Define Lid Status levels and labels
     
    138138                                    "<button name=\"Button6\" value=\"valueButton6\" type=\"submit\">Close Lid</button><p/>"
    139139                                    "<span id=\"cur1\" value=\"\002\"> Motor Current 1 = \002 A </span><p/><span id=\"cur2\" value=\"\002\"> Motor Current 2 = \002 A </span><p/>"
    140                                     "<span id=\"pos1\" value=\"\002\"> Hall Sensor 1 = \002 ADC ounts </span><p/><span id=\"pos2\" valus=\"\002\"> Hall Sensor 2 = \002 ADC counts</span><p/>"
     140                                    "<span id=\"pos1\" value=\"\002\"> Hall Sensor 1 = \002 ADC counts </span><p/><span id=\"pos2\" value=\"\002\"> Hall Sensor 2 = \002 ADC counts</span><p/>"
    141141                                    "</form></p>";
    142142                                    //<br/></body></html>
     
    277277  Serial.println(Ethernet.localIP());
    278278 
    279  // Serial.print("Gateway IP address is ");
    280  // Serial.println(ip_to_str(gatewayAddr));
    281  
    282  // Serial.print("DNS IP address is ");
    283  // Serial.println(ip_to_str(dnsAddr));
    284279
    285280
     
    625620void sendPage(EthernetClient & client, int nUriIndex, BUFFER & requestContent)
    626621{
    627 
     622  // Read Sensor values for every page reload
     623  ReadSensorM(-1,100);
     624  ReadCurrentM(-1,100);
     625 
    628626#ifdef DEBUG
    629627  Serial.print("sendPage(");
     
    957955  double travel;
    958956 
    959    // only one reading to define the position is not sufficient
    960    // current_position = ReadSensor(motor);
    961  
    962    // Calculate average final position
     957  // only one reading to define the position is not sufficient
     958  // current_position = ReadSensor(motor);
     959
     960  // Calculate average final position
    963961  double tmp=0;
    964962  double tmpM=0;
     
    974972  tmpS  = sqrt(tmpS/SAMPLES - tmpM*tmpM);
    975973 
    976   Serial.print(" - The current position of the actuator is ");
    977   Serial.print(tmpM,3);
    978   Serial.print( " +/- " );
    979   Serial.println(tmpS,3);
    980974
    981975  int tmpS_int = (int) tmpS;
     
    991985 
    992986  original_position      = current_position;
    993   err_original_position = err_current_position;
    994  
    995   Serial.print(" - The corrected position of the actuator is ");
    996   Serial.print(current_position);
    997   Serial.print( " +/- " );
    998   Serial.println(err_current_position);
    999  
    1000  
     987  err_original_position  = err_current_position;
     988
    1001989  // calculate the travel needed to reach the target position
    1002990  travel = target_position - current_position;
     
    1009997  Serial.print(target_position,3);
    1010998  Serial.print(" - Travel distance = ");
    1011   Serial.print(travel,3);
     999  Serial.println(travel,3);
     1000
     1001  Serial.print(" - The current position of the actuator is ");
     1002  Serial.print(tmpM,3);
     1003  Serial.print( " +/- " );
     1004  Serial.println(tmpS,3);
     1005
     1006  Serial.print(" - The corrected position of the actuator is ");
     1007  Serial.print(current_position);
     1008  Serial.print( " +/- " );
     1009  Serial.println(err_current_position);
     1010
    10121011 
    10131012  // [IF] the travel is bigger than +2*(absolute position error) try to move out the motor
     
    12231222  Serial.println(_StatusLabel[_LidStatus[motor]]);
    12241223 
    1225   Serial.print("availableMemory()=");
     1224  Serial.print("AvailableMemory()=");
    12261225  Serial.println(availableMemory());
    12271226
     
    12661265  Serial.println("Action->ReadSensorsM()");
    12671266#endif
    1268   _sensorValue[motor]=0;
    12691267  switch (motor){
     1268    case -1: // Read all of them
     1269      _sensorValue[0] = 0;
     1270      _sensorValue[1] = 0;
     1271      for (int j=0;j<samples;j++){
     1272        _sensorValue[0] +=  analogRead(A2);
     1273        _sensorValue[1] +=  analogRead(A3);
     1274      }
     1275      _sensorValue[0]/=samples;
     1276      _sensorValue[1]/=samples;
     1277      return -1;
     1278
    12701279    case 0:
     1280      _sensorValue[motor]=0;
    12711281      for (int j=0;j<samples;j++)
    12721282        _sensorValue[motor] +=  analogRead(A2);//*_ADC2V - _Voffset; //*_Compensation;
     1283      _sensorValue[motor] /= samples;
     1284      return _sensorValue[motor]; // Actuator 1 position
     1285
    12731286    case 1:
     1287      _sensorValue[motor]=0;
    12741288      for (int j=0;j<samples;j++)
    12751289        _sensorValue[motor] +=  analogRead(A3);//*_ADC2V - _Voffset;//_Compensation;
    1276   }
    1277  
    1278   _sensorValue[motor] /= samples;
    1279   return _sensorValue[motor]; // Actuator 1 position
     1290      _sensorValue[motor] /= samples;
     1291      return _sensorValue[motor]; // Actuator 1 position
     1292  }
     1293 
    12801294}
    12811295
     
    13011315
    13021316double ReadCurrentM(int motor,  int samples){
    1303   _currentValue[motor] = 0;
    13041317  switch (motor){
     1318    case -1: // Read all of them
     1319      _currentValue[0] = 0;
     1320      _currentValue[1] = 0;
     1321      for (int j=0;j<samples;j++){
     1322        _currentValue[0] +=  analogRead(A4)*_ADC2V/(_V2A*10.);
     1323        _currentValue[1] +=  analogRead(A5)*_ADC2V/(_V2A*10.);
     1324      }
     1325      _currentValue[0]/=samples;
     1326      _currentValue[1]/=samples;
     1327      return -1;
    13051328    case 0:
     1329      _currentValue[motor] = 0;
    13061330      for (int j=0;j<samples;j++)
    13071331        _currentValue[motor] +=  analogRead(A4)*_ADC2V/(_V2A*10.);       
     1332      _currentValue[motor]/=samples;
     1333      return _currentValue[motor];
    13081334    case 1:
     1335      _currentValue[motor] = 0;
    13091336      for (int j=0;j<samples;j++)
    13101337        _currentValue[motor] +=  analogRead(A5)*_ADC2V/(_V2A*10.);
    1311   }
    1312   _currentValue[motor]/=samples;
    1313   return _currentValue[motor];
     1338      _currentValue[motor]/=samples;
     1339      return _currentValue[motor];
     1340
     1341  }
    13141342
    13151343}
Note: See TracChangeset for help on using the changeset viewer.