View Single Post
  #5   Spotlight this post!  
Unread 24-03-2014, 12:14
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: How to change command associated with button

@jwakeman: your issue appears to be that your alternate condition was causing a new command to be created every iteration. This would cause a new command to be created, assigned to the button, and interrupt the old each iteration.

I haven't tried this code, but the pattern I used was like this:
Code:
<in class definition>
Command *mainCommand;
Command *altCommand;

<in constructor>
mainCommand = new MainCommand();
altCommand = new AlternativeCommand();

<in periodic function within the same class>
    if (condition)
    {
        button->whenPressed(altCommand);
    }
    else
    {
        button->whenPressed(mainCommand);
    }
This way, you have only have one instance of each command that can be assigned to the button.
I put this code in the OI class, and added an UpdateOI function, which is called from the teleop periodic loop.

Last edited by DjScribbles : 24-03-2014 at 12:20.
Reply With Quote