|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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); 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); 2) (CAN-compatible, PWM works too) Code:
leftJag = new CANJaguar(1); rightJag = new CANJaguar(2); drive = new RobotDrive(leftJag, rightJag); Last edited by Radical Pi : 22-04-2010 at 19:44. |
|
#3
|
||||
|
||||
|
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
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
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 ( |
|
#4
|
|||
|
|||
|
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)
|
|
#5
|
|||
|
|||
|
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. |
|
#6
|
||||
|
||||
|
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); |
|
#7
|
|||
|
|||
|
Re: Joystick Assigning/ Change to Tank Drive
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |