|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Create a low speed drive in programming
Our robots are a little too fast for anyone other than the driver to control. Since we take our robots out for demos and stuff, I being the programmer would want it to be safe. So I have been trying to come up with a program to drive this thing at half speed when the joystick are at full forward. We can't just divide all the values by 2 because that moves the center from 127 to 63.5. Anybody done such a thing, or can come up with a working program for this? I would appreciate any help
Thanks, -Bharat |
|
#2
|
|||||
|
|||||
|
Re: Create a low speed drive in programming
Quote:
[edit] You might want to tweak that reduction ratio a little, though. For example, you might want to multiply by 2/3 or 3/4 instead of 1/2. Whatever you decide to do, you can recenter your range by adding whatever it takes to get your center back to 127. So a formula would be: x1*reduction_ratio + (127-127*reduction_ratio) And the same for y1 Last edited by George1902 : 15-10-2004 at 22:34. |
|
#3
|
||||
|
||||
|
Re: Create a low speed drive in programming
Quote:
I just do the gearboxes. Any programmers wanna explain how this is possible?John |
|
#4
|
||||
|
||||
|
Re: Create a low speed drive in programming
Well I'm not sure what dial you are referring to, but I assume it is a one axis analog input. You could simply multiply the joystick input by a scaling factor (of course after first centering the joystick input around zero by subtracting 127) based on the value of this dial. It would probably be something like this (using the functions from my first example):
Code:
motorOutput = unsignValue(signValue(joystickInput) * (dialInput/255)); |
|
#5
|
|||||
|
|||||
|
Re: Create a low speed drive in programming
Here's another possible solution.
Code:
motor=y-((y-center)/factor) So for example: y=168 center=127 and factor=2 148=168 - (( 168 - 127 ) / 2 ) |
|
#6
|
|||||
|
|||||
|
Re: Create a low speed drive in programming
Quote:
|
|
#7
|
|||||
|
|||||
|
Re: Create a low speed drive in programming
The wheel that John is talking about was on the old joysticks. It was a thumb wheel located opposite the y axis trim adjustment wheel. The input was analog and reffered to in the code with a variable name similar to "thumb_wheel."
Here's the code to have the thumb wheel control the scaling on a joystick input. Code:
if (joystick < 127) {
motor = 127 - ((127 - joystick) * (thumb_wheel/254));
} else if (joystick > 127) {
motor = 127 + ((joystick - 127) * (thumb_wheel/254));
}
|
|
#8
|
|||||
|
|||||
|
Re: Create a low speed drive in programming
Now, I'm not sure about this, but I know the PIC processor is not very good with things like division. This makes me wonder if it would be faster to generate a lookup table before hand, or if the overhead of the division is so minuscule it will not make any real difference.
|
|
#9
|
||||
|
||||
|
Re: Create a low speed drive in programming
Two simple ways that I can think of off the top of my head:
1. convert the speeds to signed values then divide by two: Code:
int signValue(int value)
{
return value - 127;
}
Code:
int unsignValue(int value)
{
return value + 127;
}
Code:
char filter[255] = [64,64,65,65,etc,etc]; motorOutput = filter[joystickInput]; Last edited by Max Lobovsky : 15-10-2004 at 22:34. |
|
#10
|
|||||
|
|||||
|
Re: Create a low speed drive in programming
Quote:
Code:
const rom unsigned char mytable[256] = {
56,56,55,55....
};
|
|
#11
|
||||
|
||||
|
Re: Create a low speed drive in programming
Or perhaps have it divide the difference from 127 in half, add/subtract them and send that to PWMs
Like if your joystick is at 250 250 - 127 = 123 / 2 = 61.5 + 127 = 188.5 Code:
int DriveLimiter(int joyvalue)
{
if(joyvalue > 127)
{
return ((joyvalue - 127) / 2) + 127;
}
if(joyvalue < 127)
{
return 127 - ((127 - joyvalue) / 2);
}
}
![]() |
|
#12
|
||||
|
||||
|
Re: Create a low speed drive in programming
Just to clarify, my second method is the same as Wun's and my first method is (essentially) the same as Matt's.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| what's your most important drive train advice? | Ken Leung | Technical Discussion | 42 | 07-01-2003 09:58 |
| Power, speed, and torque... AGH | Gui Cavalcanti | Technical Discussion | 5 | 10-11-2002 19:02 |
| Quad- 1/2 track drive system | Ben Mitchell | Technical Discussion | 24 | 30-01-2002 11:55 |
| "Motors and Drive train edition" of Fresh From the Forum | Ken Leung | CD Forum Support | 6 | 29-01-2002 12:32 |
| Drivetrain Help | Jordan | Technical Discussion | 16 | 02-12-2001 12:14 |