The guide to everything controls for 1675 members.
In this lab we will create a robot program that reads driver input and drives a robot with “tank drive”.
The hardware required for this lab is:
The setup should be as follows:
What we need to do to accomplish the objective:
If you don’t have a project, see As the Wheel Turns on how to create one.
The first step is to read the input value from both control sticks’ Y-axis.
This should be relatively easy - refer to your You Turn the Wheel project if you need help.
We will now be working with more than 1 motor controller. A veteran student or mentor can help you figure out how many motor controllers and what channels or CAN IDs they have. Take a good look inside the robot with your mentor or veteran while determining this. Try to understand the relationship between the motors, controllers, wheels, and drivetrain.
“Algorithm” is just a fancy way to say “a set of steps”. Before we write code to control the robot, we need to determine our control algorithm. A good rule of thumb is that if you can explain it out loud or write it down, you can figure out how to implement it in your program.
Look at the robot and where the wheels are situated. What will happen in they spin foward or backward all at the same time? Half of them? One of them? Try drawing it out on the board or a sheet of paper.
The algorithm you should aim to implement first is “tank drive”. Imagine driving a military tank. Pushing forward on the left stick should make the left wheels go forward, and vice versa. Pushing both sticks forward the same amoutn should have the robot driving forward in a relatively straight line.
Once you can describe your algorithm to take in the two control stick inputs and turn them into motor controller commands, we can move back to coding.
Try writing the code that expresses your algorithm above. Don’t be afraid to take it one step at a time and try different things with the robot. Make sure the robot is ON BLOCKS before testing any code that you don’t know the behavior of.
QUESTION TIME!
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, once you are confident that the robot will be controllable, put it on the ground and drive it around!
IMPORTANT! Make sure a veteran student or mentor loads the correct code back into the robot before the end of the night. We don’t want people to go to a demo or something with random drive code and nothing else in the robot.