View Single Post
  #3   Spotlight this post!  
Unread 22-04-2010, 19:37
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Joystick Assigning/ Change to Tank Drive

the stick2 would be the "refNum" names. But if you are serious about C++, call them objects or instances.
//note: the lines (or ends of lines) that start with a // are comments
//They don't change the functionality of the code, but add to it's understanding, and cleanness if used correctly (code below not an example)

Code:
class RobotDemo : public SimpleRobot //this is required, 
{
//This area is where you put objects
   		RobotDrive driver;
		Joystick stick;
		Joystick stick2; //new Joystick

	public:
		RobotDemo() :
//this is the "init.vi" area
//this is where you assign pwm ports, analog ports, usb ports, etc...

			driver(1,2),//creates the RobotDrive (a group of 2 or 4 Jaguars (but victors work as well)
//as having 2 motors, on PWM 1 and 2 (left and right


 stick(1), stick2(4)
//stick is on usb 1, stick 2 is in usb 4

 // these must be initialized in the same order
// as they are declared above.
//Note, the inits are a list of, comma, seperated,     and,space,and, comments,  as, nesescearry, but, the, last, item, does, not, end, with, a, comma
		{
			GetWatchdog().SetExpiration(0.9);
		}
		
//Code ommited
Yes, the TankDrive is what you are expecting
I also notice you are using pointers (Joystick *joy vs Joystick joy)
the init area would be different:


Code:
class RobotDemo : public SimpleRobot //this is required, 
{
//This area is where you put objects
   		RobotDrive *driver;
		Joystick *stick;
		Joystick *stick2; //new Joystick

	public:
		RobotDemo() :
		{

//this is the "init.vi" area for pointers (after { above

			driver = new RobotDrive(1,2);//creates the RobotDrive
//as having 2 motors, on PWM 1 and 2 (left and right

//note: this is not a comma sep. list, each thing ends with a semicolin ;


 stick = new Joystick(1);
stick2 = new Joystick(4);
//stick is on usb 1, stick 2 is in usb 4

			GetWatchdog().SetExpiration(0.9);
		}
		
//Code ommited
Also note, you can have a mix of the two

One more point:
if using pointers:
stick->GetY();
if not using pointers:
stick.GetY();

One other tip:
Press Ctrl+Space for help completing or finding an item (ex: GetTwist). It is automatically launched for . -> and (
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote