Go to Post REMEMBER - there ARE things more important than robots... false - Botwoon [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 16-02-2013, 10:19
nickpaterni's Avatar
nickpaterni nickpaterni is offline
Programming Mentor - Java
FRC #0217 (The Thunderchickens)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Mt Clemens, MI
Posts: 16
nickpaterni is an unknown quantity at this point
Launching a command with a second thumbstick

We are using an Xbox controller for robot control, and would like to use the right thumbstick to call a command - specifically to be able to use the value from GetRawAxis() to determine the speed at which we activate a Victor. I know how to get a button to launch a command in OI, but don't know how to make movement of the right thumbstick do the same. Any ideas?
Reply With Quote
  #2   Spotlight this post!  
Unread 17-02-2013, 00:32
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Launching a command with a second thumbstick

Can you have a background command on the relevant subsystem that watches the joystick value and fires off a specific command when the value changes?

But it just sounds like you want a background command that continuously copies the joystick value to the Victor, nothing fancier than that.
Reply With Quote
  #3   Spotlight this post!  
Unread 17-02-2013, 13:47
nickpaterni's Avatar
nickpaterni nickpaterni is offline
Programming Mentor - Java
FRC #0217 (The Thunderchickens)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Mt Clemens, MI
Posts: 16
nickpaterni is an unknown quantity at this point
Re: Launching a command with a second thumbstick

Quote:
Originally Posted by Alan Anderson View Post
Can you have a background command on the relevant subsystem that watches the joystick value and fires off a specific command when the value changes?

But it just sounds like you want a background command that continuously copies the joystick value to the Victor, nothing fancier than that.
Do you have an example of setting up a background command? I've only done regular commands which require a particular subsystem(s). Is there a particular place the code goes to watch the joystick value? Does it need to be in a loop, or is it constantly being checked?

Thanks in advance for the help

Nick
Reply With Quote
  #4   Spotlight this post!  
Unread 17-02-2013, 13:31
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 586
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Launching a command with a second thumbstick

Quote:
Originally Posted by nickpaterni View Post
We are using an Xbox controller for robot control, and would like to use the right thumbstick to call a command - specifically to be able to use the value from GetRawAxis() to determine the speed at which we activate a Victor. I know how to get a button to launch a command in OI, but don't know how to make movement of the right thumbstick do the same. Any ideas?
It seems like you want a command that you schedule in teleopInit() that will just grab the joystick value and drive the motor. It can do that independently from everything else in your teleop code.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #5   Spotlight this post!  
Unread 17-02-2013, 13:48
nickpaterni's Avatar
nickpaterni nickpaterni is offline
Programming Mentor - Java
FRC #0217 (The Thunderchickens)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Mt Clemens, MI
Posts: 16
nickpaterni is an unknown quantity at this point
Re: Launching a command with a second thumbstick

Quote:
Originally Posted by BradAMiller View Post
It seems like you want a command that you schedule in teleopInit() that will just grab the joystick value and drive the motor. It can do that independently from everything else in your teleop code.
That does sound like what I'm looking for - do I just really put an if statement in the teleopInit() method that grabs the joystick value and launches a command from there? Does teleopInit() run continuously? I was under the impression that teleopInit() only ran once at the beginning of teleop.

Thanks

Nick
Reply With Quote
  #6   Spotlight this post!  
Unread 17-02-2013, 22:21
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 185
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: Launching a command with a second thumbstick

Quote:
Originally Posted by nickpaterni View Post
We are using an Xbox controller for robot control, and would like to use the right thumbstick to call a command - specifically to be able to use the value from GetRawAxis() to determine the speed at which we activate a Victor. I know how to get a button to launch a command in OI, but don't know how to make movement of the right thumbstick do the same. Any ideas?
We ran into the same problem. Our solution that I consider elegant was to make our own AnalogJoystickButton that inherits button.

You can simply create a Button like your would a JoystickButton but also pass in a threshold at which point you consider the joystick "pressed". This allows the assignment of multiple commands to different thresholds. Typically we use .5 and -.5 to get both directions from the axis.

Once you include the class below you can do the following. I'm assuming you know how to create a JoystickButton in OI. Have the member be an

Code:
AnalogJoystickButton* fireDiscButton;
Code:
fireDiscButton = new AnalogJoystickButton(shooterStick, XboxController::xbZAxis, -.5);
fireDiscButton->WhileHeld(new FireDiscCommand());
*Note: You need to provide the axis number. We have them defined as enums so we can just use XBoxController::xbZAxis to get at the trigger axis.

In your actual command you can get your joystick from OI and get the actual value of the axis if you need it for speed.

AnalogJoystickButton.h:

Code:
#ifndef _ANAOLG_JOYSTICK_BUTTON_H__
#define _ANOLOG_JOYSTICK_BUTTON_H__

#include "WPILib.h"

class AnalogJoystickButton : public Button
{
public:
	AnalogJoystickButton(GenericHID *joystick, int axisNumber, float threshold);
	virtual ~AnalogJoystickButton() {}

	virtual bool Get();
	
private:
	GenericHID *m_joystick;
	int m_axisNumber;
	float m_threshold;
};

#endif


AnalogJoystickButton.cpp:

Code:
#include "AnalogJoystickButton.h"

AnalogJoystickButton::AnalogJoystickButton(GenericHID *joystick, int axisNumber, float threshold ) {
        m_threshold = threshold;
        m_joystick = joystick;
        m_axisNumber = axisNumber;
}

bool AnalogJoystickButton::Get()
{
        if(m_threshold < 0)
                return m_joystick->GetRawAxis(m_axisNumber) < m_threshold;
        else if(m_threshold > 0)
                return m_joystick->GetRawAxis(m_axisNumber) > m_threshold;
        return false; 
                
}
Let me know if you have any questions or need help implementing it.

EDIT -- Just to make like easier.


XboxController.h:

Code:
#ifndef XBOXCONTROLLER_H_
#define XBOXCONTROLLER_H_

#include "WPILib.h"



class XboxController: public Joystick {
public:
        static const UINT32 XboxController::xbLeftXAxis;
        static const UINT32 XboxController::xbLeftYAxis;
        static const UINT32 XboxController::xbZAxis;
        static const UINT32 XboxController::xbRightXAxis;
        static const UINT32 XboxController::xbRightYAxis;
        static const UINT32 XboxController::xbAButton;
        static const UINT32 XboxController::xbBButton;
        static const UINT32 XboxController::xbXButton;
        static const UINT32 XboxController::xbYButton;
        static const UINT32 XboxController::xbStartButton;
        static const UINT32 XboxController::xbSelectButton;
        static const UINT32 XboxController::xbRightBumper;
        static const UINT32 XboxController::xbLeftBumper;
        static const UINT32 XboxController::xbRightStickCLick;
        static const UINT32 XboxController::xbLeftStickClick;
        
        XboxController(UINT32 port);
        virtual ~XboxController();
        
};

#endif /* XBOXCONTROLLER_H_ */

XboxController.cpp

Code:
#include "XboxController.h"

const UINT32 XboxController::xbLeftXAxis = 1;
const UINT32 XboxController::xbLeftYAxis = 2;
const UINT32 XboxController::xbZAxis = 3;
const UINT32 XboxController::xbRightXAxis = 4;
const UINT32 XboxController::xbRightYAxis = 5;
const UINT32 XboxController::xbAButton = 1;
const UINT32 XboxController::xbBButton = 2; 
const UINT32 XboxController::xbXButton = 3;
const UINT32 XboxController::xbYButton = 4;
const UINT32 XboxController::xbStartButton = 8;
const UINT32 XboxController::xbSelectButton = 7;
const UINT32 XboxController::xbRightBumper = 6;
const UINT32 XboxController::xbLeftBumper = 5;
const UINT32 XboxController::xbRightStickCLick = 10;
const UINT32 XboxController::xbLeftStickClick = 9;


XboxController::XboxController(UINT32 port) : Joystick(port){}

XboxController::~XboxController() {}
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?


Last edited by kylelanman : 17-02-2013 at 22:25. Reason: Added XboxController Class for easier implementation.
Reply With Quote
  #7   Spotlight this post!  
Unread 18-02-2013, 13:49
nickpaterni's Avatar
nickpaterni nickpaterni is offline
Programming Mentor - Java
FRC #0217 (The Thunderchickens)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Mt Clemens, MI
Posts: 16
nickpaterni is an unknown quantity at this point
Re: Launching a command with a second thumbstick

kylelanman:

Wow! That is awesome! I'm going to pass this on to my lead programmer and see what he makes of it. I'll let you know if I have any questions on implementation, but it looks really solid. I appreciate the help!

Nick
Reply With Quote
  #8   Spotlight this post!  
Unread 19-02-2013, 16:18
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 516
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Launching a command with a second thumbstick

teleopInit() is only called at the beginning of teleop, but if you schedule a command that doesn't end from teleopInit(), the scheduler will keep running it throughout teleop.
Reply With Quote
  #9   Spotlight this post!  
Unread 11-02-2016, 09:17
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: Launching a command with a second thumbstick

Thank you kylelanman and Roboteers! We're using a Thrustmaster X this year and decided that the Throttle and it's slider make for intuitive inputs for an arm we're using. I was going down a different road, and decided to look for something better. Sure enough, a little search on CD yielded an elegant solution

Eric
__________________

Don't PANIC!
S. P. A. M.
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 09:52.

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