|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Constants
I keep trying to write this code to help tune my joystick driving, but it keeps telling me to make a constant. I know what they are, but how would i write a constant when i want something to be more than or less than 127? for example: is it this <= or this =<? this >= or this =>?
please help me... |
|
#2
|
|||
|
|||
|
Re: Constants
Quote:
what your desired algorithm is in pseudo code, and we will have a chance of helping you out. |
|
#3
|
||||
|
||||
|
Re: Constants
Quote:
|
|
#4
|
|||
|
|||
|
Re: Constants
my bad, this is the code to drive forward or backward with sensitivity in the joystick.
#if 1 if (joystick_y < 127) { drive_left and drive_right < 127; drive_left = drive_right; } else if (joystick_y > 127) { drive_left and drive_right > 127; drive_left = drive_right; } else joystick_y == 127; Before this, the joystick would only read something if it went ONLY full forward or full backward. I want to make it so we could move it slighty when we want it to move only a little and not alot. |
|
#5
|
||||
|
||||
|
To move the motors "a little" (proportionally) to a joystick. Just assign the joystick value to the motor drive value. 0 is full reverse, 127 is neutral and 255 is full forward.
There are some lines in the default code: pwm01 = p1_y; pwm02 = p2_y; This uses two joysticks to control two motors. Now, you may want to widen the "neutral some so that the joysticks don't have to be perfectly centered for the motor to be off. Something like: if (p1_y < 120 || p1_y > 134) pwm01 = p1_y; else pwm01 = 127; // neutral The statement: drive_left and drive_right < 127 doesn't DO anything. Its just a comparison. |
|
#6
|
|||
|
|||
|
Re: Constants
I don't know what you're trying to do with this line, but it won't work.
You sure you're using a speed controller and not a spike? |
|
#7
|
|||
|
|||
|
Re: Constants
im trying to make the code work so that if the joystick goes, say, forward a little bit, the code will move closer to 255 only a little bit, say up to 145 or something like that. Same way backward, and if neither of those then the robot will be neutral and not move at all. The purpose is because we don't want to break the transmissions because it stops too hard when it goes full forward, so we would change the sensitivity of the joystick to slow down to neutral rather than go straight from 255 to 127. You get what im saying?
|
|
#9
|
|||
|
|||
|
Re: Constants
Quote:
The problem is your drivers. They are thinking like a race car game and not a real-car game. You don't slow your vehicle down by slamming the car into reverse, you slow it down by applying the brakes. Of course, I don't know what the wear/tear is on the gearbox by hitting it to neutral and whether or not that is a 'locked' neutral or a free neutral, but... If you have encoders on the wheels you could 'refuse' to allow the robot's PWM to be reduced to below 127 so long as there has been an increase in the count of the encoder in the last 26.2 ms loop. Regardless as to what you decide to do I would suggest having an 'override' for the system- one that allows your driver to go full power for any task, just in case (Say) time is running out and you've just GOT to get there. Just an idea. |
|
#10
|
|||
|
|||
|
Re: Constants
Thank you for the helping codes, it is greatly appreciated! Robot moves nice n smooth.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What constants are u using for high velocity PID | Salik Syed | Programming | 3 | 18-02-2006 23:22 |
| realistic friction constants. | Rickertsen2 | Motors | 11 | 18-10-2005 00:25 |
| Tweaking constants: any good way? | wun | Programming | 5 | 08-04-2004 10:44 |
| Global Constants | Ryan Cumings | Programming | 17 | 08-02-2004 19:05 |