# 10 - Basic Drivetrain ## Actual robot code! What does it do? Well, to start off with we're going to look at getting the robot's drive base to move. This is by far the most common thing you'll have to deal with when developing robot code, and will be something you have to do every year. Drive base code like what's in this example should be something you can do in your sleep, and if you're a rookie team or still a relatively new team, this is probably how your robot program is going to start out looking. There are other types of drive bases though that you may encounter or want to use. ## Wait, there's more than one type of drive base? Yes, speaking very generally, at the time of writing this, there were three main types seen in the competition space. There are of course, exceptions to this, but you'll generally see the following: - Differential Drive - These drivebases usually have some combination of 4, 6, or 8 wheels, and in the 6 or 8 wheel configurations, usually the center wheels will be slightly lower to the ground than the front and back wheels. This is probably the simplest robot drive base to build, as it uses simple, high traction wheels, chain or belts, and simple gearboxes to function. It's also probably the simplest to write code for. This is probably the drive base you'll be building if you're a rookie team. - Mecanum Drive - These drivebases aren't super common anymore but they are still around. The use 4 wheels, one at each corner of the drivebase. The wheels themselves are special because they have rollers ([See Here](https://www.adafruit.com/product/4679?gclid=Cj0KCQiAwJWdBhCYARIsAJc4idBJFVX-rSFgrx250d4-8Viu1bxuqatre4KCdgVIoPXs6OSyRL9_On8aAlQXEALw_wcB)) with different spin orientations (left or right). These different spin orientations, when implemented properly, allows the robot to move laterally both forward/backward as well as left/right, while still maintaining the ability to rotate about the robot's center. Mecanum is somewhat more difficult to build, and to program, when compared to Differential Drive, but not so significantly that it's inaccessible to teams who've only been in the game a year or two. - Swerve Drive - Swerve drive is complicated, but it's becoming very quickly a mainstay of the FIRST community. Essentially, at each corner of your robot you have a swerve module, the module has 2 motors, and an Encoder. One motor makes the wheel spin, as a wheel should, but the other motor, in tandem with the encoder, rotates the wheel so it can spin in 360 degrees. Because each module spins independent of the other. You get all the benefits of mechanum drive, without losing the pushing power of Differential Drive. Builting a swerve drive base is not for the faint of heart, it can be a complicated project, both mechanically and programmatically. Not recommended for beginners. ## So what do I need to get my drive base up and running in code? Not much really. In robotInit(), you should be setting up a few things. - Motor Controllers - For Differential Drive, you'll usually have 2 motors in one gearbox on each side of the robot, so 4 motors total - Motor Controller Groups - You'll need one of these for each side of your drive base, a left side and a right side, the Motor Controller Groups help you to control both motors on a single side together. - A Differential Drive - You'll need just one of these, it'll take the Motor Controller Groups you make and manipulate them so your drive base acts as a single cohesive unit - An XBox Controller (or similar control mechanism, like a Joystick) - You'll need one of these to start, but probably two for competition. Once all that is set up you just need one line of code in teleopPeriodic to make your robot move. There are two options for this: - arcadeDrive(UpDown, LeftRight) - This is like what you might use if you are playing an arcade game, a single joystick on your controller moves the robot forward and back, left and right. - tankDrive(LeftUpDown, RightUpDown) - This is like, well, controlling a tank, you use two joysticks, but only the forward and backward axis of each. Varying how much you push one or the other forward or back, you can make the robot drive forward, turn left or right, or pivot about its center. You can find more detail in the comments of the code. ## Why do we "import ctre"? Some things that we use in the example use the CTRE (Cross the Road Electronics) library. Specifically, WPI_VictorSPX, some motor controllers (among other features) can't be used without importing a separate module that contains the classes we need to build the objects we want to represent. Similar to how we import wpilib, and wpilib.drive, which contains most of the things we're using like XboxController, DifferentialDrive, MotorControllerGroup, etc, we need to import ctre to gain access to other elements that we want to use as well. For much of the examples to come, you'll see the three imports you see now, and not much else, but be aware that there are others out there that you may need as you begin to develop your own robot programs.