Go to Post To offer an opinion is fine, to demand that others adhere to your opinion is laughable. - JVN [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-12-2012, 22:17
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Implementing a switchable control scheme

Our team would like to be able to switch between control schemes (for the drivetrain) as a way to easily find out what our potential drivers are most comfortable with. There's also potential situations on the field where we might want to switch to tank for a maneuver with the push or click of a button. The problem is, I really have no idea how to translate this into code. Some of the stuff is obvious, such as using a SendableChooser, but the rest is questionable. I have a few ideas, but no way to test them since our cRIO died and we're awaiting a replacement.

We're using command-based, fyi.

To the teams that have done this before: how did you do it?
And to people who haven't: what do you feel is the best way to accomplish this?
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
  #2   Spotlight this post!  
Unread 03-12-2012, 22:53
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Implementing a switchable control scheme

Assuming you use Java (I deduced from your previous posts), the best OOP way to do something like this is to attach something of a "Drive" class to the SendableChooser, and have "TankDrive", "ArcadeDrive", etc. classes to represent the different driving techniques. With this you can just have an abstract method like "drive(Joystick)" and call that (based on the SendableChooser or something like that).

Otherwise, you can use a state machine do the work for you, and have a Smartdashboard (or Preferences - which would be better suited) field called driver type. (We did that last year, worked out fine)
__________________
All opinions are my own.
  #3   Spotlight this post!  
Unread 03-12-2012, 23:04
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: Implementing a switchable control scheme

I can't say anything about the command structure, but in LabVIEW and C I've done similar things several times. Here is how I did it:

In LV, I created blocks to calculate each of the possible left/right pairs then a Switch to pick the correct one (this is approximately equivalent to an If and Else in C), using a boolean latch to store the chosen state. The code in LV was approximately equivalent to an If and Else in C (actually, I believe you would need 3 Ifs and 1 Else to do the entire thing including boolean latch). Other variations required a single switch to be held to switch modes. All of this would be wrapped into its own block which accepts the HMI data struct and outputs a drivetrain pair struct. I could drop in other blocks at will with minimal issue.

For a similar system of more than two modes, in LV or C, I would likely create an enumerated typedef to store the currently selected mode, calculate all possible pairs (which are stored in a pair struct) and shove them into an array, and index the array by the enum. The enum would be selected using a similar stack of LV Switches per button. The single Switch is slightly more elegant for a 2-choice solution than an array with index.


As for the lack of cRio, I like testing code on my laptop on a software test harness. Usually in LV I just take the core VI and write a computer-target VI to simulate the IO and display the output, it seems like it would be significantly harder to do in C++ or Java, but still doable.

In all cases that I have used, I was simply reversing the drivetrain, to drive backwards with trigger. We don't do that any more with the Halo drive, since you only have to move one thumb stick instead of two full-sized joysticks.

While it's perfectly fine (and highly encouraged) to experiment with multiple interfaces prior to heavy driver training, I highly recommend removing this functionality from the competition code so you don't confuse your drivers more. A well tuned driver input algorithm should not require any additional driver input, or be significantly modal.

As for the command-based implementation, I can't help there. I generally do embedded systems work in Simulink, we use state machines and lookup tables rampantly.
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack
  #4   Spotlight this post!  
Unread 03-12-2012, 23:15
MichaelBick MichaelBick is offline
Registered User
FRC #1836 (MilkenKnights)
Team Role: Alumni
 
Join Date: Oct 2011
Rookie Year: 2010
Location: Los Angeles
Posts: 734
MichaelBick has a brilliant futureMichaelBick has a brilliant futureMichaelBick has a brilliant futureMichaelBick has a brilliant futureMichaelBick has a brilliant futureMichaelBick has a brilliant futureMichaelBick has a brilliant futureMichaelBick has a brilliant futureMichaelBick has a brilliant futureMichaelBick has a brilliant futureMichaelBick has a brilliant future
Re: Implementing a switchable control scheme

I'm not a programmer, but you may want to take a look at 254's 2012 code. They had different drive modes(the two notable teleop ones being Cheesy Drive and and a drive lock). It is a different purpose than what you are looking to do but I'm pretty it was built so that it is easily repurposable.
__________________
Team 1836 - The Milken Knights
2013 LA Regional Champions with 1717 and 973
2012 LA Regional Finalists with 294 and 973
To follow Team 1836 on Facebook, go to http://www.facebook.com/MilkenKnights
To go to our website, go to http://milkenknights.com/index.html
  #5   Spotlight this post!  
Unread 04-12-2012, 00:08
ttldomination's Avatar
ttldomination ttldomination is offline
Sunny
no team
Team Role: Mentor
 
Join Date: Mar 2007
Rookie Year: 2007
Location: Roanoke, TX
Posts: 2,066
ttldomination has a reputation beyond reputettldomination has a reputation beyond reputettldomination has a reputation beyond reputettldomination has a reputation beyond reputettldomination has a reputation beyond reputettldomination has a reputation beyond reputettldomination has a reputation beyond reputettldomination has a reputation beyond reputettldomination has a reputation beyond reputettldomination has a reputation beyond reputettldomination has a reputation beyond repute
Re: Implementing a switchable control scheme

We did it previously using a simple toggle button. Press A on the controller and front is front, press A again and now front is back.

Code wise, it's simply a logical variable that toggles every time you hit a button. (logVar = !logVar).

Implementation wise, this is perhaps a wise decision for testing, but not as useful to swap control schemes during actual matches, unless of course, your drivers are super used to it.

- Sunny G.
  #6   Spotlight this post!  
Unread 12-12-2012, 22:13
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Implementing a switchable control scheme

I am running Java, just for the record.

So I have this in OI:

Code:
public void switcher() {
        driveSwitch = new SendableChooser();
        driveSwitch.addDefault("Joystick Arcade (1)", new JoystickArcade());
        driveSwitch.addDefault("Joystick Arcade (2)", new DualJoystickArcade());
        driveSwitch.addDefault("Joystick Tank", new DualJoystickTank());
        driveSwitch.addObject("Kinect", new KinectCommand());
        SmartDashboard.putData("Drive Switch", driveSwitch);  
    }
And this in RobotMain:

Code:
public void testInit() {
        autonomousCommand.cancel();
        teleopCommand.cancel();
        msg.printLn("[mode] Dev");
        CommandBase.oi.initLiveWindow();
        msg.printLn("[status] LiveWindow initialized");
        CommandBase.oi.switcher();
        
        driveCommand = (Command) CommandBase.oi.driveSwitch.getSelected();        
        driveCommand.start();                
    }
    
    public void testPeriodic() {
        LiveWindow.run();      
    }

This code would allow it to switch, but it would require switching modes beforehand. My question is, how should I set it up to be able to switch modes on the fly? I feel like calling driveCommand.start() over and over in testPeriodic wouldn't work so well, but I have no idea. How should I check the current state of the SendableChooser against the current command running?
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional

Last edited by F22Rapture : 12-12-2012 at 22:24.
  #7   Spotlight this post!  
Unread 12-12-2012, 22:58
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Implementing a switchable control scheme

If you want that sort of functionality (on-the-fly) there are three options I can think of.

1. Update scheme periodically (lots of bandwidth - we did this last year and it was a bad idea)

2. Making a dashboard static widget that sends data through NetworkTable to the code and have your code adjust only when that data is sent. (I wouldn't know where to start on this kind of implementation - if you figure it out, PM me. We're looking at doing this)

3. Have a button on the joystick change schemes (ex. back button on xbox controller). No extra bandwidth required. (well, minute compared to smartdashboard)

My recommendation for less work though it to have it update every time teleop starts. It may cause some frustrations testing, but during competition I would hope you don't switch schemes mid-match.
__________________
All opinions are my own.
  #8   Spotlight this post!  
Unread 12-12-2012, 23:09
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Implementing a switchable control scheme

Quote:
Originally Posted by joelg236 View Post
If you want that sort of functionality (on-the-fly) there are three options I can think of.

My recommendation for less work though it to have it update every time teleop starts. It may cause some frustrations testing, but during competition I would hope you don't switch schemes mid-match.
Well, we have it under "test mode" (new to 2013) so that couldn't happen during comp.
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
  #9   Spotlight this post!  
Unread 12-12-2012, 23:11
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Implementing a switchable control scheme

Quote:
Originally Posted by F22Rapture View Post
Well, we have it under "test mode" (new to 2013) so that couldn't happen during comp.
What is test mode? I haven't had time to check out 2013 features yet.
__________________
All opinions are my own.
  #10   Spotlight this post!  
Unread 12-12-2012, 23:23
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Implementing a switchable control scheme

Quote:
Originally Posted by joelg236 View Post
What is test mode? I haven't had time to check out 2013 features yet.
http://wpilib.screenstepslive.com/s/...sing-test-mode
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Closed Thread


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:27.

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