Lesson 9: More about sensor input
Let's talk more about drive trains! You have already learned about the most basic type of drive train: tank drive. This lesson is a high level overview of drive trains in general.
Besides Tank, some other commonly seen drive trains (in order of complexity) are:
- H-Drive (or Slide drive)
- Mecanum Drive
- Swerve Drive
We are going to learn about Mecanum drive in the next lesson because it is fairly easy to implement but has a lot of benefits. If you need more information about the pros/cons and implementation of certain drive trains, simbotics has an excellent PDF about it here: http://www.simbotics.org/files/pdf/drivetraindesign.pdf
That's really as far as I want to get with the overview in this lesson. We do have one more thing to learn, however. What about very precise control over the motors? If you refer back to the tank drive code you wrote in lesson 4, you may notice that it can be difficult to get the robot to perform extremely fine and accurate movements. This is obviously a problem, and here are a few ways to fix it. Each method effects the handling of the robot in different ways, so be sure to read all of them and choose the one that best suits your needs
Solution 1: an extremely obvious and easy solution would be to multiply the input to the motor controller by some number less than one, .5 for example. You should have already created a gearing system, which is a way to get finer control of the motors. This solution does work (just hold a button to activate "slow" mode), but you may find depending on your robot configuration and personal preference that you like the other solutions better.
Solution 2: square or cube the input to the motor. I have included
some graphs below to help you understand what I am trying to convey here. If
you imagine putting the joystick input directly into the motor controllers
set()
method, the value input into the controller and the value put
into the motor controller follows a linear graph of x. Putting in .5 will set
the motor to speed .5, and putting in .75 will set the motor to a speed of .75.
This is the first graph seen below. If we square the input to the motor
controller, we change what that curve looks like, as shown by graph 2. Now
putting in a .5 with the joystick will only set the motor to a speed of .25. In
short, you still have the same min and max speeds, but you have more space on
the joystick that deals with slower speeds. Remember that you will need to use
a sign preserving square so that you can still drive backwards and forwards.
(Here's the sign preserving square expression, if you are stumped: |x| * x.) You
can even cube the input if it suits your taste (graph 3). Any higher
powers are left to you to use at your own discretion. Usually when you start
getting into powers of 4 and higher you start to gain speed too quickly as the
joystick nears the extremities of its range.
Graph 1 (Linear) | Graph 2 (Quadratic, sign preserved) | Graph 3 (Cubic) |
---|---|---|
Solution 3: Use a PID controller on each of your wheels. You don't know what that is yet, but I thought I would include it here just for completeness. For the curious people: that's lesson 22.
The solution that you choose should be based on your driver's preference. Test different things. Each solution will make the robot handle differently. There is no "correct" solution.
Exercises
- Go over your gearing system you made in lesson 4. Implement it so that it would be useful to control precise movements when needed. If you have access to a physical robot, try different values for the multiplier. Which number works best?
- Implement solution 2. Which curve do you prefer the best? It does boil down to a matter of personal preference in most cases. The design of your robot does play into it as well, so the same method might not get exactly the same results on every robot. Don't be afraid to try powers higher than 3 if you want.
On to lesson 11, which is all about mecanum drive!