|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Switching Drive System While Driving
Odd question but can you change the drive system as you are diving?
something like this: Code:
if(joystick1.GetRawButton(2)){
myrobot.Tankdrive(joystick1.GetY(), joystick2.GetY());
}
Any ideas? |
|
#2
|
|||
|
|||
|
Re: Switching Drive System While Driving
If you are using the Logitech Attack 3, I suggest using the "Z". So:
The "Z" is the thing at the bottom where you can push up or down. Its like a knob. if(joystick1.GetZ() > 0) { myrobot.Tankdrive(joystick1.GetY(), joystick2.GetY()); } else { //the other drive } |
|
#3
|
|||
|
|||
|
Re: Switching Drive System While Driving
so that you can do it then right?
and how would you switch back to the original drive system like this? Code:
if(joystick1.GetRawButton(2)){
myrobot.Tankdrive(joystick1.GetY(), joystick2.GetY());
}
else{
other drive drive
}
else if(joystick1.GetRawButton(3)){
other drive
}
|
|
#4
|
||||
|
||||
|
Re: Switching Drive System While Driving
Well, you could do something like
Code:
if (joystick1.GetZ() < 1.0 && joystick1.GetZ() >= 0.33)
{
// tank drive
}
else if (joystick1.GetZ() < 0.33 && joystick1.GetZ() >= -0.33)
{
// arcade drive
}
else // if (joystick1.GetZ() < -0.33 && joystick1.GetZ() >= -1.0)
{
// holonomic drive (?) ... whatever else
}
I wouldn't recommend using buttons to switch drive modes, as the change in speed can be sudden and you could tear up your drivetrain if the driver isn't careful and/or you aren't ramping your joystick inputs. Last edited by Dacilndak : 02-04-2011 at 22:45. Reason: Clarification. |
|
#5
|
|||
|
|||
|
Re: Switching Drive System While Driving
couldnt i do something like this so stop the tearing apart?
Code:
if (joystick.GetTrigger()){
myRobot.Drive(0)
tank drive
at least that is what i think you are trying to do |
|
#6
|
|||
|
|||
|
Re: Switching Drive System While Driving
i see what you are talking about now after i read it again couldnt we do the samething on a regular controller
|
|
#7
|
||||
|
||||
|
Re: Switching Drive System While Driving
What exactly do you mean by a "regular controller"? The Z-axis wheel is on all of the KOP joysticks.
If you mean just using buttons, then what you seem to be doing there (driving the motor to 0, then using the new drive mode) would certainly work. I would advise, however, adding something like a Wait(0.05); in between the two to allow the robot to come to a bit of a stop or at least slow down - by driving in the new mode immediately, the stop would be basically ignored because you'd be sending it new orders before it had time to stop. It would only stop for a fraction (1/20 in this case) of a second, but it'd really help. Try doing something like: Code:
int driveMode;
if (joy1.GetRawButton(4) == 1 && joy1.GetRawButton(3) == 0) // button 4, not button 3
{
driveMode = 0; // flag for tank drive
drive.Drive(0, 0); // stop motors
Wait(0.05); // let them stop
}
else if (joy1.GetRawButton(4) == 0 && joy1.GetRawButton(3) == 1) // button 3, not button 4
{
driveMode = 1; // flag for arcade drive
drive.Drive(0, 0); // stop motors
Wait(0.05); // let them stop
}
Code:
switch (driveMode)
{
case 0:
drive.TankDrive(joy1.GetY(), joy2.GetY()); // Tank drive
break;
case 1:
drive.Drive(joy1.GetY(), joy1.GetX()); // Arcade drive
break;
default:
drive.Drive(joy1.GetY(), joy1.GetX()); // Arcade drive (default, no buttons have been pressed)
break;
}
Also, you're transmission won't get ripped apart unless you slam the joystick from 1.0 to -1.0 quickly. Still, it's worth putting in safeties like these, since you can't trust your drivers to remember each time . |
|
#8
|
|||
|
|||
|
Re: Switching Drive System While Driving
So I should combine a if statement with a casestatment?
|
|
#9
|
|||||
|
|||||
|
Re: Switching Drive System While Driving
tomy, I'm not sure you understand the way a "drive system" works. Are you expecting to call "TankDrive" once and have the robot switch to tank drive, and later call "ArcadeDrive" once and have the robot switch to arcade drive? That's not what the functions do.
The Drive() functions take joystick inputs and mix them around to control motors. You have to call one of them at least ten times a second in order to keep your robot moving. You can decide which to use every time through your Teleop() loop, and you can change which one you use whenever you want to. I agree with the suggestion to use the Z-axis "throttle" as the selection between Arcade and Tank drive. |
|
#10
|
|||
|
|||
|
Re: Switching Drive System While Driving
Ok thar sounds good I just wanted to make sure you could do it
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|