Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   SendableChoosers are causing me grief! (http://www.chiefdelphi.com/forums/showthread.php?t=154291)

ebernerrd 26-01-2017 16:43

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:
Code:

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:
Code:

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

jreneew2 26-01-2017 17:22

Re: SendableChoosers are causing me grief!
 
This worked for us:

In Robot.h
Code:

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

In Robot.cpp
Code:

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

ebernerrd 26-01-2017 17:38

Re: SendableChoosers are causing me grief!
 
Are you including any other libraries? I get some errors with that setup.

Thanks for the quick reply btw!

jreneew2 26-01-2017 17:56

Re: SendableChoosers are causing me grief!
 
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?

ebernerrd 27-01-2017 14:24

Re: SendableChoosers are causing me grief!
 
Quote:

Originally Posted by jreneew2 (Post 1636809)
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"

ebernerrd 28-01-2017 14:16

Re: SendableChoosers are causing me grief!
 
Quote:

Originally Posted by ebernerrd (Post 1637142)
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 *)

bob.wolff68 29-01-2017 13:16

Re: SendableChoosers are causing me grief!
 
Quote:

Originally Posted by ebernerrd (Post 1637463)
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()


All times are GMT -5. The time now is 09:56.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi