Anyone encounter this. I’m monkeying around with command based c++ code. I’ve added a command to the dashboard so I can test in the simulator. The command shows up but the button to run it does not. I’m getting Unknown Command where the button should be
If the CommandPtr goes out of scope, the command is destroyed (it’s a wrapper around std::unique_ptr), so the Command* passed to PutData is a dangling pointer. You will need to store the CommandPtr somewhere in the RobotContainer instance so it doesn’t go out of scope.
That’s not the correct way to build a vector of CommandPtr. The CommandPtr’s need to be moved into the vector (they’re not copyable). You also have to move the vector into the sequence. So the last two lines become:
std::vector<frc2::CommandPtr> commandVector{std::move(resetControllerCommandPtr), std::move(turnToPositionCommandPtr)};
auto command = frc2::cmd::Sequence(std::move(commandVector));
And upon running the simulator I got this error after the simulator immediately crashed
Error at frc2::CommandPtr::AssertValid [CommandPtr.cpp:28]: Illegal use of Command: Moved-from CommandPtr object used!
Error at frc::impl::RunRobot: Error: The robot program quit unexpectedly. This is usually due to a code error.
So FinallyDo() is only available on rvalues (it’s a && overload). It’s also directly available on CommandPtr. So you need to do something like: auto shutOff = std::move(driveAtVelocityCommandPtr).FinallyDo(end);
Most of these functions are designed to be chained in a single statement, not stored in variables, which would avoid the need for all the std::move’s, e.g.