# limiting voltage to the speed controller

Is there a location (file) in EasyC that we can change the ratio between the tellioperated input signal into the robot controller, and the pwm output signal to the speed controllers For ex. when i push a joystick 50% of its motion forward, can i have the controller only send out 10% of the pwm output signal. (to say it more simply the voltage to the speed controller)

you can set up a look up table.
ie: an array with 256 elements where each element has a value from 0-255

so if it were 50% push on a joy stick that would look like array[192] = 147ish

you can also run the joystick value through a math function to get your answer
left = ((left -127) /2 ) + 127

btw thats our “half the displacement” algorithm

The enclosed zip file is a Graphing Calculator file that demonstrates how you can have a linear translation from the joystick to the motor.

Graphing Calculator including a viewer is available from Pacific Tech at http://www.pacifict.com/Products.html

Joystick Scale.gcf.zip (673 Bytes)

Joystick Scale.gcf.zip (673 Bytes)

When you say left = … are you using a variable for that?? Because i’m not quite sure on how to do that. And also do you add a user function block to put that task in or is it under assignment that you put that in or what. it’s all quite confusing to me…Could you explain more simply how do you run the joystick value through a math function??? This if my first year working on this program and i am still becoming familiar with the software and help would be greatly appreciated

Can you explain how to “: array with 256 elements where each element has a value from 0-255” in easycpro for us newbies. Maybe a quick step by step. Thanks

If it was me, I don’t think I’d use a lookup table. I have no idea how to set that up in easyC (which is part of why I don’t use it all the time). In any case, here’s my solution.

If you take the joystick input and subtract 127, you get a -127 to 127 value. Divide that by 127 to get a -1 to 1 value. Then, you multiply that by the range you want the output to be–if you want it to be half what it is, the range would be 127 / 2 = 64ish. So you’d multiply by 64. That will give you a -64 to 64 value. Then, add 127 to center it around 127 again, for the PWM output, and output it.

I’ve attached a screen shot of the code I use. I multiplied the value first, then divided, but that shouldn’t change the answer.

JBot

I’m pretty sure you cannot use lookup tables with easyC. The solutions posted will work.

You could even do something like a cubic regression. If you do it right, it will let you move the motor very slowly, but you will still be able to use the full range if you need to.

you can also run the joystick value through a math function to get your answer
left = ((left -127) /2 ) + 127

Dont forget to typecast or else you will overflow.

left = (( (int)left - 127) /2 ) + 127

you can replace 2 with any value that you want to in order to further dampen the speed.