Go to Post Students... be sure to drill air holes in the crate though. Maybe toss in some cheetos for the programmers. - Andrew Schreiber [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 21-01-2009, 14:53
CardcaptorRLH85's Avatar
Happy Birthday! CardcaptorRLH85 CardcaptorRLH85 is offline
The master of the cards ^_^
AKA: Raa'Shaun H.
FRC #0322 (F.I.R.E. "Flint Inspires Real Engineers")
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Michigan, USA
Posts: 59
CardcaptorRLH85 is an unknown quantity at this point
Send a message via ICQ to CardcaptorRLH85 Send a message via AIM to CardcaptorRLH85 Send a message via MSN to CardcaptorRLH85 Send a message via Yahoo to CardcaptorRLH85
How do I Link a (group of) Joystick button(s) to a motor?

OK, I'm not new at the programming thing but I seem to be having one of those problems that I believe should have a simple solution. Long story short, our robot has a roller on the front. I want buttons 4, 3, and 5 on the Joystick attached to USB port 3 on the DS to control Reverse, Stop, and Forward respectively. I'm extending the IterativeRobot Class for this code. This is what I have so far:

Code:
// These lines are in the declaration
Joystick* m_rollerStick;        // joystick 3 (roller)
Victor *m_roller;
int m_rollerCondition;

// These lines are in the constructor
m_roller = new Victor(4,3);
m_rollerStick = new Joystick(3);
m_rollerCondition = 0;

//These lines are in TelopPeriodic()
.
.
.
if (m_ds->GetPacketNumber() != m_priorPacketNumber) {
.
.
.
// Roller Control
if(m_rollerStick->GetRawButton(4)) m_rollerCondition = -1;
if(m_rollerStick->GetRawButton(5)) m_rollerCondition = 1;
if(m_rollerStick->GetRawButton(3)) m_rollerCondition = 0;

switch (m_rollerCondition)
    {
        case -1:
            m_roller->Set(-1);
            break;
        case 1:
                m_roller->Set(1);
                break;
        case 0:
            default:
                m_roller->Set(0);
                break;
    }
.
.
.
}
I think that I've pasted all of the pertinent code here so I don't have to copy & paste (or upload) the entire file here.

By the way, I've also tried using the Joystick::GetY() function to just output the Y axis on the Joystick directly to the Victor::Set() like this

Code:
m_roller->Set(m_rollerStick->GetY());
However that just caused our roller to run at a forward speed just outside of the deadband. Also, I'm pretty sure that this is a programming issue since Im able to use the m_roller->Set() and m_roller->SetRaw() functions to run the roller.

Thank you all for any help that you can provide for me.
__________________


Last edited by CardcaptorRLH85 : 21-01-2009 at 14:55. Reason: Error in one of my code samples.
Reply With Quote
  #2   Spotlight this post!  
Unread 21-01-2009, 17:16
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: How do I Link a (group of) Joystick button(s) to a motor?

I can't see anything wrong with the code you posted. I'm not sure that you are reading the stick, however.

Print out the status of "m_rollerStick->GetRawButton(X)" and make sure you are correctly reading the buttons. This will also indicate whether for some reason the block of code isn't getting run because of a conditional somewhere.

Lastly, make sure you don't re-set "m_roller" later in the code.
Reply With Quote
  #3   Spotlight this post!  
Unread 22-01-2009, 23:23
LinuxMercedes LinuxMercedes is offline
Real men use Macs
FRC #1444 (Lightning Lancers)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: St. Louis, MO
Posts: 22
LinuxMercedes is an unknown quantity at this point
Re: How do I Link a (group of) Joystick button(s) to a motor?

I *think* I see the problem with your code. Basically, it won't hold the value the victor is set at.

It works this way: Say you push button 4. One cycle reads the button:

if(m_rollerStick->GetRawButton(4)) m_rollerCondition = -1;

and since it sees that button 4 is pushed, it sets the victor to -1. Then it cycles through again. But since you're not holding down the button, it won't keep the victor at -1. Instead, it will do your default action:

default:
m_roller->Set(0);
break;

which sets the victor back to 0. So what you should do is set up some code that reads a button state, sets a variable that stays at that value until it detects that a different button is pushed. I'll leave the implementation of that to the reader =]

Let me know if that wasn't clear enough. I'm good at explaining things to myself; it's explaining things to others that's hard =]
__________________
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming a joystick button... programmr Programming 2 05-01-2009 16:13
Using a button on a joystick to track? DemonYawgmoth Programming 5 12-02-2006 11:17
Joystick Hat button ten3brousone Programming 8 20-02-2005 13:31
Joystick Button programming Bharat Nain Programming 5 18-02-2005 11:48
Joystick Button Deference cibressus53 Electrical 3 01-11-2004 09:38


All times are GMT -5. The time now is 14:08.

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