hbrobotics / ros_arduino_bridge

ROS + Arduino = Robot
355 stars 351 forks source link

Problem with encoder readings on A4 A5 #55

Open chrissunny94 opened 6 years ago

chrissunny94 commented 6 years ago

I have tried setup the connections properly , while testing i am always getting flawed reading (almost static ) on the Analog ports . I am using an Arduino UNO , the encoders are connected directly to the arduino .

For the motor control , i am using L298.

What should i do to change , to change the A4,A5 pin to any of the portD pins .

`
/ Interrupt routine for LEFT encoder, taking care of actual counting / ISR (PCINT2_vect){ static uint8_t enc_last=0;

enc_last <<=2; //shift previous state two places
enc_last |= (PIND & (3 << 2)) >> 2; //read the current state into lowest 2 bits

left_enc_pos += ENC_STATES[(enc_last & 0x0f)];

}

/ Interrupt routine for RIGHT encoder, taking care of actual counting / ISR (PCINT1_vect){ static uint8_t enc_last=0;

enc_last <<=2; //shift previous state two places
enc_last |= (PINC & (3 << 4)) >> 4; //read the current state into lowest 2 bits

right_enc_pos += ENC_STATES[(enc_last & 0x0f)];

}`

What should i change here?

chrissunny94 commented 6 years ago

Sorry , wires were lose , sorted .

Femi-Tofade commented 4 years ago

Hi, did the ros_arduino_bridge give you correct odometry readings? My encoders are connected directly to the wheelchair too...