MOW RPM measurement problem

alda

Member
Hello, sorry for English post, but I need help regarding RPM measurement. I have a following code :

Hallo, sorry für englische Post, aber ich brauche Hilfe zur RPM-Messung. Ich habe einen folgenden Code:


Code:
// enable interrupts
  //-----------------------------------------------------------------------------------------------------------------UweZ geändert Anfang---------------------------------
  #ifdef __AVR__
    // R/C
    PCICR |= (1<<PCIE0);
      if (remoteUse==1){                   // überprüfe ob RemoteUse aktiviert ist;
        bitWrite(PCMSK0, PCINT4, HIGH);  // und wenn ja schreibe eine 1 ins PCMSK0 Register4  "XXX1XXXX" Interrupt PCINT4 Register4 entspricht den Pin 10 des Arduino Mega
      }
      else                               // und wenn nicht  
      {
      bitWrite(PCMSK0, PCINT4, LOW);     // dann schreibe eine 0 ins PCMSK0 PCINT4 Register4  "XXX0XXXX"                                           
    }
     //-----------------------------------------------------------------------------------------------------------------  
    if (remoteUse==1){                   // überprüfe ob RemoteUse aktiviert ist;
        bitWrite(PCMSK0, PCINT5, HIGH);  // und wenn ja schreibe eine 1 ins PCMSK0 Register5  "XX1XXXXX" Interrupt PCINT5 Register5 entspricht den Pin 11 des Arduino Mega
      }
      else                               // und wenn nicht  
      {
      bitWrite(PCMSK0, PCINT5, LOW);     // dann schreibe eine 0 ins PCMSK0 PCINT5 Register5  "XX0XXXXX"                                           
    }
    //-----------------------------------------------------------------------------------------------------------------
    if (remoteUse==1){                   // überprüfe ob RemoteUse aktiviert ist;
        bitWrite(PCMSK0, PCINT6, HIGH);  // und wenn ja schreibe eine 1 ins PCMSK0 Register6  "X1XXXXXX" Interrupt PCINT6 Register6 entspricht den Pin 12 des Arduino Mega
      }
      else                               // und wenn nicht  
      {
      bitWrite(PCMSK0, PCINT6, LOW);     // dann schreibe eine 0 ins PCMSK0 PCINT6 Register6  "X0XXXXXX"                                           
    }
    //-----------------------------------------------------------------------------------------------------------------
   if (remoteUse==1){                   // überprüfe ob RemoteUse aktiviert ist;
        bitWrite(PCMSK0, PCINT7, HIGH);  // und wenn ja schreibe eine 1 ins PCMSK0 Register7  "XXXXXX1X" Interrupt PCINT1 Register7 entspricht den Pin 13 des Arduino Mega
      }
      else                               // und wenn nicht  
      {
      bitWrite(PCMSK0, PCINT7, LOW);     // dann schreibe eine 0 ins PCMSK0 PCINT7 Register7  "XXXXXX0X"                                           
    } 
    
   // odometry
    PCICR |= (1<<PCIE2);

    if (odometryUse==1){                  // überprüfe ob die 1 fache Odemetrie aktiviert ist - Links
        bitWrite(PCMSK2, PCINT19, HIGH);  // und wenn ja schreibe eine 1 ins PCMSK2 register0  "XXX1XXXX" Interrupt PCINT19 Register4 entspricht den Pin A11 des Arduino Mega
      }
      else                               // und wenn nicht  
      {
      bitWrite(PCMSK2, PCINT19, LOW);    // dann schreibe eine 0 ins PCMSK2 Register4  "XXX0XXXX"                                           
    }
    //-----------------------------------------------------------------------------------------------------------------
    if (twoWayOdometrySensorUse==1){      // überprüfe ob die twoWayOdometry Odemetrie aktiviert ist - Links
      bitWrite(PCMSK2, PCINT20, HIGH);    // und wenn ja schreibe eine 1 ins PCMSK2 register1  "XX1XXXXX" Interrupt PCINT20 Register5 entspricht den Pin A12 des Arduino Mega
    }
      else                               // und wenn nicht 
      {
      bitWrite(PCMSK2, PCINT20, LOW);     // dann schreibe eine 0 ins PCMSK2 register5  "XX0XXXXX"                                          
    }
    //-----------------------------------------------------------------------------------------------------------------   
     if (odometryUse==1){                 // überprüfe ob die 1 fache Odemetrie aktiviert ist - Rechts
        bitWrite(PCMSK2, PCINT21, HIGH);  // und wenn ja schreibe eine 1 ins PCMSK2 register2  "X1XXXXXX" Interrupt PCINT21 Register6 entspricht den Pin A13 des Arduino Mega
      }
      else                               // und wenn nicht  
      {
      bitWrite(PCMSK2, PCINT21, LOW);     // dann schreibe eine 0 ins PCMSK2 Register6  "X0XXXXXX"                                           
    }
    //-----------------------------------------------------------------------------------------------------------------

    if (twoWayOdometrySensorUse==1){      // überprüfe ob die twoWayOdometry Odemetrie aktiviert ist - Rechts
      bitWrite(PCMSK2, PCINT22, HIGH);    // und wenn ja schreibe eine 1 ins PCMSK2 Register7  "1XXXXXXX" Interrupt PCINT22 Register7 entspricht den Pin A14 des Arduino Mega
    }
      else                               // und wenn nicht 
      {
      bitWrite(PCMSK2, PCINT22, LOW);     // dann schreibe eine 0 ins PCMSK2 Register7  "0XXXXXXX"                                          
    }
    
    // mower motor speed sensor interrupt
    //attachInterrupt(5, rpm_interrupt, CHANGE);
    //-----------------------------------------------------------------------------------------------------------------   Geändert von PCMSK2 |= (1<<PCINT19);
     if (motorMowModulate==1){            // überprüfe ob die motorMowModulate aktiviert ist;
        bitWrite(PCMSK2, PCINT18, HIGH);  // und wenn ja schreibe eine 1 ins PCMSK2 Register3  "XXXX1XXX" Interrupt PCINT18 Register3 entspricht den Pin A10 des Arduino Mega
      }
      else                               // und wenn nicht 
      {
      bitWrite(PCMSK2, PCINT18, LOW);     // dann schreibe eine 0 ins PCMSK2 Register3  "XXXX0XXX"                                  
    }
    //-----------------------------------------------------------------------------------------------------------------UweZ geändert Ende-----------------------------------
  #else
    // Due interrupts
    attachInterrupt(pinOdometryLeft, PCINT2_vect, CHANGE);
    attachInterrupt(pinOdometryLeft2, PCINT2_vect, CHANGE);
    attachInterrupt(pinOdometryRight, PCINT2_vect, CHANGE);    
    attachInterrupt(pinOdometryRight2, PCINT2_vect, CHANGE);            
    
    attachInterrupt(pinRemoteSpeed, PCINT0_vect, CHANGE);            
    attachInterrupt(pinRemoteSteer, PCINT0_vect, CHANGE);            
    attachInterrupt(pinRemoteMow, PCINT0_vect, CHANGE);   
    attachInterrupt(pinRemoteSwitch, PCINT0_vect, CHANGE);       
    
    //attachInterrupt(pinMotorMowRpm, rpm_interrupt, CHANGE);
    attachInterrupt(pinMotorMowRpm, PCINT2_vect, CHANGE);    
  #endif



Problem is, that MOW RPM measurement isn't working correctly. When mower stop motors, MOW RPM goes to 0. It looks like RPM measurement is measuring not MOW motor, but signal from the odometry. What is wrong ? Thank you for help and explanation.

Problem ist, dass MOW RPM Messung nicht richtig funktioniert. Wenn Mäher-Stopp-Motoren, geht MOW RPM auf 0. Es sieht aus wie RPM-Messung misst nicht MOW-Motor, sondern Signal aus der Odometrie. Was ist falsch ? Vielen Dank für Hilfe und Erklärung.

Thank you

Alex
 
Was passiert, wenn motorMowModulate==0, aber mähen Sensor sendet impulse ?
Und odometrie = 1 :
Wann kommt es Signal von Odometrie Programm springt hier:


Code:
#ifdef __AVR__
ISR(PCINT2_vect, ISR_NOBLOCK){
#else
ISR(PCINT2_vect){
#endif
  unsigned long timeMicros = micros();
  boolean odometryLeftState = digitalRead(pinOdometryLeft);
  boolean odometryLeftState2 = digitalRead(pinOdometryLeft2);
  boolean odometryRightState = digitalRead(pinOdometryRight);  
  boolean odometryRightState2 = digitalRead(pinOdometryRight2);  
  boolean motorMowRpmState = digitalRead(pinMotorMowRpm);
  robot.setOdometryState(timeMicros, odometryLeftState, odometryRightState, odometryLeftState2, odometryRightState2);   
  robot.setMotorMowRPMState(motorMowRpmState);  
}


und Programm verarbeitet auch das Signal für MOW RPM

ist das richtig?

Danke

Alex
 
Hello Alex,
I didn' look at the code, but following sentence makes me wondering:

It looks like RPM measurement is measuring not MOW motor, but signal from the odometry. What is wrong ?

How would you like measuring rounds per minute without odometrie (encoder)? What do you mean with: "measuring not MOW motor"? From the mow motor you can measure the current nothing more.

Therefore: "When mower stop motors, MOW RPM goes to 0" must be correct because the wheel is not spinning anymore, and rounds per minute goes to 0.
 
No, I mean odometry from L/R motor.....
When setup is motor mow modulation = 0, and encoder on the Mow motor is implemented : Active is interrupt from odomery (motor L/R) and R/C. But when programm will jump to code where interrupt is hadled, here is also working (counting) with signal from encoder on the Mow motor and I think it's wrong and makes a wrong RPM MOW measurement.

Alex
 
I am sorry I misunderstood .
Currently, the code on github is not the code you shown. Therefore I am not possible to take a look in the code.
Your code in "ISR(PCINT2_vect)" is very time consuming. In would change the code.

Anyway, take a look in the function:
robot.setOdometryState(timeMicros, odometryLeftState, odometryRightState, odometryLeftState2, odometryRightState2);

Happens there something that influence following function?
robot.setMotorMowRPMState(motorMowRpmState);
Or is the problem in this function?


In my opinion teh interrrupt for mow motor will be activated and never deactivated .
Your code:
if (motorMowModulate==1){ // überprüfe ob die motorMowModulate aktiviert ist;
bitWrite(PCMSK2, PCINT18, HIGH); // und wenn ja schreibe eine 1 ins PCMSK2 Register3 "XXXX1XXX" Interrupt PCINT18 Register3 entspricht den Pin A10 des Arduino Mega
}

Current Github code: if (motorMowModulate)
{
PCICR |= (1
 
Thank you for your answer
I'm using pcint18, because I have other mainboard and wire connection.
it's strange, that you have other code, because I again downloaded latest 1.0a6-Azurit which is on github and code is same which I posted
Alex
 
take a look here
https://github.com/Ardumower/ardumower/blob/master/code/ardumower/mower.cpp
There stands following:


Code:
#ifdef __AVR__

  volatile byte oldOdoPins = 0;
  ISR(PCINT2_vect, ISR_NOBLOCK)
  {
    const byte actPins = PINK;                				// read register PINK
    const byte setPins = (oldOdoPins ^ actPins);
    if (setPins & 0b00010000)                 				// pin left has changed 
    {
      if (robot.motorLeftPWMCurr >= 0)						// forward
        robot.odometryLeft++;
      else
        robot.odometryLeft--;									// backward
    }
    if (setPins & 0b01000000)                  				// pin right has changed
    {
      if (robot.motorRightPWMCurr >= 0)
        robot.odometryRight++;								// forward
      else
        robot.odometryRight--;								// backward
    }  
    oldOdoPins = actPins;
  }

#else
 
hmm, it is a nightly build ? becuase it isn't 1.0a6-Azurit which I downloaded from wiki link.
Ok let me check how interrupt from motor mow encoder is hadled....
 
Hi,
So I compared Last released verison 1.0a6-Azurit with this from the link :
github.com/Ardumower/ardumower/blob/mast.../ardumower/mower.cpp
and in the new verison I see only odometry left and right defined (left2 and right2 no longer hadled ?)
and also I can't find how is handled interrupt for mow RPM measurement ?

Thanks for help

Alex
 
Oben