Errors with VictorSPs

Hello,

We are having some issues with our code. We are using SampleRobot. We’re trying to declare and initialize 2 joysticks, 4 VictorSPs, and a RobotDrive. The code built with no errors, but as soon as we tried to deploy, our code started getting errors, some of which are:

  • ‘VictorSP’ does not name a type
  • ‘lmotor1’ was not declared in this scope
  • expected type-specifier before ‘VictorSP’

These errors were given for each VictorSP that we were trying to code for. Any ideas for what we’re missing? 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>


using namespace frc; //<-- Parker added this 2/9/17
using namespace std;

class Robot: public SampleRobot {
	//frc::RobotDrive myRobot { 0, 1 }; // robot drive system --commented 2/10/17

	Joystick *lstick; // declaring left joystick
	Joystick *rstick; // declaring right joystick

	VictorSP *lmotor1;
	VictorSP *lmotor2;
	VictorSP *rmotor1;
	VictorSP *rmotor2;

	RobotDrive *drivetrain;

	//frc::Joystick stick { 0 }; // only joystick--commented 2/10/17
	//Joystick rstick{1}; //<-- Parker added this 2/9/17


	SendableChooser<string> chooser;


	const string autoNameDefault = "Default";
	const string autoNameCustom = "My Auto";

public:
	Robot() {
		//Note SmartDashboard is not initialized here, wait until RobotInit to make SmartDashboard calls
		drivetrain->SetExpiration(0.1);

		lstick = new Joystick(0); //initializing left joystick
		rstick = new Joystick(1); //initializing right joystick

		lmotor1 = new VictorSP(0);
		lmotor2 = new VictorSP(1);
		rmotor1 = new VictorSP(2);
		rmotor2 = new VictorSP(3);

		drivetrain = new RobotDrive(lmotor1, lmotor2, rmotor1, rmotor2);
	}

	void RobotInit() {

		chooser.AddDefault(autoNameDefault, autoNameDefault);
		chooser.AddObject(autoNameCustom, autoNameCustom);
		SmartDashboard::PutData("Auto Modes", &chooser);
	}


Update: we just tired “Debug as” and the errors went away. No idea why, but the code appears to be working now. Thanks!

It is possible that doing the ‘new’ of all of those objects in the Robot() constructor is simply “too early” in the lifecycle of the robot. I’d suggest that you should put those ‘new’ items into RobotInit() rather than Robot(). It may have worked in Debug as the timing of things change pretty drastically in debug. Make sure you can work in ‘Run As’ or you’ll be in a panic later on in the season…