Hi,
I’m on a small rural team with no coding mentors. I know that the RobotDrive class has been deprecated this season, but when I try to implement use of the DifferentialDrive class, various parts of the code errors out. Here is basic TeleOp code that I know worked last season. Can someone walk me through what needs to change in order for this code to be updated with the DifferentialDrive class? Thanks!
#include "WPILib.h" //<-- Parker added this 2/9/17
#include <iostream>
#include <memory>
#include <string>
#include <VictorSP.h>
#include <Joystick.h>
#include <SampleRobot.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
#include <RobotDrive.h>
#include <Timer.h>
#include "RobotBase.h"
using namespace frc; //<-- Parker added this 2/9/17
using namespace std;
/**
* This is a demo program showing the use of the RobotDrive class.
* The SampleRobot class is the base of a robot application that will
* automatically call your Autonomous and OperatorControl methods at the right
* time as controlled by the switches on the driver station or the field
* controls.
*
* WARNING: While it may look like a good choice to use for your code if you're
* inexperienced, don't. Unless you know what you are doing, complex code will
* be much more difficult under this system. Use IterativeRobot or Command-Based
* instead if you're new.
*/
class Robot: public SampleRobot {
//frc::RobotDrive myRobot { 0, 1 }; // robot drive system --commented 2/10/17
Joystick *stick; // declaring left joystick
Joystick *rstick; // declaring right joystick
VictorSP *lmotor1; // declaring one of two victors on the left side of the drivetrain
VictorSP *lmotor2; // declaring one of two victors on the left side of the drivetrain
VictorSP *rmotor1; // declaring one of two victors on the right side of the drivetrain
VictorSP *rmotor2; // declaring one of two victors on the right side of the drivetrain
RobotDrive *drivetrain; // declaring the drivetrain
public:
Robot() {
//Note SmartDashboard is not initialized here, wait until RobotInit to make SmartDashboard calls
stick = new Joystick(0); //initializing left joystick
rstick = new Joystick(1); //initializing right joystick
lmotor1 = new VictorSP(1);
lmotor1->SetInverted(true);
lmotor2 = new VictorSP(2);
lmotor2->SetInverted(true);
rmotor1 = new VictorSP(3);
rmotor1->SetInverted(true);
rmotor2 = new VictorSP(4);
rmotor2->SetInverted(true);
drivetrain = new RobotDrive(lmotor1, lmotor2, rmotor1, rmotor2);
drivetrain->SetExpiration(0.1);
}
void RobotInit() {
}
/*
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* GetString line to get the auto name from the text box below the Gyro.
*
* You can add additional auto modes by adding additional comparisons to the
* if-else structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as well.
*/
/*
* Runs the motors with tank steering.
*/
void OperatorControl() override {
drivetrain->SetSafetyEnabled(true);
while (IsOperatorControl() && IsEnabled())
{
// drive with arcade style (use right stick)
drivetrain->TankDrive(lstick, rstick);
//float joystick_y = stick->GetY();
//float joystick_x = stick->GetX();
}
}
/*
* Runs during test mode
*/
void Test() override {
}
}
};
START_ROBOT_CLASS(Robot)