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 =>?
Post a snippet of your actual code generating the error, or
what your desired algorithm is in pseudo code, and we will
have a chance of helping you out.
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.
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.
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?
Ahhh, the beauty of a PID controller. I wish I had a way to demonstrate it without the UI, because that’s about what you’re wishing to do, minus the driving aspect.
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.