Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Robotbuilder c++ code dies in Test Mode (http://www.chiefdelphi.com/forums/showthread.php?t=141975)

rod@3711 01-17-2016 01:22 PM

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.

Joe Ross 01-17-2016 03:23 PM

Re: Robotbuilder c++ code dies in Test Mode
 
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:

Code:

lw->AddActuator("Subsystem 1", "Speed Controller 1", (Talon&)subsystem1SpeedController1);
Here's code that works:
Code:

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 01-17-2016 03:54 PM

Re: Robotbuilder c++ code dies in Test Mode
 
Quote:

Originally Posted by Joe Ross (Post 1525449)
Here's code that works:
Code:

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.

Quote:

Originally Posted by Joe Ross (Post 1525449)
Here's the code that causes the crash:

Code:

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 01-17-2016 04:09 PM

Re: Robotbuilder c++ code dies in Test Mode
 
Quote:

Originally Posted by mathmogul (Post 1525471)
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)

Code:

#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 01-17-2016 05:09 PM

Re: Robotbuilder c++ code dies in Test Mode
 
Thanks, that worked for me.

Joe Ross 01-18-2016 10:38 AM

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

rod@3711 01-20-2016 03:49 PM

Re: Robotbuilder c++ code dies in Test Mode
 
How do I find out when or if Robot Builder gets revised?

Joe Ross 01-20-2016 08:59 PM

Re: Robotbuilder c++ code dies in Test Mode
 
New software releases are mentioned in team updates, or you can watch one of these pages on screensteps: http://wpilib.screenstepslive.com/s/...ware-revisions or http://wpilib.screenstepslive.com/s/...ugin-changelog

Joe Ross 01-24-2016 10:03 PM

Re: Robotbuilder c++ code dies in Test Mode
 
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 01-24-2016 11:05 PM

Re: Robotbuilder c++ code dies in Test Mode
 
Did a quick test and it works. Thanx a lot...

rod@3711 01-25-2016 12:10 AM

Re: Robotbuilder c++ code dies in Test Mode
 
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>(subsystem1SpeedCon troller1)); // <<< this is OK

Joe Ross 01-25-2016 12:49 AM

Re: Robotbuilder c++ code dies in Test Mode
 
1 Attachment(s)
Try this version

rod@3711 01-25-2016 10:15 AM

Re: Robotbuilder c++ code dies in Test Mode
 
Quote:

Originally Posted by Joe Ross (Post 1529630)
Try this version

Looks right. I will test on robot this afternoon.

Thanx


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

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