wot's this code mean

tomwinter

New member
Yo...

walking through the code, too much of a load, wot's it all mean:

hey - wot does this code do in ardumower:


Code:
// ---- odometry (interrupt) --------------------------------------------------------
// odometryState:  1st left and right odometry signal
// odometryState2: 2nd left and right odometry signal (optional two-wire encoders)
void setOdometryState(unsigned long timeMicros, boolean odometryLeftState, boolean odometryRightState, boolean odometryLeftState2, boolean odometryRightState2){
  if (odometryLeftState != odometryLeftLastState){    
    if (odometryLeftState){
      if (!odometryLeftState2) odometryLeft++; else odometryLeft--; 
    }
    odometryLeftLastState = odometryLeftState;
  } 
  if (odometryRightState != odometryRightLastState){
    if (odometryRightState){
      if (!odometryRightState2) odometryRight++; else odometryRight--;     
    }
    odometryRightLastState = odometryRightState;
  }  
  if (odometryRightState2 != odometryRightLastState2){
    odometryRightLastState2 = odometryRightState2;    
  }  
  if (odometryLeftState2 != odometryLeftLastState2){
    odometryLeftLastState2 = odometryLeftState2;    
  }   
}


pow cheers!

tomDW
 
That helper code determines the rotation count and direction of the odometry encoders. It is called in the odometry pins interrupt.

Have a look here, this is the encoder signal (two wires): http://wiki.ardumower.de/images/e/e2/Ardumower_odometry_encoder.jpg
The logic is:

Code:
If the pin1 change transition (odometryLeftState) is LOW -> HIGH... 
   If the pin2 current state is LOW :  step count forward   (odometryLeft++)
     Otherwise :  step count reverse   (odometryLeft--)
 
Oben