SendableChoosers are causing me grief!

Hello! My name is Eric, and I am the lead programmer for team 3236. This is my first year, and so far, things are going good!

I am attempting to add radio buttons to my SmartDashboard so that I can choose the autonomous mode to run at a specific time. I am running it through a Command based system, as it seemed the easiest and most logical to my head.

In Eclipse, functions like “AddDefault” or “AddObject” do not work when written like this:


private:
		Teleop *TeleopControls;
		SendableChooser<Command *> *autonomouschooser;
		Command *autonomousCommand;



		virtual void RobotInit() override {
			autonomouschooser->AddDefault("Basic Auto", new AutoDefault());
			SmartDashboard::PutData("Chooser", autonomouschooser);
		}

However, Eclipse recognizes these functions when the code is written as such:


private:
		Teleop *TeleopControls;
		SendableChooser *autonomouschooser;
		Command *autonomousCommand;



		virtual void RobotInit() override {
			autonomouschooser->AddDefault("Basic Auto", new AutoDefault());
			SmartDashboard::PutData("Chooser", autonomouschooser);
		}

In this case, I get the error “invalid use of template-name ‘frc::SendableChooser’ without an argument list”.

I know that this is not because of an issue of “AutoDefault()” not existing, or anything along those lines.

If anyone has a possible solution or explanation, we’d greatly appreciate it!

Thank you!
-Eric

This worked for us:

In Robot.h


private:
    frc::SendableChooser<frc::Command*> autoChooser;
    std::unique_ptr<frc::Command> selectedMode;

In Robot.cpp


Robot::RobotInit() {
    autoChooser.AddDefault("Do Nothing", new DoNothing(15));
    autoChooser.AddObject("Gear Align Center", new GearAlignCenter());

    SmartDashboard::PutData("Auto Chooser", &autoChooser);
}

Robot::AutonomousInit() {
    selectedMode.reset(autoChooser.GetSelected());
    if(selectedMode != nullptr) {
        selectedMode->Start();
    }
}

Good luck with the season!

Best Wishes,
Drew

Are you including any other libraries? I get some errors with that setup.

Thanks for the quick reply btw!

I’m including

#include “WPILib.h”
#include “RobotMap.h”

in Robot.h

and

#include “Robot.h”

in Robot.cpp

What is the error your getting?

I get the errors “Symbol SendableChooser could not be resolved” and “Type ::Command could not be resolved”

I’ve actually gone and fixed these issues. When I write the code as you did, I get an error on SmartDashboard::PutData(“Auto modes”, &autonomousChooser);

The error I have is:

invalid arguments
Candidates are:
void PutData(llvm::StringRef, frc::Sendable *)
void PutData(frc::NamedSendable *)

autonomousChoose was defined as a pointer already “SendableChooser<Command *> *autonomousChooser”

while the other team’s example was NOT a pointer (no * before the variable name).

As such, PutData is looking for a pointer to be sent to it… so you should not preceed it with & but instead just give the name of the variable (the pointer). The other team needs the & in order to give an address (pointer) to PutData. I believe if you remove the & you’ll be good there.

BTW, don’t forget to ‘new’ any pointers before using them and ‘delete’ them at the end in some destructor like ~Robot()