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
Now that we’ve got a driving tank drive robot, let’s try something more interesting: arcade drive! This exercise will skip over some of the more detailed steps covered in the tank drive tutorial, so you may want to refer to that tutorial if you get stuck.
Arcade drive may be more familiar, because it is the basis of many video games. One joystick moves the robot forward and backward, and the second joystick turns left and right To do this, we will make the left joystick set a value for both motors and the right joystick will increase or decrease the motor speeds to turn the robot This control scheme offers less driver control, but it’s easy to learn and many drivers enjoy it.
If you have some experience programming, try implementing this drive control now. Otherwise, read on for step-by-step instructions.
To make a working arcade drive, we need to implement the following:
left_out = left_y + right_x
right_out = left_y - right_x
You may notice that we add right_x
to the left output and subtract from the right output.
This has the effect of increasing the left output and decreasing right output for positive x values, and the opposite for negative x values.
Having a speed difference between the motors causes turning.
Note that we still have to invert the left motor as we discovered in Tank Drive. We need to make sure we continue to include this inversion.
If you have any ideas on how to do this, try it on your own before following the step-by-step instructions.
Just like Tank Drive, we’ll start by:
DriveSubsystem
DriveSubsystem
RobotContainer
If you’ve already implemented another drive setup, you can reuse that here and we’ll modify. Otherwise, you can follow the detailed instructions in Tank Drive.
DriveSubsystem.h
void ArcadeDrive(const double forwardSpeed, const double turnSpeed);
DriveSubsystem.cpp
and add a corresponding function definition.
void DriveSubsystem::ArcadeDrive(const double forwardSpeed, const double turnSpeed) {
}
left_out = forwardSpeed + turnSpeed
right_out = forwardSpeed - turnSpeed
DriveSubsystem::ArcadeDrive()
void DriveSubsystem::ArcadeDrive(const double forwardSpeed, const double turnSpeed) {
m_leftDrive.Set(ControlMode::PercentOutput, forwardSpeed + turnSpeed);
m_rightDrive.Set(ControlMode::PercentOutput, forwardSpeed - turnSpeed);
}
The basics of this will be the same as Tank Drive, but now we’re going to use a different drive function and different joystick axes.
RobotContainer.cpp
m_drive.SetDefaultCommand()
call so it uses your new DriveSubsystem::ArcadeDrive()
function instead of DriveSubsystem::TankDrive()
. We need to make sure the y axis is still inverted.
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
m_drive.ArcadeDrive(m_controller.GetRawAxis(static_cast<int>(frc::XboxController::Axis::kLeftY)) * -1,
m_controller.GetRawAxis(static_cast<int>(frc::XboxController::Axis::kRightX)));
},
{&m_drive}
));
WPILib: Deploy Robot Code
Just like tank drive, we’ll start by opening the drive VI and unbundling the joystick values we want.
Drive_Arcade.vi
from the project explorerJoystick_In
controlJoystick.Y_Axis_Left
and Joystick.X_Axis_Right
When you are complete, you should end up with the following:
For this design, we will be using blocks from the numeric palette as shown below:
Note that we’ll be inverting the left motor like in Tank Drive.
right_x
joystick value to both motor wires
Now that we’ve got a new drive control VI, let’s try driving with it.
ArgoBot_Main.vi
Drive_Tank
block and select “Replace”>”All Palettes”>”Select A VI…”
Drive_Arcade.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 two different drive styles under your belt! Next up: button drive!
<-Previous | Index | Next-> |