speed controller max speed

we were testing our robot and we realized that the mototrs are way to sensitive. how do we make the max speed on the speed controllers from 255 to around 200. what is the code for that. whenever we use the triggers the robots moves and we dont want that. HELP!!! thanks.

any help plz. i kind of need the answer as quick as possible

yay for fellow San Jose Team. What you need to do is add a limit to the pwm values that are being sent to the speed controllers.
For instance
(insert x for the pwm number)

if(pwmX >= 200)
{
pwmX=200;
}

or

pwmX= pwmX >=200 ? 200 : pwmX;

We also added a dead band where any value +30 or the middle 127 on the joystick will not make the motors move since the joysticks are so sensitive

You could one of three basic things:
You could use a formula to squish things in, which may take longer, but consume less space
or you could use a lookup table, which would take less time, but consume more space.
Or you could just cut everything off after 200, which is small and takes little time.
Here is a an example fomula one:


unsigned int Limit(unsigned int pwmin)
{
unsigned int tmppwm = 0;
tmppwm = (unsigned int)(((pwmin-127)*72)/127) + 127);
return (tmppwm+127);
}

how do u set the dead band because the joysticks are really sensitive? thanks for your help

I think this is what you mean:


unsigned int DeadLimit(unsigned int pwmin)
{
if(((pwmin-127) && 0x7F) >15 ) return pwmin;
else return 127;
}

Which would make anything from 112 to 142 all to 127.

it comes up with an error on the line that has the " { " on it

What does the error say?

error: syntax eror c:233. it says it when i compile it. on line 233 is the " { " after:

unsigned int deadlimit (unsigned int pwmin)
{ <— that is where the error is

It might be because you left a bracket open from another peice of code earlier in the code…

If that is not the problem… it might be that you did not define
“unsigned int DeadLimit(unsigned int pwmin);” in an h file for referring to it in anotehr piece of code.

nvm that i figured it out but now it says pwmin has not been defined. do i just do #define or do io have to define it a different wway. thanks a lot for your help.

no you do not need to use a define…
you should just call it as a function like so:

pwm01 = deadlimit(pwm01);

or something like that…

The pwmin is defined by the function…
be sure that you define:
“unsigned int DeadLimit(unsigned int pwmin);”
inside of an h file that you have included in it.

so i should add unsigned int deadlimit … into and h file and then the

“{
if (((pwm-127) && 0x7f >15) return pwmin
else return 127;
}”

into user_routines.c. where do i put the pwm01 = deadlimit(pwm01)?

im really confused right now. so if you could right it out in a post that would be really appreciated.

is there an easier way to do this because it to compile but then when it gets to the 3rd stage it says : could not find definition of symbol deadlimit in file user_routines.o

you would put “pwm01 = deadlimit(pwm01);” into the code right before you are outputting inside of function User_Driver() in user_routines.c…

Yes…
You could just forget about a function and just do the code like this:


if (((pwm01-127) && 0x7f <=15) pwm01=127;

and just replace the 01 with whatever pwms you want to put out to…

I forgot about another way you could do it…
Which is just do the same for the joystick… like so:


if ((((signed int)p1_x-127) && 0x7f <=15) p1_x=127;
if ((((signed int)p1_y-127) && 0x7f <=15) p1_y=127;