![]() |
Creating a program that switch between tank and arcade
I havehit a hard point in trying to creat a program that can switch between both tank and arcade drive. I have basic block structure for both, I have no clue what to do next can any help?
|
Re: Creating a program that switch between tank and arcade
We usually right that into out drive program when we have a tank base too. It's pretty simple to set up. For our program (in C++, but the logic is the same wherever), we used the throttle on the left joystick as our switch. In the program, this is the z axis and reports values from -1 to 1. The idea is that you have each drive in a if/else if or case block and you grab the value from the z axis (or whatever control you use) at the beginning of the teleop loop and use this to choose which drive block to use.
If you want to use an instantaneous button, the easiest way is probably to write the button value to a variable at the end of the loop then compare the current value to the last value to see if the value has changed and the value is true. This condition can toggle a variable that saves the current drive type. You would then use that current drive variable to decide which drive to use. Additionally, you can decrease the amount of duplicate code by saving the pwm value for the motors in a variable for each motor in the drive blocks, then setting the motor pwm values at the end of the loop outside of the control blocks. This also makes it easier to implement a drive ramp or other filters on the pwm values that are universal to all drives. Good Luck! |
Re: Creating a program that switch between tank and arcade
What language are you using?
In LabVIEW it's easy: just put the two different drive functions in separate cases of a CASE structure, and use whatever you have controlling which mode you want to select the appropriate case. In C++, use an if/then/else to drive it in one fashion or the other. Java should work just like C++. |
Re: Creating a program that switch between tank and arcade
Thank you, but I should have asked how to set up using a button control I originally had them in a case structure but after that using the buttons wasn't connecting right?
|
Re: Creating a program that switch between tank and arcade
Quote:
Tell us how you want the driver to use it, and we can tell you how to program it to work that way. |
Re: Creating a program that switch between tank and arcade
If you want to make the system remember whether you're currently on tank or arcade drive without using something like the Z-axis, you'd need to add a state field to the class, like:
bool isArcadeDrive = true; Then, you'd modify that during each loop with conditionals to change it: if( joystick->getRawButton(ArcadeButton)) { isArcadeDrive = true; } else if ( joystick->getRawButton(TankButton)) { isArcadeDrive = false; } This way, during each loop, your code constantly checks whether you've hit either button to switch driving modes, and the mode, being held in a field, is static during the program, so the program remembers whether you're in arcade or tank drive at any moment. Next, you could add conditionals so that, depending on whether isArcadeDrive indicates arcade or tank driving, to use the drive code associated with either arcade or tank driving. Example: if(isArcadeDrive){ //Arcade drive code } else { //isArcadeDrive is false, therefore use Tank drive settings //tank drive code } |
Re: Creating a program that switch between tank and arcade
Using Java I created 3 classes and an interface.
the interface (ControlMap) was just a list of functions we would need to get the infomation from the joysticks. things like getThrottle() in arcade and getLeftJoystick() and getRightJoystick() for Tank. Then the other two classes were tankControlBoard and arcadeControlBoard. Which implemented the ControlMap interface. This way I could use a single ControlMap object and just switch which implentation to use, and thus change what code was used to get the data needed. That is how I did the controls selection. Then another class i made was softSwitch. which basicly had the methods getState(), toggleState(), and setState() so that I could use a button on the joystick as an on/off toggle (as well as set the button's state in software). so then in our ControlOperator class, which read the data from the ControlMap (and then used the proper ControlBoard) would tell the Drive Train how to drive, using Tank or Arcade. I can't seem to find the code I used. If you need help I will gladly attempt to rewrite a simple version of it. |
Re: Creating a program that switch between tank and arcade
Thanks guys you helped out a lot.:D
|
Re: Creating a program that switch between tank and arcade
I have code for this somehwhere...
its labview code it uses 3 drive modes, controlled by joystick buttons one is pure arcade (arcade), one is RC car (left stick steers, right stick throttles), one is tank it also has a dashboard to go with it. I'll post the code once I get it off my old laptop edit- someone must have deleted it from dropbox... the code worked like this: (in teleop) - 3 buttons for each setting - each button connects to a select block - the false inputs of the slects are hooked tot he select above it, with the last select going into a feedback node, which returns to the false input of the first select block. the true inputs connect the the button's corresponding mode. -the initial input of the feedback note is set to arcade (set to the default case) -the output of the last select goes to a case structure, with one case for each mode. for each case, it uses 2 of 4 axises to go to either an arcade block (arcade and rc) or tank (tank): - the current case selected also goes to a global variable, which is sent to the dashboard data vi to be sent to the dashboard, which has an added display for the current mode. I wish I still had the code, but as far as i can tell it is lost... if I do happen to find it, i will post it. |
Re: Creating a program that switch between tank and arcade
1 Attachment(s)
Quote:
included in the .zip: robot source code driver station source code driver station .exe It was designed to be used with Logitech wingman extreme 3d joystics (I donated an old pair I had sitting). it also uses the left joystick's throttle to scale the speed as the bot it was written for had an unusually high drive gearing (at full speed it was known for flinging batteries :ahh: ) maybe this will be useful in the future to somebody... |
Re: Creating a program that switch between tank and arcade
Your example did come in handy in teaching me how to pass data from the robot to the dashboard :D
|
Re: Creating a program that switch between tank and arcade
Here's another idea, which our team is using. The new Smart Dashboard has a way of storing values and sending them to the robot on startup. We use one of the variables to store a value indicating which steering method to use. When the robot connects, it reads that variable and stores the value locally. The code from that point is pretty much as other posters have described.
As an aside, we have three different steering methods to choose from:
Hope this helps. Good luck, all! |
| All times are GMT -5. The time now is 23:33. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi