Transfer of Eclipse Files to VSCode

So we just installed VSCode and all WPILib libraries onto our Windows 10 MSi computer for C++. We then learned that all of our work in Eclipse could be transferred over to VSCode. We followed all instructions on the FRC website, but all files that our codes were on (Mainly Robot.cpp) didn’t appear in the folders associated with them. So we just copied and pasted the code into a new workspace, but turns out, syntax and libraries are a bit different in VSCode than in Eclipse.

How do we just transfer work over, and figure out correct syntax while trying to keep most of it intact?

Thanks,
Team 2148

The files are located in a different spot then previous years, but the syntax hasn’t really changed. The eclipse importer puts your robot code in src/main/cpp. What errors are you getting exactly? Can you post screenshots?

Or post the code that you’re trying to import.

Since you’re using C++, the most common syntax thing teams are running into is the removal of the “using namespace frc;” shim from WPILib. You can either add this line to your source/header files (not recommended) or (recommended) add “frc::” in front of any wpilib class name (e.g. “Victor” becomes (“frc::Victor”).

#include
#include
#include <CameraServer.h>
#include <IterativeRobot.h>
#include <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
#include <Joystick.h>
#include <WPILib.h>
#include <Ultrasonic.h>
#include <Commands/Command.h>
#include <Commands/Scheduler.h>

class Robot : public frc::IterativeRobot {
public:
Joystick *stick;
frc::Spark *motor1;
frc::Spark *motor2;
frc::Spark *motor3;
frc::Spark *motor4;
frc::Spark *motor5;

frc::Spark *motors [7];
//--PIN INDEX DEFINITIONS
int PIN_LEFT_MOTOR = 2;
int PIN_RIGHT_MOTOR = 3;
int PIN_CLIMB_MOTOR = 5;
int PIN_CLIMB_MOTOR2 = 1;
int PIN_LEFT_ARM = 4;
int PIN_RIGHT_ARM = 0;
int PIN_LIMIT_TOP = 0;
int PIN_LIMIT_BOTTOM = 1;

int JS_BTN_A = 1;
int JS_BTN_B = 2;
int JS_BTN_X = 3;
int JS_BTN_Y = 4;
int JS_BTN_BACK = 7;
int JS_BTN_START = 8;
int JS_BTN_LEFT_TOGGLE = 9;
int JS_BTN_RIGHT_TOGGLE = 10;
int JS_BTN_LEFT_BUMPER = 5;
int JS_BTN_RIGHT_BUMPER = 6;

int JS_AXIS_LTOGGLE_X = 0;
int JS_AXIS_LTOGGLE_Y = 1;
int JS_AXIS_RTOGGLE_X = 4;
int JS_AXIS_RTOGGLE_Y = 5;
int JS_AXIS_LEFT_TRIGGER = 2;
int JS_AXIS_RIGHT_TRIGGER = 3;
//--

double SENSITIVITY_DEFAULT = 0.05;
double SENSITIVITY_BOOST = 0.5;

frc::Spark *motor_left;
frc::Spark *motor_right;
frc::Spark *motor_climb;
frc::Spark *motor2_climb;
frc::Spark *motor_arm_left;
frc::Spark *motor_arm_right;
frc::DigitalInput *limit_top;
frc::DigitalInput *limit_bottom;

frc::ADXRS450_Gyro  *gyro;
frc::DigitalInput *climb;
frc::Ultrasonic *ultra;
double startangle;

//int curr_position = 0;
//bool a_press = false;

//AUTONOMOUS PARAMETERS
int auto_counter = 0;
double curr_speed = 0;
int AUTO_DURATION = 100;
double AUTO_DELAY = 0.05;
double AUTO_SPEED = -0.4;

void RobotInit() {
	m_chooser.AddDefault(kAutoNameDefault, kAutoNameDefault);
	m_chooser.AddObject(kAutoNameCustom, kAutoNameCustom);
	frc::SmartDashboard::PutData("Auto Modes", &m_chooser);
	CameraServer::GetInstance()->StartAutomaticCapture();

	/*for (int i=0; i<sizeof(motors); i++) {
		if (motors[i] == NULL) {
			motors[i] = new frc::Spark(i);
		}
	}*/

	//REV 2
	if (!motor_left) {
		motor_left = new frc::Spark(PIN_LEFT_MOTOR);
	}
	if (!motor_right) {
		motor_right = new frc::Spark(PIN_RIGHT_MOTOR);
	}
	if (!motor_climb) {
		motor_climb = new frc::Spark(PIN_CLIMB_MOTOR);
	}
	if (!motor2_climb) {
		motor2_climb = new frc::Spark(PIN_CLIMB_MOTOR2);
	}
	if (!motor_arm_right) {
		motor_arm_right = new frc::Spark(PIN_RIGHT_ARM);
	}
	if (!motor_arm_left) {
		motor_arm_left = new frc::Spark(PIN_LEFT_ARM);
	}
	if (!limit_top) {
		limit_top = new frc::DigitalInput(PIN_LIMIT_TOP);
	}
	if (!limit_bottom){
		limit_bottom = new frc::DigitalInput(PIN_LIMIT_BOTTOM);
	}
	//INVERT MOTORS
	//motor_left->SetInverted(true);
	motor_right->SetInverted(true);
	//motor_climb->SetInverted(true);
	//motor_arm_right->SetInverted(true);
	motor_arm_left->SetInverted(true);

	//NEEDED CODE
	/*if (motor1 == NULL) {
		motor1 = new frc::Spark(0);
	}
	if (motor2 == NULL) {
		motor2 = new frc::Spark(1);
	}
	if (motor3 == NULL) {
		motor3 = new frc::Spark(2);
	}
	if (motor4 == NULL) {
		motor4 = new frc::Spark(3);
	}
	if (motor5 == NULL){
		motor5 = new frc::Spark(4);
	}
	*/
	if (stick == NULL) {
		stick = new frc::Joystick(0);
	}
	/*if (climb == NULL) {
		climb = new frc::DigitalInput(0);
	}*/
	/*if (gyro == NULL) {
		gyro = new frc::ADXRS450_Gyro(0);
	}
	ultra = new Ultrasonic(1, 1);
	ultra->SetAutomaticMode(true);
		}*/
	}
/*
 * 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.
 */
void AutonomousInit() override {

}
//int i = 0;
void AutonomousPeriodic() {
	//NEEDED CODE
	/*frc::Wait(.05);
	i = i+1;
	if (i >= 85){
		motor1->Set(0);
		motor2->Set(0);
		motor3->Set(0);
		motor4->Set(0);
	}else {
		motor1->Set(-.2);
		motor2->Set(-.2);
		motor3->Set(.2);
		motor4->Set(.2);
	}*/
	curr_speed = (auto_counter < AUTO_DURATION) ? AUTO_SPEED : 0;
	Drive(curr_speed, 0, false);
	auto_counter++;
	Wait(AUTO_DELAY);
}


void TeleopInit() {

}

void TeleopPeriodic() {
	/*
	//NEEDED CODE
	double sense = 0.4;
	double speed = 0;
	double lift = 0;
	bool X = stick->GetRawButton(3);
			if (X){
				speed = 0.5;
			}
	bool B = stick->GetRawButton(2);
			if (B){
				speed = -0.5;
			}
	bool A = stick->GetRawButton(1);
			if (A) {
				lift = -0.5;
			}
	double jyv = stick->GetRawAxis(1)*sense;
	double jxv = stick->GetRawAxis(0)*sense;
	double Y = stick->GetRawButton(4);
			if (Y) {
				lift = 0.5;
			}
	motor1->Set(speed);
	motor2->Set(jyv+jxv);
	motor3->Set(lift);
	motor4->Set(-jyv+jxv);
	motor5->Set(speed);
	*/

	//---MOTOR TEST---
	/*bool a_curr_press = stick->GetRawButton(1);
	if (a_curr_press && !a_press) {
		//Switch PWM
		curr_position = (curr_position + 1) % 7;
	}
	double jyv = stick->GetRawAxis(1);
	motors[curr_position]->Set(jyv);
	frc::SmartDashboard::PutNumber("PWM_INDEX", curr_position);
	a_press = a_curr_press;*/
	//---END OF MOTOR TEST---

	//REV 2
	double y = stick->GetRawAxis(JS_AXIS_LTOGGLE_Y)*-.65;
	double x = stick->GetRawAxis(JS_AXIS_LTOGGLE_X)*.65;
	double climb = (double) stick->GetRawAxis(JS_AXIS_LEFT_TRIGGER)*1 - (double) stick->GetRawAxis(JS_AXIS_RIGHT_TRIGGER)*1;
	bool lim_top = limit_top->Get();
	bool lim_bottom = limit_bottom->Get();
	double arms = stick->GetRawButton(JS_BTN_A)*.9 - stick->GetRawButton(JS_BTN_Y)*.9;
	bool boost = false;
	Drive(y, x, boost);
	climb = (lim_top && climb < 0) ? 0 : climb;
	climb = (lim_bottom && climb > 0) ? 0 : climb;
	motor_climb->Set(climb);
	motor2_climb->Set(climb);
	motor_arm_right->Set(arms);
	motor_arm_left->Set(arms);

	/*bool X = stick->GetRawButton(3);
	if (X) {
		motor1->Set(-0.3);
		motor2->Set(-0.3);
		motor3->Set(-0.3);
		motor4->Set(-0.3);
	}
	bool B = stick->GetRawButton(2);
	if (B) {
		motor1->Set(0.3);
		motor2->Set(0.3);
		motor3->Set(0.3);
		motor4->Set(0.3);
	} else {
		motor1->Set(0);
		motor2->Set(0);
		motor3->Set(0);
		motor4->Set(0);
	}
	bool S = stick->GetRawButton(8);
	bool L = climb->Get();
	if (S) {
		motor5->Set(-0.5);
	} else if (Y && L){
		motor5->Set(0.5);
	} else {
		motor5->Set(0);
	}
	frc::SmartDashboard::PutBoolean("L", L);*/

	/*bool B = stick->GetRawButton(2);
				if (B) {
				if (range <= 12){
					motor1->Set(0);
					motor2->Set(0);
					motor3->Set(0);
					motor4->Set(0);
					motor5->Set(0.5);

				}
				else {
					motor5->Set(0);
				}
}*/
}
void Drive(double forward, double side, bool boost) {
	bool sense = boost ? SENSITIVITY_BOOST : SENSITIVITY_DEFAULT;
	motor_left->Set((forward + side) * sense);
	motor_right->Set((forward - side) * sense);
}

/*void SetLeftMotors(double speed) {
	motor1->Set(speed);
	motor2->Set(speed);
}
void SetRightMotors(double speed) {
	motor3->Set(-speed);
	motor4->Set(-speed);
}
void Drive(double ve, double rotate){
	SetLeftMotors(ve + rotate);
	SetRightMotors(ve - rotate);
}
void Turn(double speed) {
	SetLeftMotors(speed);
	SetRightMotors(-speed);
}*/
void TestPeriodic() {}

private:
frc::LiveWindow& m_lw = *LiveWindow::GetInstance();
frc::SendableChooserstd::string m_chooser;
const std::string kAutoNameDefault = “Default”;
const std::string kAutoNameCustom = “My Auto”;
std::string m_autoSelected;
};

START_ROBOT_CLASS(Robot)

Blank include spaces are Iostream and String

This is unrelated, but you can use triple-backticks standalone on a line to denote blocks of code in posts on CD (Markdown syntax). This makes it so brackets don’t get hidden and the overall format is much easier to read.

What errors are you getting when you compile the code?