Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Switching Drive System While Driving (http://www.chiefdelphi.com/forums/showthread.php?t=94252)

tomy 02-04-2011 22:18

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());
}

Im asking this because today at our competition our drive didnt want to use menanume drive during parts of the match so i comments out the old drive system and then he wanted mecaume again and it was quite annoying

Any ideas?

davidthefat 02-04-2011 22:20

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
}

tomy 02-04-2011 22:26

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
}


Dacilndak 02-04-2011 22:43

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
}

Ideally, then, in the middle of driving you could turn the Z wheel (towards the bottom of the joystick closest to you, like davidthefat said), thus switching drive modes.

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.

tomy 02-04-2011 22:52

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

my thinking is that when you push the trigger it will stop the robot and then it will switch modes that way you do not have to worry about the robot driving while you are switching modes

at least that is what i think you are trying to do

tomy 02-04-2011 22:53

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

Dacilndak 03-04-2011 00:30

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
}

then later...

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;
}

to do the actual switching process. The above would make it so that if you press button 4, you swap to tank drive mode and stay in it until you press button 3.

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 ;).

tomy 03-04-2011 10:35

Re: Switching Drive System While Driving
 
So I should combine a if statement with a casestatment?

Alan Anderson 03-04-2011 13:00

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.

tomy 03-04-2011 13:12

Re: Switching Drive System While Driving
 
Ok thar sounds good I just wanted to make sure you could do it


All times are GMT -5. The time now is 17:45.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi