|
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!
__________________
2008-2011: #226 - The Hammerheads
Last edited by spacepenguine : 22-12-2011 at 10:09.
|