Go to Post Use checklists. If it's good enough for NASA, it's good enough for FIRST. - Rick TYler [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 10-03-2012, 10:45
Camren's Avatar
Camren Camren is offline
Mentor
FRC #3081 (RoBoEaGleS)
Team Role: Mentor
 
Join Date: Mar 2011
Rookie Year: 2011
Location: Minnesota
Posts: 219
Camren is a jewel in the roughCamren is a jewel in the roughCamren is a jewel in the rough
Gamepad help

Hello

Im semi new to using wind-river though i do a bit of visual studio work so I understand the terminology. My current project is programming a gamepad to work im pretty sure it is a logitech f310 but i can adapt code to work for which ever one i have. So can anyone give me some example code so i can see what i need to work on.
Reply With Quote
  #2   Spotlight this post!  
Unread 12-03-2012, 15:52
Jay Meldrum's Avatar
Jay Meldrum Jay Meldrum is offline
Registered User
FRC #0067 (H.O.T.)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2003
Location: Michigan
Posts: 42
Jay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud ofJay Meldrum has much to be proud of
Re: Gamepad help

First you have to declare them in the main class
Code:
class BuiltinDefaultCode : public IterativeRobot
{
        //Declare Controllers
        Joystick *m_Gamepad1;
        Joystick *m_Gamepad2;
}
Then initialize them in the main function

Code:
BuiltinDefaultCode(void)
{
                //Initialize Controllers
                m_Gamepad1 = new Joystick(1);
                m_Gamepad2 = new Joystick(2);
}
You then can call the joystick button/axis using various commands. We tend to use the GetRawAxis/Button Function.

WPILib Joystick Doxygen
http://www.virtualroadside.com/WPILi..._joystick.html

Code:
 void TeleopDrive(void)
{
       m_robotDrive->ArcadeDrive((-m_Gamepad1->GetRawAxis(LEFT_Y)), -(m_Gamepad1->GetRawAxis(RIGHT_X)));
}

void TeleopArmPosition(void)
{
         if(m_Gamepad1->GetRawButton(BUTTON_1))
          {
                 ArmPosition(ARM_BRIDGE);
          }
}
Just for ease we #define all the different axis/buttons
Code:
//Define Buttons
#define BUTTON_1 1

//Define Axis
#define LEFT_X 1
For reference, here is a map for using GetRawButton/Axis with the Logitech F310:

-Buttons 1-8 are used. They are not labeled, you can try reading all 8 and seeing what maps to what. I know that 9-12 are not used.
Axis 1 -> Left X
Axis 2 -> Left Y
Axis 3 -> Sum of L2 and R2 analog triggers - One is positive, the other is negative, both or neither is 0.
Axis 4 -> Right X
Axis 5 -> Right y
Axis 6 -> D-Pad X (binary like above - Note that you can't read D-Pad Y)
Reply With Quote
  #3   Spotlight this post!  
Unread 12-03-2012, 18:11
Alexander Meyer Alexander Meyer is offline
Registered User
FRC #2358 (Bearbotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Lake Zurich, Illinois
Posts: 36
Alexander Meyer is on a distinguished road
Re: Gamepad help

If you do have the F310, I wrote a class a while back to make using it easier. You can find it here:

http://www.chiefdelphi.com/forums/sh...ad.php?t=90022

If you'd like to write your own code, you can at least use it for the axis and button mappings. If not, usage is very similar to a regular WPILib Joystick.

Code:
F310 *gamepad = new F310(1);
float leftX = gamepad->GetX(F310::kLeftStick);
float rightY = gamepad->GetY(F310::kRightStick);

bool leftTrigger = gamepad->GetButton(F310::kLeftTrigger);

delete gamepad;
gamepad = NULL;
jsmeldru, perhaps we have different versions of the F310? I'm able to read all 12 buttons as well as both DPad axes.
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 03:02.

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