hbrobotics / ros_arduino_bridge

ROS + Arduino = Robot
355 stars 351 forks source link

Encoder reading using Ardunio Mega #66

Open Mubashir-alam opened 6 months ago

Mubashir-alam commented 6 months ago

I can send PWM signal to the motor and it responds well I am trying to read the encoder value using e but it always shows "0 0" I modified motor_driver.h according to where my encoder PINs are connected I am using Arduino mega interrupt PINS PIN2,PIN3 AND PIN20,PIN21 for the left and right encoder

/* *************************************************************
   Encoder driver function definitions - by James Nugen
   ************************************************************ */

#ifdef ARDUINO_ENC_COUNTER
  //below can be changed, but should be PORTD pins; 
  //otherwise additional changes in the code are required
  #define LEFT_ENC_PIN_A 20  
  #define LEFT_ENC_PIN_B 21  

  //below can be changed, but should be PORTC pins
  #define RIGHT_ENC_PIN_A 2 
  #define RIGHT_ENC_PIN_B 3  
#endif

long readEncoder(int i);
void resetEncoder(int i);
void resetEncoders();
MSohan14 commented 1 week ago

Hey, I've run into the same issue and am using an arduino MEGA as well. Were you able to solve this issue?