The guide to everything controls for 1675 members.
In this lab, we will create our first robot program and make a wheel turn using a motor controller.
The hardware required for this lab is:
The setup should be as follows:
You’re in luck! Every past 1675 robot that still has its electronics has all these things. Let’s go a little more in-depth on some of the aspects of the hardware setup.
You will need a computer with Driver Station installed to start the robot. We won’t be using any human input in this lab, so the program is all you need.
The RoboRIO is the “brain” of the robot. It will run our code, take input signals, and send output signals. One key output is sending commands to motor controllers, over either PWM or CAN.
The PD (Power Distribution) board connects to the battery and distributes power to the robot. The electrical team will handle this for the most part, but using CAN we can get some info about power usage of various channels if we need to.
This is a motor controller. It takes power in from the PD board (+ and -), outputs power to the motor (+ and -), and has signal wires. The output wires going to the motor will apply some voltage to the motor depending on how we command it. In FRC, motor controllers work using the CAN (Controller Area Network) Bus, or using PWM (Pulse-Width Modulation) signals. The two methods use different wiring and different code. Typically, 1675 uses communication over the CAN bus.
The CAN Bus is 2 wires that all the CAN Bus devices on the robot chain together and enter the roboRIO at one point. Each CAN Device has its own “CAN ID” used to refer to it in the code.
This is a motor. This motor is a Rev Neo, but we use many different kids of motors (determined by the rules and the design team). Most motors we will use work the same way. The two power wires connect to the outputs of the motor controller. When the motor controller applies voltage to the motor, the motor will turn proportional to the voltage given. How fast the motor spins is determined by both the applied voltage and the motor specifications. Each motor requires its own dedicated motor controller.
The wheel will turn when the motor turns. How fast it spins depends on how it is conected to the motor. The design team determines what the ratio from the motor to the wheel will be. If you are running on this lab on a test board, no wheel will be connected, which is OK.
To program the robot you will need VSCode with the FRC development plugins installed and vendor library for motor controllers (e.g. CTRE, Rev. Ask a mentor if you are unsure of this). For help, see Setting up your development environment (robot).
What we need to do to accomplish the objective:
To create the template project
If successful you will have a new project in VSCode and in that project will be a Robot.java file with a lot of template code and comments.
In FRC, if a robot is turned on, it is in one of 3 modes: Disabled, Teleoperated, or Autonomous. In Disabled mode all outputs are disabled. In Autonomous all input from the Driver Station is disabled. In the TimedRobot framework your code can be called in one of 2 ways: init, periodic. Each mode has its own version of a method for these ways. (ex. autonomousInit
, disabledPeriodic
.
autonomousInit
, teleopInit
, disabledInit
autonomousInit
runs once whenever the robot enters autonomous mode.autonomousPeriodic
, teleopPeriodic
, disabledPeriodic
disabledPeriodic
runs every 20ms when the robot is in disabled mode.robotInit
, that runs once, ever, whenever the robot code starts.QUESTION TIME!
On 1675 we typically use Command-Based programming to program our competition robots, but it is important to understand how IterativeRobot works first.
For this lab, make the wheel spin at 50% speed forward any time the robot is in teleop mode.
What method or methods should our code to do this go in? Think about it or discuss with your group.
What code will you need to add? Here are some tips:
WPI_TalonSRX
.
0.5
will set the motor to 50% speed forward.When you test your code for the first time, always do it “on blocks”. No moving part of the robot should be touching the floor or anything else. For this lab you can leave the robot on blocks as we are only turning one wheel.