Go to Post Don't you know anything about programming? It's a black box; you don't need to know how it works. - Chriszuma [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 24-02-2013, 20:03
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
methods for Switchable Autonomous Modes

Hello,

I have looked through much of the forums before Stop Build Date for the best and easiest switchable autonomous mode, but none seemed to work.

I use the Simple Robot Template for my code. (my entire cpp file code is posted below)

I noticed methods that are solely through the driver station (IO, Position, etc), and using something through that interface is preferred. I was unable to get any to work in the code (and was uncertain about the position selector).

My second choice would be a dip switch option on the robot itself. (Just I have never programmed inputs like those on the robot, and I still prefer the DS method).

Thanks,
Davis

Robot Code:
Code:
#include "WPILib.h"
#include "Math.h"
#include "stdlib.h"
#include "DriverStation.h"

class RobotDemo : public SimpleRobot
{
	RobotDrive R_myRobot;
	
	Joystick J_stick1;
	Joystick J_stick2;
	Joystick J_stick3;
	Joystick J_stick4;
	
	Relay M_standLeft;
	Relay M_standCenter;
	Relay M_standRight;
	
	Victor M_arm;
	
	Relay M_frisbeePusher;
	Relay M_frisbeeReleaser;

public:
	RobotDemo(void):
		R_myRobot(1, 2),
		
		J_stick1(1),
		J_stick2(2),
		J_stick3(3),
		J_stick4(4),
		
		M_standLeft(1),
		M_standCenter(3),
		M_standRight(2),
		
		M_arm(3),
		
		M_frisbeePusher(4),
		M_frisbeeReleaser(5)
	
	{	
		R_myRobot.SetExpiration(0.1);
	}

	void Autonomous(void)
	{		
		R_myRobot.SetSafetyEnabled(false);		
	}

	void OperatorControl(void)
	{
		R_myRobot.SetSafetyEnabled(true);
		
		// inverts the left motor
		R_myRobot.SetInvertedMotor(R_myRobot.kRearLeftMotor, true);
		// inverts the right motor
		R_myRobot.SetInvertedMotor(R_myRobot.kRearRightMotor, true);
		

		R_myRobot.Drive(0.0, 0.0);
		
		
		while (IsOperatorControl())
		{			
			
			// Drive
			R_myRobot.TankDrive(J_stick1, J_stick2);

			// Arm
			if(J_stick4.GetRawButton(1))
				M_arm.Set(J_stick4.GetY());
			else
				if(J_stick4.GetRawButton(2))
					M_arm.Set(J_stick4.GetY()*3/4);	
				else
					M_arm.Set(0.0);
			
			// frisbee pusher
			if(J_stick1.GetRawButton(1))
				M_frisbeePusher.Set(Relay::kForward);
			else
				if(J_stick1.GetRawButton(2))
					M_frisbeePusher.Set(Relay::kReverse);
				else
					M_frisbeePusher.Set(Relay::kOff);
			
			// frisbee Releaser
			if(J_stick2.GetRawButton(1))
				M_frisbeePusher.Set(Relay::kForward);
			else
				if(J_stick2.GetRawButton(2))
					M_frisbeePusher.Set(Relay::kReverse);
				else
					M_frisbeePusher.Set(Relay::kOff);
			
			// stand center
			if(J_stick4.GetRawButton(4))
				M_standCenter.Set(Relay::kForward);
			else
				if(J_stick4.GetRawButton(5))
					M_standCenter.Set(Relay::kReverse);
				else
					if(J_stick4.GetRawButton(3))
						M_standCenter.Set(Relay::kOff);
									
			// stand left + right
			if(J_stick3.GetRawButton(4))
			{
				M_standLeft.Set(Relay::kForward);
				M_standRight.Set(Relay::kForward);
			}
			else
			{
				if(J_stick3.GetRawButton(5))
				{
					M_standLeft.Set(Relay::kReverse);
					M_standRight.Set(Relay::kReverse);
				}
				else
				{
					if(J_stick3.GetRawButton(3))
					{
						M_standLeft.Set(Relay::kOff);
						M_standRight.Set(Relay::kOff);
					}
					else	
					{
						
						// stand left
						if(J_stick3.GetRawButton(6))
							M_standLeft.Set(Relay::kForward);
						else
						{
							if(J_stick3.GetRawButton(7))
								M_standLeft.Set(Relay::kReverse);
							else
							{
								if(J_stick3.GetRawButton(8))
									M_standLeft.Set(Relay::kOff);
							}
						}
						
						// stand right
						if(J_stick3.GetRawButton(11))
							M_standRight.Set(Relay::kForward);
						else
						{
							if(J_stick3.GetRawButton(10))
								M_standRight.Set(Relay::kReverse);
							else
							{
								if(J_stick3.GetRawButton(9))
									M_standRight.Set(Relay::kOff);
							}
						}
					}
				}
			}
			
			Wait(0.005);
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
Reply With Quote
  #2   Spotlight this post!  
Unread 24-02-2013, 20:15
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: methods for Switchable Autonomous Modes

Why not use a SendableChooser with SmartDashboard?
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #3   Spotlight this post!  
Unread 24-02-2013, 20:25
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: methods for Switchable Autonomous Modes

Quote:
Originally Posted by F22Rapture View Post
Why not use a SendableChooser with SmartDashboard?
How would I do that? (I have only ever worked with the default dashboard, and I only used the camera feed from that)

-Davis
Reply With Quote
  #4   Spotlight this post!  
Unread 24-02-2013, 20:44
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: methods for Switchable Autonomous Modes

Quote:
Originally Posted by DavisC View Post
How would I do that? (I have only ever worked with the default dashboard, and I only used the camera feed from that)

-Davis
Here's my code, in Java

Code:
public void robotInit() {
        // Create a switching autonomous mode
        autoSwitcher = new SendableChooser();
        autoSwitcher.addDefault("Auto 0", new Auton0());
        autoSwitcher.addObject("Auto 1", new Auton1());
        autoSwitcher.addObject("Auto 2", new Auton2());
        SmartDashboard.putData("Auto Switcher", autoSwitcher);
    }

    public void autonomousInit() {
        autonomousCommand = autoSwitcher.getSelected();    
        autonomousCommand.start();
    }
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #5   Spotlight this post!  
Unread 24-02-2013, 23:29
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
Re: methods for Switchable Autonomous Modes

Yes! I can share my experience! In my opinion, you should go with putting a toggle switch or rotary switch on the robot itself. It's extremely easy to do (just analog). We tried using
Code:
switch(variable) //switch variable
{ 
    case ??:    //if variable == something
    case ???:  //if variable == something else
}
but we had some weird problems where we needed to restart the robot to acquire the new position of the switch (we placed something like x=ToggleSwitch->Get() right above while isOperatorControl. I never got around to asking why, because we restart the robot after every match anyways). Ultimately, it worked really well.
Reply With Quote
  #6   Spotlight this post!  
Unread 25-02-2013, 00:26
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: methods for Switchable Autonomous Modes

If you are looking for an on-robot switch like ekapalka is saying, you could use this:

https://www.estoprobotics.com/estore...d&productId=63

Which would give you the ability to choose between 8 different autonomous modes using the same logic he used. I still prefer SendableChooser, but if you aren't looking to mess around with new dashboards and such it's definitely an option.

(note: it does take up 3 DIO ports on the sidecar, and I know my team is sitting around 12-13 out of 14 atm...)
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #7   Spotlight this post!  
Unread 25-02-2013, 12:07
GrimmReaper's Avatar
GrimmReaper GrimmReaper is offline
Registered User
FRC #2046 (Bear Metal)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Maple Valley, WA
Posts: 24
GrimmReaper is on a distinguished road
Re: methods for Switchable Autonomous Modes

I like using the DIO's on the I/O tab of the drivers station. You had mentioned that and yes it's easily doable. Something like this:
Code:
//declare the driver station - perhaps globally in the robot
DriverStation* driverStation;

//...  then in your init code grab the instance
driverStation = DriverStation::GetInstance();

// then in autonomous mode read the inputs to decide
// Start with just 1 through 8 because you can actually label them on
//the driver station what they are
		if (driverStation->GetDigitalIn(1)) {
			AutoRoutine1();
		} else if (driverStation->GetDigitalIn(2)) {
			AutoRoutine2();
		} else if (driverStation->GetDigitalIn(3)) {
			AutoRoutine3();
		}
If you get beyond 8 needed modes, you'll have to keep a list of how to set the IO's and you can check for combinations of Inputs you could do this straight binary and use 4 lights to get you 16 or in our case we just had a couple more, so we just added on a couple of 2 light scenarios at the top: use Digital IO's to choose autonomous Scenarios
Code:
		if (driverStation->GetDigitalIn(1) && driverStation->GetDigitalIn(2)) {
			AutoRoutine9();
		} else if (driverStation->GetDigitalIn(1) && driverStation->GetDigitalIn(3)) {
			AutoRoutine10();
		} else if (driverStation->GetDigitalIn(1)) {
			AutoRoutine1();
		} else if (driverStation->GetDigitalIn(2)) {
			AutoRoutine2();
		} else if (driverStation->GetDigitalIn(3)) {
			AutoRoutine3();
		}
Reply With Quote
  #8   Spotlight this post!  
Unread 26-02-2013, 21:52
Adamc4's Avatar
Adamc4 Adamc4 is offline
Registered User
AKA: Adam Crandall
FRC #3145 (Teraviks)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Coeur d'Alene, ID
Posts: 21
Adamc4 is an unknown quantity at this point
Re: methods for Switchable Autonomous Modes

Our team came up with a pretty easy method using GPIO and a switch that toggles on and off. Off would be the left side, and on would be the right side. Coding it is incredibly easy because all you need to do is set the two autonomous modes for true and false on the readout of the GPIO. This was a method we came up with right before packaging our bot, and if you are looking for a quick and easy solution I would definitely recommend keeping it simple.
__________________
RoDeL!!!!

Autodesk Oregon Regional Finalists 2013
Spokane Regional Finalists 2013

Creativity and Industrial Design Award 2013
Reply With Quote
  #9   Spotlight this post!  
Unread 27-02-2013, 09:21
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: methods for Switchable Autonomous Modes

To add one more alternative method to the mix, I typically monitor the joystick buttons during disabled mode, if a pair of buttons gets held for 2 seconds, I change the autonomous mode variable.

When the robot goes into autonomous, I have a switch case that calls the different routines based on the autonomous mode variable.

It has the disadvantage that it doesn't persist through reset, so if you restart the match or reboot the robot it needs to be set back to the mode you want. It works well if you use the same mode 90% of the time, and have other modes for flexibility. The advantage is that you don't need any hardware, the implementation is entirely in the robot code.
Reply With Quote
  #10   Spotlight this post!  
Unread 27-02-2013, 13:21
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 152
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: methods for Switchable Autonomous Modes

Really folks - providing you use Smartdashboard, the simplest and most intuitive way to do autonomous is SendableChooser. You don't even have to have real 'Commands' as shown above. The pointer given to AddObject is just a pointer -- point it back to the string itself and compare at autonomous time to decide what the user has chosen. It's super elegant and flexible over time. No need for switches, documenting said switches, holding down buttons, etc.

bob
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
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:54.

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