![]() |
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 |
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 |
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) Code:
int unsignValue(int value)Code:
char filter[255] = [64,64,65,65,etc,etc]; |
Re: Create a low speed drive in programming
Quote:
Code:
const rom unsigned char mytable[256] = { |
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) |
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.
|
Re: Create a low speed drive in programming
Quote:
I just do the gearboxes. ;) Any programmers wanna explain how this is possible? John |
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)); |
Re: Create a low speed drive in programming
Here's another possible solution.
Code:
motor=y-((y-center)/factor) |
Re: Create a low speed drive in programming
Quote:
|
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) { |
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.
|
| All times are GMT -5. The time now is 17:48. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi