0

I'm using a ANALOG joystick and Arduino to control X,Y motors using two PWM.

Each PWM controls the speed of the corresponding motor.

Right now it works but its not smooth, I need a exponential function to make it smooth.

Need an exponential function that changes the PWM a little bit exponentially toward the new values like this.

 void loop()
 {
    currentX=read joystick X
    currentY=read joystick Y

    dx=expFunction(previousX - currentX);
    dy=expFunction(previousY - currentY);
    set X PWM for motor to DX;
    set Y PWM for motor to DY;
    previousX=currentX;
    previousY=currentY;
}

the expFunction should be replaced with a real function, this I dont know.

anybody has idea, or can point me in the right direction?

thanks rough

N S
  • 303
  • 4
  • 17
  • Look for `exp()` in the C standard math library. –  Aug 03 '13 at 12:31
  • (But hey, is it **this** hard to google "C exponential function"!?) –  Aug 03 '13 at 12:32
  • I did google it, but its not that straight forward. The exp must be applied so that the PWM only changes a little bit each loop(),and that change is an exponential change as time goes on, but there is no time variable. So I'm trying to figure out how it all goes together. – N S Aug 03 '13 at 12:54
  • basically I have to find an exponential curve of points between the starting speed and the ending speed. – N S Aug 03 '13 at 13:00
  • `exp()` is fine for that purpose - you have to do some linear interpolation with the logarithm of the starting and ending values, but that's all you need. –  Aug 03 '13 at 13:15
  • after research, the result is that I need a damping exponential equation given two points (starting speed, and ending speed) and also how long to take to go from one speed to another. lump all that into one equation Y=(a)(b)^x. solve for a,b,and x. Have to make sure its a negative (damping) exponential function so that the delta gets smaller as it approaches the target speed. – N S Aug 03 '13 at 13:31
  • You use a base smaller than one. –  Aug 03 '13 at 13:34
  • doesnt work it seems,need something else. If the final value is speed=0, then the equation is zero, makes no sense. – N S Aug 03 '13 at 15:21

0 Answers0