Go to Post To put it simply: An adult coach impacts a team for two minutes. An adult mentor impacts a team for a lifetime. - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-03-2015, 18:12
jfitz0807 jfitz0807 is offline
Registered User
FRC #2877 (Ligerbots)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Newton, MA
Posts: 66
jfitz0807 is an unknown quantity at this point
HELP! CommandGroup not working

We're at competition. We had a number of autonomous command groups coded, but we didn't get to test them on the competition bot until this morning. We're using the SmartDashboard chooser to select one for each match. At least, that was the plan.

It turns out that no matter what we try, even defining just a single commandGroup and not using the chooser, our robot runs through autonomousInit() and then goes into autonomousPeriodic(), but it never returns form the call to Scheduler::GetInstance()->Run(); We can't figure out what's going wrong. A printf right after the call never appears in the log, but the code is still running. The DriverStation still shows "Robot Code" green and we can still transition into and out of Teleop and even back into Auto. It's just that nothing happens on the robot. None of our Teleop commands from the joystick work and our camera feed doesn't work either.

If we change our autonomousCommand from a CommandGroup to a Command, it works.

Full disclosure: We used java last year and switched to C++ this year since we had more C++ mentors and our java programmers graduated last year. Since we didn't use C++ last year, we don't have a CommandBase class from which our Commands inherit. According to the documentation, this is not necessary this year.

I'm going to try to make a number of commands that explicitly chain other commands together by having one call the next it it's end() method as a workaround, but if anyone has any thoughts on how to make the CommandGroups work, that would be greatly appreciated.
Reply With Quote
  #2   Spotlight this post!  
Unread 13-03-2015, 18:25
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: HELP! CommandGroup not working

Can you post your code? At a minimum Robot.cpp?
__________________
http://team2168.org
Reply With Quote
  #3   Spotlight this post!  
Unread 13-03-2015, 18:31
jfitz0807 jfitz0807 is offline
Registered User
FRC #2877 (Ligerbots)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Newton, MA
Posts: 66
jfitz0807 is an unknown quantity at this point
Re: HELP! CommandGroup not working

Here are some code snippets:

In Robot.h:

class Robot : public IterativeRobot {
private:

public:
CommandGroup *autonomousCommand;
SendableChooser *chooser;
CommandGroup *autoCommand1Can;
CommandGroup *autoCommandMoveToZone;
CommandGroup *autoCommand1Can1Tote;
CommandGroup *autoCommandDoNothing;

Robot.cpp:

autoCommand1Can = new AutonomousCommand1Can();
autoCommandMoveToZone = new AutonomousMoveToZone();
autoCommand1Can1Tote = new AutonomousCommand1Can1Tote();
autoCommandDoNothing = new AutonomousEmpty();

// Stuff to get autonomous selection on SmartDashboard
chooser = new SendableChooser();
chooser->AddDefault("Can to Auto Zone", autoCommandMoveToZone);
chooser->AddObject("Drive to Auto Zone", autoCommand1Can);
chooser->AddObject("Drive to Auto Zone", autoCommand1Can1Tote);
chooser->AddObject("Do absolutely nothing", autoCommandDoNothing);
SmartDashboard:utData("Autonomous Modes",chooser);


Each of the commands is a CommandGroup in which we addSequential a series or other commands, each of which has been tested.

Thanks again for any help.
Reply With Quote
  #4   Spotlight this post!  
Unread 13-03-2015, 18:33
EmileH's Avatar
EmileH EmileH is offline
it's not a water game, ok?
AKA: Emile Hamwey
FRC #1058 (PVC Pirates) & FF (NE Way You Want It)
Team Role: Programmer
 
Join Date: Dec 2014
Rookie Year: 2011
Location: New England
Posts: 531
EmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant futureEmileH has a brilliant future
Re: HELP! CommandGroup not working

I have a feeling that your autonomous CommandGroup isn't ending. Try putting in a parallel waitcommand that goes for 14 seconds (or the length of your autonomous, whichever is smaller, because you want to leave time for the robot to kick back into the default autonomous).
__________________
2016-present: High School Student, FRC 1058 PVC Pirates
2016: RiverRage 20 Champions, Battle of the Bay 3 Champions

2013-2015: Middle School Student, FRC 3467 Windham Windup
Reply With Quote
  #5   Spotlight this post!  
Unread 13-03-2015, 18:47
cbf cbf is offline
Registered User
FRC #2877
 
Join Date: Feb 2012
Location: Newton, MA
Posts: 74
cbf is just really nicecbf is just really nicecbf is just really nicecbf is just really nicecbf is just really nice
Re: HELP! CommandGroup not working

You're welcome to all of it: https://github.com/ligerbots/Recycle...ree/dartFriday

Specifically, if look at line 149 of Robot.cpp in AutonomousInit(). You'll see a commented out line:

Code:
autonomousCommand = (CommandGroup *)new DrivePID(100.0, 100.0);
Note that DrivePID is a command (i.e. derives from the WPILib Command class). The assignment above shouldn't work. But it does. It's the only thing we've gotten to work in autonomous -- running a single command.

When we assign a class that instead derives from CommandGroup (so we can do things like AddSequential and AddParallel), which is how we thought this was supposed to work the first call to Scheduler::GetInstance()->Run(); in AutonomousPeriodic goes away and never returns. I traced a couple of instruction into it, and it definitely looks like its been passed a class other than what it expects and is thus calling through a random vtable pointer. We don't get a segfault, but nothing in the program runs after that.

The code at that Git repository right now is the code that fails (but that might change if I can find a fix tonight).

John and I have been trying to find examples of a working Iterative Robot C++ autonomous without success so far, but we'd be very happy if someone can look at our code and tell us we've done thing stupid and obvious..
Reply With Quote
  #6   Spotlight this post!  
Unread 13-03-2015, 18:48
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: HELP! CommandGroup not working

I don't see a problem with the excerpts provided. If you could provide a more complete set of code that would likely prove useful. (like the a command group and the commands which it's running)


Have you tried running one of the command groups that isn't working in auto mode from a joystick button.

Map the command group to a button in the OI class, enable in teleop mode. Press the button. If if you have the same problem, you have an issue in your command group or in one of the commands which it's calling. If you don't then there's something wrong with the way you're using the scheduler?

I can only guess at this point since I don't have a clear picture of what you're doing in your code.
__________________
http://team2168.org
Reply With Quote
  #7   Spotlight this post!  
Unread 13-03-2015, 18:49
jfitz0807 jfitz0807 is offline
Registered User
FRC #2877 (Ligerbots)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Newton, MA
Posts: 66
jfitz0807 is an unknown quantity at this point
Re: HELP! CommandGroup not working

Here's our autonomousPeriodic():

void Robot::AutonomousPeriodic() {
if (autoPeriodicCount++ < 4) {
printf("AutoPeriodic %d!\n", autoPeriodicCount);
}
else if (autoPeriodicCount==120) printf("AutoPeriodic still alive %d!\n", autoPeriodicCount);
Scheduler::GetInstance()->Run();
UpdateDashboardPeriodic();
Camera::Feed();
}

We only see the printf once. And the UpdateDashboardPeriodic and Camera::Feed are not getting called. The dashboard does not update and we don't get a camera image. Plus there are printfs in the Camera class that we don't see.

It looks like Scheduler::GetInstance()->Run() never returns, but we don;t get error messages to the console, riolog or even to the terminal if we explicitly run the FRCUserProgram from the linux shell. And it doesn't segfault either.
Reply With Quote
  #8   Spotlight this post!  
Unread 13-03-2015, 18:53
jfitz0807 jfitz0807 is offline
Registered User
FRC #2877 (Ligerbots)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Newton, MA
Posts: 66
jfitz0807 is an unknown quantity at this point
Re: HELP! CommandGroup not working

Our mechanical team is currently working some repairs so I can't try executing a commandGroup from a button. I will try as soon as practicable. That's a great suggestion.

Charles (CBF) has our Test Bot at home. I am still at the venue.
Reply With Quote
  #9   Spotlight this post!  
Unread 13-03-2015, 19:04
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: HELP! CommandGroup not working

For you auto modes, all the addSequential calls that you're making within the robotinit function should be made directly within the CommandGroup classes that you have in the Command package.

The commandgroup comments in wpilib for the addsequential function state that calls should be made in the constructor of the CommandGroup. I haven't gone through the source code to see why exactly, but if for nothing else it helps keep your code more organized/readable.
__________________
http://team2168.org
Reply With Quote
  #10   Spotlight this post!  
Unread 13-03-2015, 19:10
cbf cbf is offline
Registered User
FRC #2877
 
Join Date: Feb 2012
Location: Newton, MA
Posts: 74
cbf is just really nicecbf is just really nicecbf is just really nicecbf is just really nicecbf is just really nice
Re: HELP! CommandGroup not working

Quote:
Originally Posted by emileh3467 View Post
I have a feeling that your autonomous CommandGroup isn't ending. Try putting in a parallel waitcommand that goes for 14 seconds (or the length of your autonomous, whichever is smaller, because you want to leave time for the robot to kick back into the default autonomous).
Don't think so. None of the commands in our command groups seem to get run at all. Look at https://github.com/ligerbots/Recycle...ands/Delay.cpp -- a command that simply counts off a number of ticks and returns. We never see the output from the printf in the initialization method.

As I said above, the Scheduler::GetInstance()->Run(); in AutonomousPeriodic executes exactly once and never returns..
Reply With Quote
  #11   Spotlight this post!  
Unread 13-03-2015, 19:11
jfitz0807 jfitz0807 is offline
Registered User
FRC #2877 (Ligerbots)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Newton, MA
Posts: 66
jfitz0807 is an unknown quantity at this point
Re: HELP! CommandGroup not working

We had tried that first, but it was giving the same behavior. We were grasping at straws. The Orange Hat guys here thought it was worth a try so we gave it a go.
Reply With Quote
  #12   Spotlight this post!  
Unread 13-03-2015, 20:22
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,587
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: HELP! CommandGroup not working

At least one thing you're doing wrong is reusing Commands all over the place in your CommandGroups and such. For instance:
Code:
AddSequential(Robot::oi->canUp);
That's wrong. You can't reuse Commands like this, especially in CommandGroups. Here's the relevant code from WPILib:
Code:
void Command::Start()
{
	LockChanges();
	if (m_parent != NULL)
		wpi_setWPIErrorWithContext(CommandIllegalUse, "Can not start a command that is part of a command group");

	Scheduler::GetInstance()->AddCommand(this);
}
So once you call that CommandGroup constructor with that bad AddSequential, the command instance for your CanUp button gets a parent added to it and will no longer work because that instance now thinks it's part of a CommandGroup. So everywhere you have this design anti-pattern:
Code:
AddSequential(Robot::oi->canUp);
You should replace with something like:
Code:
AddSequential(new PositionElevator(1, true));
It's more annoying, but thems the breaks.

I'm still looking at other things. Your AutonomousInit is screwy. You're starting the ZeroElevator command in there. Twice. Commands ONLY run when Scheduler->Run() is called. It's never called in AutonInit, so that command only starts to run at the first call of AutonomousPeriodic. You've already added a CommandGroup requiring the elevator after that, so I'm pretty sure the Zero Elevator command gets immediately cancelled without even initializing.

I'm not sure about your idea for triggering commands from other commands. I've never needed to do it, so I have no idea if it will work.

My only other suggestion at the moment is to start up NetConsole, cause it gives you much more detailed debugging info and you might be able to tell what's hanging up the scheduler there.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
Reply With Quote
  #13   Spotlight this post!  
Unread 13-03-2015, 20:32
cbf cbf is offline
Registered User
FRC #2877
 
Join Date: Feb 2012
Location: Newton, MA
Posts: 74
cbf is just really nicecbf is just really nicecbf is just really nicecbf is just really nicecbf is just really nice
Re: HELP! CommandGroup not working

Kevin --

Thanks for looking at this. Actually, pretty much all the glitches you point out we've already fixed. Sorry for the confusion about branches, but the latest is at: https://github.com/ligerbots/Recycle...tialDartmouth2.

Note that one of the orange hats at the UMass Dartmouth meet today suggested moving the AddSequentials out of the autonomous class constructors, but it made no difference. I'll probably move them back in.

There are likely more errors to be discovered -- if could only at least get our autonomous command groups to be run..
Reply With Quote
  #14   Spotlight this post!  
Unread 13-03-2015, 21:13
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,587
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: HELP! CommandGroup not working

Putting kids to bed, so I can't delve deeper right now. I'll admit I was looking at things before your Friday commit so I could see what y'all were talking about. I'll try to have more thoughts in an hour or two. I'm suspicious of default commands you might be running hanging things.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
Reply With Quote
  #15   Spotlight this post!  
Unread 13-03-2015, 22:05
cbf cbf is offline
Registered User
FRC #2877
 
Join Date: Feb 2012
Location: Newton, MA
Posts: 74
cbf is just really nicecbf is just really nicecbf is just really nicecbf is just really nicecbf is just really nice
Re: HELP! CommandGroup not working

Well here's a new data point:

All of our Autonomous Command classes had a #include "../robot.h" in them (the students can be pretty sloppy about these things). I had meant to clean this up, but you know.. more important things like actually making the program work got in the way.

Simply out of suspicion, I decided to clean these up.

Now our "do nothing" autonomous command is successfully executed, but unfortunately the ones that actually do something still never return from
Scheduler::GetInstance()->Run();

I'm guessing that there was some C++ class, possibly even name confusion.

At least this is now looking less hopeless and somewhat debuggable. The tree has been updated with this.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:58.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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