View Full Version : [FTC]: Not Deadbands now.....speed limits
JohnFogarty
06-11-2010, 07:58
I know someone somewhere out there uses a speed limit on their joysticks. Even when you've geared the motors down sometimes the speed is a little tooo fast. Soo say I want to limit on the upper values like 90 and above or -90 and below to the speed of 60/-60. The logic doesn't work like an if/then statement or rather I haven't gotten it to work.
P.S.-It seems RobotC's compiler takes two compiles sometimes just to get the robot to see a change you've made.
rzoeller
06-11-2010, 18:01
To circumvent the double compile problem (I have experienced it as well), use a different name for each version. You should do this anyways, but just tag it with a version number and it will update correctly.
One solution to the other problem is to use a parabolic system, demonstrated by the code below.
#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
void initializeRobot()
{
return;
}
void scaleMotor(char motorname, int joyVal)
{
int sign = joyVal / abs(joyVal); //Returns a 1 or -1
float ratio = ((joyVal * joyVal) / (16129)); //Gets a ratio from a parabolic curve
int scaledVal = (sign * 100) * ratio;
motor[motorname] = scaledVal;
}
task main()
{
initializeRobot();
waitForStart(); // wait for start of tele-op phase
while (true)
{
getJoystickSettings(joystick);
scaleMotor(DriveL, joystick.joy1_y1);
scaleMotor(DriveR, joystick.joy1_y2);
}
}
You add if statements to that to limit when it will scale the motors, I.E. below 75%.
Or just change the multiplier, from * 100 to whatever you want for the maximum speed. This way you keep the entirety of the joystick for driving, instead of having your code lump the outer edges together.
PSHRobotics
28-11-2010, 16:42
Or just change the multiplier, from * 100 to whatever you want for the maximum speed. This way you keep the entirety of the joystick for driving, instead of having your code lump the outer edges together.
I know this is a slightly old topic, but the original poster has not responded saying how he fixed his issue and it is something that I had been looking into earlier and would like to see if anyone has actually found an effective solution.
That's how we have been doing it for the past couple of years. In which case, he would scale the joystick values by dividing by 127 and then just multiplying by 90. (I use LabView, but I believe the logic works the same).
What I am curious about, however, is that the original poster seems to want the values to be above 60 (and under 90). I am unsure how I would actually do this.
I would think the best way to do it would be to find the "sign" of the joystick value (which rzoeller has shown in his code) and split into an if, then, and else sequence where if the sign is positive (1) you take the joystick value divide by 127 then multiply by 30 and finally add 60. While if the sign is negative you take the joystick value divide by 127 then multiply by 30 and finally subtract 60.
EricVanWyk
28-11-2010, 20:07
NOTE: I am relatively unfamiliar with Robot C, I have one season of coaching BEST worth of experience with it. Please check that my assumptions are correct. The first bit might not actually be an issue...
There may be a bug hiding in this line:
float ratio = ((joyVal * joyVal) / (16129));
If Robot C handles casting like C does, the actual math will be done in integer math, and then cast to a float at the end. Follow it through the parenthesis to find this:
float ratio = ((joyVal * joyVal) / (16129));
float ratio = float ((int * int) / (const int));
float ratio = float (int / const int);
float ratio = float (int);
In the 3rd step, dividing an int by a const int will truncate to an int. When it is cast to a float in the 4th step, the information is already lost. It is likely that this doesn't really matter, but it makes for a confusing read.
I'd recommend replacing the line with
float ratio = ((joyVal * joyVal) / (16129.0));
Now you are dividing an int by a const float, which will be done in floating point math.
Do you want to rescale the sticks so that full forward on the stick is 60%, and everything in between is rescaled? Or, do you just want to chop off the top of the sticks so that anything above 60 is limited to 60?
Rescale:
The key to rescaling is to find center of your range, pull it to zero, do your scaling, and then push it back to the real center. Then, shuffle your math around until it looks good for a computer.
For example, lets rescale around 127:
recentered = input - 127;
scaled = recentered * ratio;
output = scaled + 127;
Put it all on one line:
output = (input-127) * ratio + 127;
If ratio is a floating point number between 0 and 1, you are done. If you want to rephrase it as your new maximum value, write it like this:
output = (input-127) * max_value / 127.0 + 127;
You can likely leave off the ".0" from "127.0". Just be sure you follow the golden rule of integer division: Multiply, then divide. Going the other way around kills your accuracy.
PS/EDIT: I'm confused as to your goal still. Could you please draw a graph of what you want to do, with "input from the joystick" on the x axis and "output to the motors" on the y axis? You can sketch it in mspaint or whatever, just label a few key spots.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.