ahmedragia21
Member
Hi, im trying to do a PD for a robot to let it move in straight line , im just experimenting with just one motor connected to an encoder , well , when i get some samples from the enocders and when its not pointed to the motor encoder's strips , the motor change its speed as a function of the samples from the encoder is that correct ? also when i point the encoder sensor to the motor , the motor oscillates , dunno why ? and the desired_speed constant doesnt affect the speed of the motor ....
im using that code
for getting the Lvel , im just using an external interrupt .. and made a global variable unsigned char Lvel =0;
im using that code
Code:
#define left_velocity 10
#define K_PRO 3 /* proportional constant */
#define K_DRV 3 /* derivative constant */
int Lvel, Rvel; /* requested input velocities, ticks per 1/20 sec */
int leftacc, rightacc; /* accumulators for motor output values */
int leftlast, rightlast; /* history values for calculating derivative */
void speedcontrol() /* PID controller*/
{
int lf, rt;
lf = (Lvel - left_velocity)*256;
leftacc += ((lf/K_PRO) + ((lf - leftlast)/K_DRV));
leftlast = lf;
pwmL(leftacc/256);
}
for getting the Lvel , im just using an external interrupt .. and made a global variable unsigned char Lvel =0;