Go to Post Don't forget the robot, the most important hardware there is!:p - artK [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 02-02-2015, 00:55
Ebslgpy Ebslgpy is offline
Registered User
FRC #5700
 
Join Date: Feb 2015
Location: San Francisco, California
Posts: 1
Ebslgpy is an unknown quantity at this point
Help with implementing Joysticks into C++ command based code

Hello, I am one of the two programmers in a rookie team starting out this year. We have never programmed for a robot before, but did have experience with C++. We successfully connected commands to joystick buttons, but do not know how to declare the axis of the joysticks in our code (we are using 2 joysticks). Any help in regards of that and how to code the joystick to control the drive train would be appreciated.

P.S. Please do ask if the above paragraph was not clear enough. I hope we can learn more through communicating with experienced programmers.
Reply With Quote
  #2   Spotlight this post!  
Unread 02-02-2015, 07:39
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: 186
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: Help with implementing Joysticks into C++ command based code

Assuming you already have the joystick defined in your OI class you can access joystick axis in a command like this.

Code:
#ifndef DriveCommand_H
#define DriveCommand_H

#include "../CommandBase.h"
#include "WPILib.h"

class DriveCommand: public CommandBase
{
public:
	DriveCommand();
	void Initialize();
	void Execute() {
		driveTrain->Crab(oi->GetDriverStick()->GetRawAxis(1),
				         oi->GetDriverStick()->GetRawAxis(2),
						 oi->GetDriverStick()->GetRawAxis(3));
	}
	bool IsFinished(){
		return false;
	}
	void End();
	void Interrupted();
};

#endif
In this particular command, driveTrain has been defined in CommandBase as a static. DriveTrain has a method defined called Crab that is passed float parameters. In this case we are passing in 3 joystick axis.

Optionally you may want this command to be running on the subsystem as the default behavior when no other command is running. To achieve this ensure you have an InitDefaultCommand() method defined in your subsystem that calls SetDefaultCommand(new DriveCommand);

Code:
void DriveTrain::InitDefaultCommand() {
	SetDefaultCommand(new DriveCommand());
}
You might want to read through http://wpilib.screenstepslive.com/s/.../13810/c/88685. It tells you everything you need to know about command based programming.
__________________
"May the coms be with you"

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

Reply With Quote
  #3   Spotlight this post!  
Unread 03-02-2015, 22:13
JohnSmooth42 JohnSmooth42 is offline
Is writing code
FRC #0375 (The Robotic Plague)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2012
Location: New York
Posts: 27
JohnSmooth42 is an unknown quantity at this point
Re: Help with implementing Joysticks into C++ command based code

The GearsBot example project also has some very good examples on how to do this.
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 12: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