![]() |
Programming Toggle Swiches
I am new with labview and have gotten everything but the autonomous done.
i need help trying to set up switches. i have two switches. if both of them are on then do no autonomous. if toggle one on and toggle two off, do autonomous code one if toggle one is off, 2 on, do autonomous code 2 if both on do automous code three |
Re: Programming Toggle Swiches
Chris,
Read them both in as Boolean then convert to a number. Each will be a zero or a one. Now multiply #2 by 2 and add to #1. You now have a number ranging from 0 to 3. Put this into a switch or case statement (depending on your programming language). You're done... Mike |
Re: Programming Toggle Swiches
There are a couple things to do here. One task is to get toggle switches connected to the Cypress board. You also need to write code. If you want to write the code first, or do the tasks in parallel with someone else, you can disconnect the board from the DS and simply change the digital inputs on the I/O screen directly (this assumes you are using the compatible mode for I/O).
Once this works, or the physical toggles are connected and control the switches on the screen of the DS I/O tab, you want to read those in Autonomous. The VI for this is in palette at WPILib>>Driver Station>>Compatibility I/O>>Get Digital Inputs. It returns an array, and you can retrieve the Booleans from the array using an array indexer or other means. I'd recommend combining the Booleans together into a number and wiring the number to a switch statement around most of your autonomous code. You'll probably find it useful to get the refnums in common code outside the switch, and then put the various autonomous with. You can also make the autonomous routines into subVIs too and simply call them from within the switch statement. Greg McKaskle |
Re: Programming Toggle Swiches
Thanks Mike I think we managed to get that code made but I don't think it will quite work with the system we have.
We will have three switches with on/ off positions that will controll three different autonomous modes. The problem is that we are not sure how to connect the switches to the code. We need the code to recieve the position of all the switches form DIO 3-5. We tried to use the select but said that we were using the wrong type of input for "S", but it is the same concept. If button one is on, and others off, then run autonomous for feild section one. If button two on, and others off, then run autonomous for feild section two. If button 3 on and others off, then run autonomous for reild section 3. Could anyone give me some tips, we are kind off hitting a wall. |
Re: Programming Toggle Swiches
Quote:
I really think that converting to a number and then feedng a switch is far easier and less confusing to do. Mike |
| All times are GMT -5. The time now is 11:48. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi