Go to Post its kind of a bad idea to implement traction control when you have no traction in the first place. - Uberbots [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 28-04-2016, 20:38
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 212
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
How simple should commands be? And how should they be structured?

Hello everyone,

I was wondering how other people structured or put together commands in their command-based robots. I am always struggling with myself on how to structure them and how simple they should be.

For example, lets say I want to open and close a solenoid. Should I make a command that opens it, and a command that closes it, or just have a single command that gets passed a value to tell which valve I want to open?

I think the first way of doing that is way too "separated", so in my code I use the second method.

However, one issue I always run into is when I want to use "axis" values on a joystick in a command. For example, on our shooter, we use the right trigger on the xbox 360 controller for spinning up our shooter, but that leads to a weird situation where I had to write a special condition where if the time parameter passed in was exactly 0, it would assume it was in teleoperated mode. Here is what I am talking about:

Code:
	
        timeCurrent = timer->Get();
	if(timeTarget == 0) {
		if(rightTrigger2 > 0.2) {
			//Robot::shooterSubsystem->Shoot(12);
			Robot::shooterSubsystem->Shoot(6000);
			Robot::intakeSubsystem->Intake(-1);
		}
		else if(leftTrigger2 > 0.2) {
			Robot::shooterSubsystem->Shoot(-1500);
			Robot::intakeSubsystem->Intake(1);
			Robot::shooterSubsystem->SetAngleLeftServo(0);
			Robot::shooterSubsystem->SetAngleRightServo(200);
		}
		else {
			Robot::shooterSubsystem->Shoot(0);
			Robot::intakeSubsystem->Intake(0);
			Robot::shooterSubsystem->SetAngleLeftServo(70);
			Robot::shooterSubsystem->SetAngleRightServo(110);
		}
		isDone = true;
	}
	else {
		if(timeCurrent >= timeTarget) {
			Robot::shooterSubsystem->Shoot(0);
			isDone = true;
		}
		else {
			Robot::shooterSubsystem->Shoot(inputSpeed);
			isDone = false;
		}
	}
That way of doing it seems wrong, but I'm not sure. Opinions and suggestions would be greatly appreciated!

Thanks,
Drew
Reply With Quote
  #2   Spotlight this post!  
Unread 28-04-2016, 21:22
414cnewq 414cnewq is online now
Registered User
FRC #3844 (Kentucky Wildbots)
Team Role: Alumni
 
Join Date: Jul 2014
Rookie Year: 2014
Location: KY
Posts: 86
414cnewq has much to be proud of414cnewq has much to be proud of414cnewq has much to be proud of414cnewq has much to be proud of414cnewq has much to be proud of414cnewq has much to be proud of414cnewq has much to be proud of414cnewq has much to be proud of414cnewq has much to be proud of414cnewq has much to be proud of
Re: How simple should commands be? And how should they be structured?

When I needed to activate something via the Xbox 360 controller, I used the wpilib triggers functionality.
My GetTrigger.h (C++)
Code:
#ifndef GetTrigger_H
#define GetTrigger_H

#include "WPILib.h"

class GetTrigger: public Trigger
{
private:
	int m_axis;
	Joystick* joy;
public:
	GetTrigger(int, Joystick*);
	bool Get();
};

#endif
And GetTrigger.CPP
Code:
#include "GetTrigger.h"

GetTrigger::GetTrigger(int axis, Joystick* Joy)
{
	joy=Joy;
	m_axis=axis;
}

bool GetTrigger::Get()
{
	return joy->GetRawAxis(m_axis)>0;
}
You just declare an object of Type, in this case, GetTrigger in your OI as defined in your constructor and Initialize it like a JoystickButton. If I'm too vaugue, just look in the WPIlub documentation on Triggers here.

Last edited by 414cnewq : 28-04-2016 at 21:26. Reason: Aa
Reply With Quote
  #3   Spotlight this post!  
Unread 28-04-2016, 21:25
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 212
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
Re: How simple should commands be? And how should they be structured?

Oh wow! I didn't even know that existed! Thanks!

I still would like to keep this thread up for discussion on how people use the command based framework. I find it very intresting how people structure their code.
Reply With Quote
  #4   Spotlight this post!  
Unread 28-04-2016, 22:56
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 374
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: How simple should commands be? And how should they be structured?

Quote:
Originally Posted by jreneew2 View Post
For example, lets say I want to open and close a solenoid. Should I make a command that opens it, and a command that closes it, or just have a single command that gets passed a value to tell which valve I want to open?
I think it makes more sense to have a single command. The way we threw together commands like this was something like
Code:
class SomethingToggleCommand: CommandBase {
int m_mode;
public:
SomethingToggleCommand(){ // default action: toggle
  m_mode = 2;
}
SomethingToggleCommand(bool isOpen){ // explicitly set open or closed
  m_mode = isOpen;
}
void Execute(){
  if(m_mode == 2) { 
    somethingSubsystem->setSomething(!somethingSubsystem->isSomethingOpen());
  } else {
    somethingSubsystem->setSomething(m_mode);
  }
}
bool IsFinished(){
  return true;
}
// etc
}
I don't think it's the best way in terms of design, but it works ¯\_(ツ)_/¯
Reply With Quote
  #5   Spotlight this post!  
Unread 29-04-2016, 16:48
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,679
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: How simple should commands be? And how should they be structured?

As far as I am aware, none of our commands take arguments.

As an example, for our ball pickup, we have four separate commands:
  • BallPickupForward()
  • BallPickupReverse()
  • BallPickupStop()
  • ControlIntakeMotor()
ControlIntakeMotor() reads the joystick and selects the appropriate command of the other three. (It would probably have been better named something like BallPickupOperate()).
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 29-04-2016 at 16:50.
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 19:15.

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