Log in

View Full Version : Robotbuilder c++ code dies in Test Mode


rod@3711
17-01-2016, 13:22
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.

Joe Ross
17-01-2016, 15:23
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.

calcmogul
17-01-2016, 15:54
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.

Here's the code that causes the crash:

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

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.

Joe Ross
17-01-2016, 16:09
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);
}

rod@3711
17-01-2016, 17:09
Thanks, that worked for me.

Joe Ross
18-01-2016, 10:38
I submitted a patch for review for this for Robot Builder.

rod@3711
20-01-2016, 15:49
How do I find out when or if Robot Builder gets revised?

Joe Ross
20-01-2016, 20:59
New software releases are mentioned in team updates, or you can watch one of these pages on screensteps: http://wpilib.screenstepslive.com/s/4485/m/13503/l/305566-current-software-revisions or http://wpilib.screenstepslive.com/s/4485/m/13810/l/483574-c-java-plugin-changelog

Joe Ross
24-01-2016, 22:03
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.

rod@3711
24-01-2016, 23:05
Did a quick test and it works. Thanx a lot...

rod@3711
25-01-2016, 00:10
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->AddActuator("Subsystem 1", "Speed Controller 1", (Talon&) subsystem1SpeedController1); // <<< this caused Test Mode to abort

new robot builder

static std::shared_ptr<SpeedController> subsystem1SpeedController1; // <<< this causes a build error

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

Joe Ross
25-01-2016, 00:49
Try this version

rod@3711
25-01-2016, 10:15
Try this version

Looks right. I will test on robot this afternoon.

Thanx