Here you'll find some tutorials to write drive code for the ArgoBot (or any robot) using LabVIEW or C++
This project is maintained by FRC1756-Argos
Seems like you’ve mastered driving with joysticks. What about all those buttons on the controller? Now, we’ll try a different approach to driving: button drive. This exercise will skip over some of the more detailed steps covered in the tank drive and arcade drive tutorials, so you may want to refer to those tutorials if you get stuck.
Button drive may be the strangest drive control covered in this training because it uses pure digital controls. Typically we use analog controls like joysticks because they allow both slow and fast driving, but with digital controls like buttons we get “stop” and “go” with no speed control. We will use the four right hand buttons to go forward, backward, turn left, and turn right as shown in the diagram. To do this, we will use the tank and arcade drive concepts and add in digital controls.
If you have already used LabVIEW, try implementing this drive control now. Otherwise, read on for step-by-step instructions.
To make a working button drive, we need to implement the following:
if A is pressed:
Reverse
else if B is pressed:
Right
else if X is pressed:
Left
else if Y is pressed:
Forward
else:
Stop
And the motor outputs for each state should be as follows:
Mode | Left Output | Right Output |
---|---|---|
Forward | 1 | 1 |
Reverse | -1 | -1 |
Left | 1 | -1 |
Right | -1 | 1 |
Stop | 0 | 0 |
Note that the left motor must be inverted as in the previous drives because forward is inverted on the left motor. The order of the button checks is not important, but what is important is that we can only ever drive one way at a time in button drive. There will be no forward and turn a little this time :)
If you have any ideas on how to do this, try it on your own before following the step-by-step instructions.
DriveSubsystem.h
void ButtonDrive(const bool forward, const bool right, const bool reverse, const bool left);
Note that the parameter names are based on the function of each input instead of the button we plan on using.
DriveSubsystem.cpp
void DriveSubsystem::ButtonDrive(const bool forward,
const bool right,
const bool reverse,
const bool left) {
}
Notice how we can align parameters so lines aren’t so long. C++ lets you format your code with whitespace without changing how your programs work.
if
, else if
, and else
blocks.
if
checks a condition (kind of like asking a question where the answer is ‘yes’ or ‘no’) and runs a block if that condition is true.else if
must always follow an if
or else if
statement. This checks another condition like if
, but only runs a block if the previous conditions were false and the new condition is true.else
must always follow an if
or else if
statement and will also be the last statement in a condition. Its block will be executed if none of the previous conditions were true.if(forward) {
} else if(reverse) {
} else if(right) {
} else if(left) {
} else {
}
if(forward) {
ArcadeDrive(0.5, 0);
} else if(reverse) {
ArcadeDrive(-0.5, 0);
} else if(right) {
ArcadeDrive(0, 0.5);
} else if(left) {
ArcadeDrive(0, -0.5);
} else {
ArcadeDrive(0, 0);
}
RobotContainer
and connect buttons to the function parameters.RobotContainer.cpp
and replace your existing drive function with ButtonDrive
in the SetDefaultCommand
call.
m_drive.ButtonDrive(/* Y button */,
/* B button */,
/* A button */,
/* X button */);
Note that the /* */
parts are comments, so they aren’t run by the robot program.
frc::XboxController::Button
enum so we can use button names and there’s a GetRawButton
to detect if the button is pressed.
m_drive.ButtonDrive(m_controller.GetRawButton(static_cast<int>(frc::XboxController::Button::kY)),
m_controller.GetRawButton(static_cast<int>(frc::XboxController::Button::kB)),
m_controller.GetRawButton(static_cast<int>(frc::XboxController::Button::kA)),
m_controller.GetRawButton(static_cast<int>(frc::XboxController::Button::kX)));
Just like before, we’ll start by opening the drive VI and unbundling the joystick values we want.
Drive_Button.vi
from the project explorerJoystick_In
controlJoystick.A
, Joystick.B
, Joystick.X
, and Joystick.Y
,When you are complete, you should end up with the following:
Joystick.A
is pressed it doesn’t matter what other buttons are pressed. A’s output will always be asserted.
Inputs above other inputs will have priority over those below. The bottommost value is called ‘default’ because it is only output if no button is pressed.
True
inputs and one to the default input.Now that we’ve got a new drive control VI, let’s try driving with it.
ArgoBot_Main.vi
Drive_Arcade
block and select “Replace”>”All Palettes”>”Select A VI…”Drive_Button.vi
Try driving it a little to see what you do or don’t like. You’ll want to improve on the design in future exercises.
What did you like more or less about this drive style? Is there anything that makes it hard to drive?
Congratulations! Now you have three different drive styles under your belt! Next up: Cheezy drive!
<-Previous | Index | Next-> |