Stuck in the interrupt callback

Hello,

I am developing a basic differential drive robot with Arduino and I am facing a problem when the code starts implementing the interrupts never getting out of it again.

the interrupt is to get the encoder ticks for the DC motors so I am assuming that since the wheels will continue moving the trigger pin will get high always and being stuck in the callback function I want to know is this the situation, if so how can I use the interrupts properly

the values of the encoder ticks will be sent to through serial port to ROS to be processed
here is my code

// *********************************************** //
void setup() {
  
  setupROS();

  setupEncoders();

  setupMotors();

}
// *********************************************** //

void setupROS(){
  
  nh.initNode();
  nh.subscribe(sL);
  nh.subscribe(sR);
  nh.advertise(pL);
  nh.advertise(pR);

}//end of the setup ROS function

void setupEncoders(){
  
  pinMode(Left_Encoder_PinA, INPUT_PULLUP); 
  pinMode(Left_Encoder_PinB, INPUT_PULLUP);
  //Attaching interrupt in Left_Enc_PinA.
  attachInterrupt(Left_Encoder_PinA, do_Left_Encoder, RISING);

  pinMode(Right_Encoder_PinA, INPUT_PULLUP);
  pinMode(Right_Encoder_PinB, INPUT_PULLUP);
  //Attaching interrupt in Right_Enc_PinA.
  attachInterrupt(Right_Encoder_PinA, do_Right_Encoder, RISING); 

}// end of the setup Encoders Function

void setupMotors(){

  pinMode(A_L,OUTPUT);
  pinMode(B_L,OUTPUT);
  pinMode(PWM_L,OUTPUT);
  
  pinMode(A_R,OUTPUT);
  pinMode(B_R,OUTPUT);
  pinMode(PWM_R,OUTPUT);

}// end of the setupMotors Function

// *********************************************** //
void loop() {

  do_Left_Encoder();
  do_Right_Encoder();

  moveLeftMotor(left_motor_speed);
  moveRightMotor(right_motor_speed);
  
  nh.spinOnce();  
}// end of the main function
// ********************************************** //



//############################################################//
void moveLeftMotor(float PWM_val){
  if (PWM_val>0)
  {
       
 digitalWrite(A_L,HIGH);
 digitalWrite(B_L,LOW);
 analogWrite(PWM_L,PWM_val);
    
  }
  else if(PWM_val<0)
  {
 digitalWrite(A_L,LOW);
 digitalWrite(B_L,HIGH);
 analogWrite(PWM_L,abs(PWM_val));
 
  }
  
  else if(PWM_val == 0)
  {
 digitalWrite(A_L,HIGH);
 digitalWrite(B_L,HIGH);
    
    
  }
  
}
//############################################################//



//############################################################//
void moveRightMotor(float PWM_val){
  
  if (PWM_val>0)
  {
       
 digitalWrite(A_R,HIGH);
 digitalWrite(B_R,LOW);
 analogWrite(PWM_R,PWM_val);
    
  }
  else if(PWM_val<0)
  {
 digitalWrite(A_R,LOW);
 digitalWrite(B_R,HIGH);
 analogWrite(PWM_R,abs(PWM_val));
 
  }
  
  else if(PWM_val == 0)
  {
 digitalWrite(A_R,HIGH);
 digitalWrite(B_R,HIGH);
    
    
  }

}// end of the move right motor function
//############################################################//

//############################################################//
/* void do_Right_Encoder()
{
    if (digitalRead(Right_Encoder_PinB) == HIGH) {
    if (digitalRead(Right_Encoder_PinA) == LOW) {
      Right_Encoder_Ticks++;
    } else {
      Right_Encoder_Ticks--;
    }
  } else {
    if (digitalRead(Right_Encoder_PinB) == LOW) {
      Right_Encoder_Ticks--;
    } else {
      Right_Encoder_Ticks++;
    }
  }
  //enRticks.data = Right_Encoder_Ticks;
  //pR.publish(&enRticks);
 
  
}// end of the do right encoder function
//############################################################//
//############################################################//
void do_Left_Encoder()
{
   // Test transition; since the interrupt will only fire on 'rising' we don't need to read pin A
    if (digitalRead(Left_Encoder_PinB) == HIGH) {
    if (digitalRead(Left_Encoder_PinA) == LOW) {
      Left_Encoder_Ticks++;
    } else {
      Left_Encoder_Ticks--;
    }
  } else {
    if (digitalRead(Right_Encoder_PinB) == LOW) {
      Left_Encoder_Ticks--;
    } else {
      Left_Encoder_Ticks++;
    }
  }
  enLticks.data = Left_Encoder_Ticks;
  pL.publish(&enLticks);
   
}// end of the do left encoder function */
//############################################################//

void do_Left_Encoder()
{
   // Test transition; since the interrupt will only fire on 'rising' we don't need to read pin A
  LeftEncoderBSet = digitalRead(Left_Encoder_PinB);   // read the input pin
  Left_Encoder_Ticks -= LeftEncoderBSet ? -1 : +1;
  enLticks.data = Left_Encoder_Ticks;
  pL.publish(&enLticks);
   
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//do_Right_Encoder() Definitions

void do_Right_Encoder()
{
  
  RightEncoderBSet = digitalRead(Right_Encoder_PinB);   // read the input pin
  Right_Encoder_Ticks += RightEncoderBSet ? -1 : +1;
  enRticks.data = Right_Encoder_Ticks;
  pR.publish(&enRticks);

 
 
  
}

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code.

It seems like some of your code is missing. It would be most helpful for you to post the complete code.

It might help if you post complete code; this does not compile (e.g. lack of variable declarations). Also please provides any links to non-standard libraries.

If encoder pulses come in while the ISR is being processed, it will look like you're stuck in the ISR; the code will leave the ISR and nearly immediately return back to it. How fast are te encoder pulses come in?

What is pL.publish()?

void loop() {

  do_Left_Encoder();
  do_Right_Encoder();

This is wrong. Why are you calling the ISR routines in loop()?

Pete

  pinMode(Left_Encoder_PinA, INPUT_PULLUP); 
  attachInterrupt(Left_Encoder_PinA, do_Left_Encoder, RISING);

  pinMode(Right_Encoder_PinA, INPUT_PULLUP);
  attachInterrupt(Right_Encoder_PinA, do_Right_Encoder, RISING);

The first argument to attachInterrupt() is NOT a pin number. It is an interrupt number.

Use the digitalPinToInterrupt() function (macro?) to do the translation. If you are using an Arduino UNO or Nano then I hope your Left_Encoder_PinA and Right_Encoder_PinA are Pin 2 and Pin 3 since those are the only two pins on the UNO/Nano that support external interrupts. (That's one reason we want to see ALL of your sketch.)

  pinMode(Left_Encoder_PinA, INPUT_PULLUP); 
  attachInterrupt(digitalPinToInterrupt(Left_Encoder_PinA), do_Left_Encoder, RISING);

  pinMode(Right_Encoder_PinA, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(Right_Encoder_PinA), do_Right_Encoder, RISING);