So our team is having difficulty driving completely straight at 100% power because we use tank drive. To control our bot we use an Xbox controller - Left 2 motors (y-splitter) connected to pwm 0, controlled by left stick - Right 2 motors (y-splitter) connected to pwm 1, controlled by by right stick.
We want to add a boolean function to a button that makes both drive trains move together at 100% speed. I was able to just create the function for the button separately from the rest of the drive train code, but they were trying to override each other.
I understand why that is happening, but I’m not quite sure what logic to use to connect them such that - when the button is not pressed, the drive train refers to the 2-stick axes, and also vice-versa.
Have the two settings wires from the joysticks pass through a Case statement decided by the button press.
False case just passes through the joystick values from one side of the Case to the other.
True case outputs a constant 1.0
Then out the other side of the case feed the inputs into a single Drive Set.
Don’t ever have two different Drive Sets active.
As an alternative, if you have triggers on your controller (such as on an Xbox or Logitech F310), you can use those to drive straight at variable speed. I’m both programmer and driver, and I have the controller set so that the right trigger drives straight forward and the left trigger drives straight backwards.
Be sure to figure out which controls have priority over others - if you don’t, you’ll end up setting the motor’s speed multiple times in the same iteration, causing your robot to jitter around.
I have an example here if needed. (Lines 55-68 also includes a P controller for angle using the NavX - you can ignore this, it should work just fine without it)
This sounds like a perfect way to resolve our problem, and I know what you mean, but I’m not exactly sure how to set it up. Do you possibly have a screenshot of an example you could send? Thanks again for the help Mark.
As @Low3arth0rbit mentioned, driving two sides at the same % doesn’t mean the robot will necessarily go straight.
When I drove tank-drive-style in 2017 and 2018, I had it set up so that holding the “A” button would cause the left joystick to control the speed of both sides simultaneously.
In normal operation I would move both sticks to move both sides independently. If I wanted to drive straight, I’d press the A button with my right thumb and control the robot speed (forward or backward) with the left stick only.
The % was corrected with experimental testing so that the robot would drive straight. For example last year the right side needed to be 98% of the left side for it to drive straight.
Just a thought. I liked the ability to drive in a straight line not only at full speed, but at any arbitrary speed. It was fairly intuitive once you get the hang of it.
Here is the percent reduction of a side. I would personally recommending figuring out which side is “stronger” and reduce it assuming that it applies linerally. For example if you are turning to the left than your right is “stronger” so if you make your right go at 97% power you will drive straight.
So when the button is not pressed (case statement in 0 mode) it would pass through the stick values to the left and right sides of the drivetrain. When the button is pressed (case statement in 1 mode) it should pass the left stick through to both sides of the drivetrain.