Compiling Issues in VS Code

Hi, so I was trying to upload some simple code into our robot, just to get it running using Tank Drive. The first time we uploaded, it was fine and our robot was able to run. We wanted to go back in to fix some things and only changed two lines of code. When we tried to upload once more we got this error:

The terminal process “cmd.exe /d /c gradlew deploy -PteamNumber=6914 --offline -Dorg.gradle.java.home=“C:\Users\Public\wpilib\2021\jdk”” terminated with exit code: 1.

When we scrolled up we got:

Task :compileFrcUserProgramLinuxathenaReleaseExecutableFrcUserProgramCpp FAILED
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:15:54: error: expected identifier before numeric constant
ctre::phoenix::motorcontrol::can::WPI_TalonSRX leftf(1);
^
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:15:54: error: expected ‘,’ or ‘…’ before numeric constant
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:16:54: error: expected identifier before numeric constant
ctre::phoenix::motorcontrol::can::WPI_TalonSRX leftb(5);
^
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:16:54: error: expected ‘,’ or ‘…’ before numeric constant
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:19:55: error: expected identifier before numeric constant
ctre::phoenix::motorcontrol::can::WPI_TalonSRX rightf(2);
^
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:19:55: error: expected ‘,’ or ‘…’ before numeric constant
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:20:55: error: expected identifier before numeric constant
ctre::phoenix::motorcontrol::can::WPI_TalonSRX rightb(4);
^
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:20:55: error: expected ‘,’ or ‘…’ before numeric constant
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:25:26: error: expected identifier before numeric constant
frc::Joystick rightstick(1);
^
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:25:26: error: expected ‘,’ or ‘…’ before numeric constant
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:17:49: error: could not convert ‘{((Robot*)this)->Robot::leftf, ((Robot*)this)->Robot::leftb}’ from ‘’ to ‘frc::SpeedControllerGroup’
frc::SpeedControllerGroup leftDrive{leftf, leftb};
^
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:21:52: error: could not convert ‘{((Robot*)this)->Robot::rightf, ((Robot*)this)->Robot::rightb}’ from ‘’ to ‘frc::SpeedControllerGroup’
frc::SpeedControllerGroup rightDrive{rightf, rightb};
^
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp: In member function ‘virtual void Robot::TeleopPeriodic()’:
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:37:25: error: ‘rightStick’ was not declared in this scope
tankDrive.TankDrive(rightStick.GetX(), rightStick.GetY());
^~~~~~~~~~
C:\Users\Beta\Documents\VS Code 2021\6914 Drivetrain Test Code\src\main\cpp\Robot.cpp:37:25: note: suggested alternative: ‘rightstick’
tankDrive.TankDrive(rightStick.GetX(), rightStick.GetY());
^~~~~~~~~~
rightstick

Compilation Error!
GradleRIO detected this build failed due to a Compile Error (compileFrcUserProgram).
Check that all your files are saved, then scroll up in this log for more information.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:compileFrcUserProgramLinuxathenaReleaseExecutableFrcUserProgramCpp’.
    A build operation failed.
    C++ compiler failed while compiling Robot.cpp.
    See the complete log at: file:///C:/Users/Beta/Documents/VS%20Code%202021/6914%20Drivetrain%20Test%20Code/build/tmp/compileFrcUserProgramLinuxathenaReleaseExecutableFrcUserProgramCpp/output.txt
    C++ compiler failed while compiling Robot.cpp.

We have tried opening a new project and retyping everything, but the same issue came up. Not sure where to go from here. Thanks!

1 Like

Your file paths suggest you haven’t updated everything for 2022. There are a number of changes this year.

Compilers can be easily confused by seemingly simple things. For example, if you forget to close a comment block, it will comment out anything between that and the next end comment block, causing compiler failures in anything that using something declared in the now commented out code. You can get similar issues with string literals. For example printf(“abd”"); will cause issues. Even things like missing semicolons can cause downstream issues.

If you really only changed two lines, then the problem should be in one of those two lines. However, it’s unlikely that we can help further without seeing the full code.

Here is our full code.

// Copyright (c) FIRST and other WPILib contributors.

// Open Source Software; you can modify and/or share it under the terms of

// the WPILib BSD license file in the root directory of this project.

#include <frc/Joystick.h>

#include <frc/TimedRobot.h>

#include <ctre/phoenix/motorcontrol/can/WPI_TalonSRX.h>

#include <frc/drive/DifferentialDrive.h>

#include <frc/SpeedControllerGroup.h>

class Robot : public frc::TimedRobot {

ctre::phoenix::motorcontrol::can::WPI_TalonSRX leftf(1);

ctre::phoenix::motorcontrol::can::WPI_TalonSRX leftb(5);

frc::SpeedControllerGroup leftDrive{leftf, leftb};

ctre::phoenix::motorcontrol::can::WPI_TalonSRX rightf(2);

ctre::phoenix::motorcontrol::can::WPI_TalonSRX rightb(4);

frc::SpeedControllerGroup rightDrive{rightf, rightb};

frc::DifferentialDrive tankDrive{leftDrive, rightDrive};

frc::Joystick rightstick(1);

public:

void RobotInit() override {

// We need to invert one side of the drivetrain so that positive voltages

// result in both sides moving forward. Depending on how your robot's

// gearbox is constructed, you might have to invert the left side instead.

rightDrive.SetInverted(true);

}

void TeleopPeriodic() override {

// Drive with tank style

tankDrive.TankDrive(rightStick.GetX(), rightStick.GetY());

}

};

#ifndef RUNNING_FRC_TESTS

int main() {

return frc::StartRobot();

}

#endif

What two lines did you change?

One problem is that you defined “rightstick” (with a lowercase ‘s’) but then tried to use it as “rightStick” (with an uppercase ‘S’ in two places on line 37). C/C++ is really picky about that, and sees those two character strings as completely different (though in the error it gave, it did say what it thought you meant). You could change the definition line to
frc::Joystick rightStick(1);

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.