Go to Post I personally hope they change the terrain of the playing field ... if only to "level" the playing field. - Daniel_LaFleur [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 22-04-2010, 19:15
DWirth DWirth is offline
Registered User
FRC #2509
 
Join Date: Feb 2009
Location: Hutch
Posts: 10
DWirth is an unknown quantity at this point
Joystick Assigning/ Change to Tank Drive

Hello
Our team next year will be using C++ instead of LabView, so we're learning C++ now.
I am not sure in the MyRobot.cpp file how you assign a joystick to be on usb 1 or 2. Or atleast different from the original joystick in the file. I've added this line under the first joystick:

Joystick *stick2; //Right joystick

Will this make it different than the first? And for LabView users, would the "stick2" in that line be equivalent to a RefNum names? I've also changed the arcade mode line to:

myRobot->TankDrive(stick,stick2); //

Will this use the two joysticks to drive each side? Also I'm not sure how you tell which PWM you use for each Victor or Jaguar.

A lot of questions, so I thank you for reading it and for any help and clarificaition you can give me.
D. Wirth 2509
Reply With Quote
  #2   Spotlight this post!  
Unread 22-04-2010, 19:30
Radical Pi Radical Pi is offline
Putting the Jumper in the Bumper
AKA: Ian Thompson
FRC #0639 (Code Red Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York
Posts: 655
Radical Pi has a spectacular aura aboutRadical Pi has a spectacular aura aboutRadical Pi has a spectacular aura about
Re: Joystick Assigning/ Change to Tank Drive

The sample programs are an excellent resource for looking at how all this works

For your specific question, no the names have no bearing on what port they are on. In fact, with what you have right now your code will not work and will crash as soon as you start Teleop (possibly sooner)

This must be in the class constructor:
Code:
stick2 = new Joystick(2);
Put that below the one for the first joystick. What this does is allocate the memory and create the actual Joystick that you will be interacting with. The first statement only declares that the stick2 variable exists and is a pointer to a Joystick object.

To assign usb ports, simply change the number inside the parenthases in "new Joystick(2)" to the port number and it will assign the port

EDIT: missed the question about PWM

There are 2 ways that the Victor/Jaguar ports are defined. Both occur when the "new RobotDrive(...);" happens.
1) (cannot be used with CAN controllers)
Code:
drive = new RobotDrive(1,2);
This tells the drive object that the motor on the left is PWM port 1, and right is PWM port 2. A 2nd version of this exists as well, defining a 4 wheel drive system (2 independent motors on each side). The declaration, instead of 2 numbers, has 4 numbers, which are the following: front left motor, rear left motor, front right motor, rear right motor.

2) (CAN-compatible, PWM works too)
Code:
leftJag = new CANJaguar(1);
rightJag = new CANJaguar(2);
drive = new RobotDrive(leftJag, rightJag);
This version, instead of creating the motor objects itself, has you create the objects and give them to the RobotDrive (useful if you switch the RobotDrive on and off during a match to manually run the motors instead for some reason). The constructor can take a Victor, Jaguar, or CANJaguar object, as well as anything else you come across that inherits the SpeedController class. This also has a 4-motor variant identical to the one above
__________________

"To have no errors would be life without meaning. No strugle, no joy"
"A network is only as strong as it's weakest linksys"

Last edited by Radical Pi : 22-04-2010 at 19:44.
Reply With Quote
  #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
  #4   Spotlight this post!  
Unread 22-04-2010, 19:56
Radical Pi Radical Pi is offline
Putting the Jumper in the Bumper
AKA: Ian Thompson
FRC #0639 (Code Red Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York
Posts: 655
Radical Pi has a spectacular aura aboutRadical Pi has a spectacular aura aboutRadical Pi has a spectacular aura about
Re: Joystick Assigning/ Change to Tank Drive

One more thing. I'd reccomend doing a google search about "object oriented programming" and possibly append c++ to the end of it. A lot of these things will make much more sense if you understand the basics of an OO language (which this year's labview is not)
__________________

"To have no errors would be life without meaning. No strugle, no joy"
"A network is only as strong as it's weakest linksys"
Reply With Quote
  #5   Spotlight this post!  
Unread 24-04-2010, 12:22
nighterfighter nighterfighter is offline
1771 Alum, 1771 Mentor
AKA: Matt B
FRC #1771 (1771)
Team Role: Mentor
 
Join Date: Sep 2009
Rookie Year: 2007
Location: Suwanee/Kennesaw, GA
Posts: 835
nighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant future
Re: Joystick Assigning/ Change to Tank Drive

Just to add clarification to what byteit said, about the leftStick.GetY();

For the tank drive function accepts 2 float values.

What you said, is myRobot->TankDrive(stick,stick2); This is passing the 2 joysticks themselves, which would not work. Instead, you should pass their Y Values.

leftStick.GetY() returns a float value from -1(all the way foward) to 1 (all the way backwards).

So in order to drive the robot, (assuming everything else is correct) you would do this:

myRobot.TankDrive( leftStick.GetY(), rightStick.GetY() );

Note: You may need to make one of those values negative (put a "-" infront of one, such as -leftStick.GetY()) so the robot will drive straight when pushed full fowards, not turn.
Reply With Quote
  #6   Spotlight this post!  
Unread 25-04-2010, 04:09
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Joystick Assigning/ Change to Tank Drive

There are five overloaded TankDrive methods in RobotDrive.h. One of them takes two joystick pointers. Another one takes two jockstick references. So TankDrive(stick, stick2) would work.
Code:
void TankDrive(GenericHID *leftStick, GenericHID *rightStick);
void TankDrive(GenericHID &leftStick, GenericHID &rightStick);
void TankDrive(GenericHID *leftStick, UINT32 leftAxis, GenericHID *rightStick, UINT32 rightAxis);
void TankDrive(GenericHID &leftStick, UINT32 leftAxis, GenericHID &rightStick, UINT32 rightAxis);
void TankDrive(float leftValue, float rightValue);
__________________
Reply With Quote
  #7   Spotlight this post!  
Unread 25-04-2010, 09:38
nighterfighter nighterfighter is offline
1771 Alum, 1771 Mentor
AKA: Matt B
FRC #1771 (1771)
Team Role: Mentor
 
Join Date: Sep 2009
Rookie Year: 2007
Location: Suwanee/Kennesaw, GA
Posts: 835
nighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant future
Re: Joystick Assigning/ Change to Tank Drive

Quote:
Originally Posted by mikets View Post
There are five overloaded TankDrive methods in RobotDrive.h. One of them takes two joystick pointers. Another one takes two jockstick references. So TankDrive(stick, stick2) would work.
Code:
void TankDrive(GenericHID *leftStick, GenericHID *rightStick);
void TankDrive(GenericHID &leftStick, GenericHID &rightStick);
void TankDrive(GenericHID *leftStick, UINT32 leftAxis, GenericHID *rightStick, UINT32 rightAxis);
void TankDrive(GenericHID &leftStick, UINT32 leftAxis, GenericHID &rightStick, UINT32 rightAxis);
void TankDrive(float leftValue, float rightValue);
Ah! I stand corrected, nevermind!
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
Tank Drive Joystick thatoneguy23 Programming 8 08-02-2010 21:28
Tank Drive vs. Omni Directional Drive jamie_1930 General Forum 9 24-01-2010 22:50
Change joystick to pwm mapping Joe Lewis Programming 3 30-03-2005 19:27
Assigning Joystick buttons.... archiver 2001 5 24-06-2002 00:59
Single Joystick Tank Steering archiver 2001 5 23-06-2002 22:49


All times are GMT -5. The time now is 13:50.

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