![]() |
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 |
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); |
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, 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, 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 ( |
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)
|
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. |
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); |
Re: Joystick Assigning/ Change to Tank Drive
Quote:
|
| All times are GMT -5. The time now is 13:50. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi