Robotbuilder c++ code dies in Test Mode

Finally got example robot programs to run after Plugin update. Thanx.

Now I tried the most simple RobotBuilder C++ code (one subsystem with one speed controller). exported, imported, built and deployed OK. When I select Test Mode then enable. The Drivers Station indicates Test Enabled for 1/2 second, then Test Disabled. The roborio Mode indicator goes Red, then Comm indicator Red, then Mode goes off and Comm goes back to green.

I’ve duplicated this. It has to do with the way the SpeedController object is cast to the

Here’s the code that causes the crash:

lw->AddActuator("Subsystem 1", "Speed Controller 1", (Talon&)subsystem1SpeedController1);

Here’s code that works:

lw->AddActuator("Subsystem 1", "Speed Controller 1", std::static_pointer_cast<Talon>(subsystem1SpeedController1));

I’m not a C++ guru, so I’m not sure if that’s the right method to cast the shared_pointer from a SpeedController to Talon or other class that implements a SpeedController.

I think std::static_pointer_cast will work here. The type is definitely a Talon, so std::dynamic_pointer_cast isn’t necessary. Note that the pointer passed in can’t be that of a stack allocated object or a double-free would occur later.

Is subsystem1SpeedController1 an object or pointer to an object? If the suggested code is correct, then subsystem1SpeedController1 is a pointer and casting to Talon& seems strange to me anyway.

Here’s the full code as RobotBuilder generated (minus the comments)

#include "RobotMap.h"
#include "LiveWindow/LiveWindow.h"

std::shared_ptr<SpeedController> RobotMap::subsystem1SpeedController1;
void RobotMap::init() {

    LiveWindow *lw = LiveWindow::GetInstance();

    subsystem1SpeedController1.reset(new Talon(0));
    lw->AddActuator("Subsystem 1", "Speed Controller 1", (Talon&) subsystem1SpeedController1);

Thanks, that worked for me.

I submitted a patch for review for this for Robot Builder.

How do I find out when or if Robot Builder gets revised?

New software releases are mentioned in team updates, or you can watch one of these pages on screensteps: or

I think there’s an eminent release of the eclipse plugins including robot builder with this fix. However, in the meantime, here’s a version with the fix.

Edit: see version below.

Did a quick test and it works. Thanx a lot…

Still have problem with the most simple c++ program built with new Robot Builder (one generic subsystem with one motor actuator).

old robot builder

std::shared_ptr<SpeedController> RobotMap::subsystem1SpeedController1; // <<< this is ok

lw-&gt;AddActuator("Subsystem 1", "Speed Controller 1", (Talon&) subsystem1SpeedController1); // &lt;&lt;&lt; this caused Test Mode to abort

new robot builder

static std::shared_ptr&lt;SpeedController&gt; subsystem1SpeedController1;  // &lt;&lt;&lt; this causes a build error

lw->AddActuator(“Subsystem 1”, “Speed Controller 1”, std::static_pointer_cast<Talon>(subsystem1SpeedController1)); // <<< this is OK

Try this version (4.43 MB) (4.43 MB)

Looks right. I will test on robot this afternoon.