|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
[FTC]: Toggle controls
Is it possible to toggle the controls?
i have a couple of servos that need it |
|
#2
|
||||
|
||||
|
Re: [FTC]: Toggle controls
Can you provide additional details about what is meant by "toggle the controls?"
Thanks, Michael |
|
#3
|
||||
|
||||
|
Re: [FTC]: Toggle controls
Push a button...the servo goes there
release the button and it says there push again and it goes to the starting position release and it stays there ex) ![]() animation made by me |
|
#4
|
||||
|
||||
|
Re: [FTC]: Toggle controls
Great animation! Thanks.
Which programming language are you using? Michael |
|
#5
|
||||
|
||||
|
Re: [FTC]: Toggle controls
Robot C
|
|
#6
|
||||
|
||||
|
Re: [FTC]: Toggle controls
OK. So what you want is that when u press a button, let's assume button 1, then the servo moves to one position. if you press another button, the servo moves to an original position.
So, the code has is a tad bit more complex. int sum = 2; if(joy2Btn(1)) // if button one is pressed { sum = sum +1; } int calcremainder = sum % 2; // This line calculates the remainder of sum/2. if (calcremainder = 0) { servo[Servo1] = 100; } else { servo[Servo1] = 0; } So the code above basically does this. Each time you hit the button, the program counts it. I know there's an official counter in the program, but i'm ghetto like this. Then, it takes the number of times the button has been hit, and it divides by 2. So, then the value can either be 0 or 1. So each time you hit the button, the value switches between 0 and 1, so when the value is 0, you have a position, when it is 1 you have a position. That's the logic. There might be a better way, but this is one possibly option. |
|
#7
|
||||
|
||||
|
Re: [FTC]: Toggle controls
it just makes the arm reverse itself
|
|
#8
|
||||
|
||||
|
Re: [FTC]: Toggle controls
That code above should do what the animation does. But you will have to put in the correct servo values.
|
|
#9
|
||||
|
||||
|
Re: [FTC]: Toggle controls
yeah, i put that in and reset the servo values, but it just reversed the servo...
here's my code Code:
int sum = 2;
if(joy2Btn(2)) // if button 2 is pressed
{
sum = sum +1;
}
int calcremainder = sum % 2; // This line calculates the remainder of sum/2.
if (calcremainder == 0) <this was an error in your lines...it needed a double=
{
servo[ServoB] = 100;
}
else
{
servo[ServoB] = 0;
}
|
|
#10
|
|||
|
|||
|
Re: [FTC]: Toggle controls
What do you mean it makes the servos reverse themselves?
Also, I don't see how that works if the counter resets itself each time, it wouldn't stay I don't believe Code:
int touch = 1;
//put variable before while loop
if(joy2Btn(1)) {
if(touch == 1){
touch = 0;
}else{
touch = 1;
}
}
//you may want a really short wait here so when you press the button it does not switch back to original really quick
if(touch == 1){
servo[ServoB] = 100;
}else{
servo[ServoB] = 0;
}
|
|
#11
|
||||
|
||||
|
Re: [FTC]: Toggle controls
ah yes. The counter would have to be outside the while loop.
That is a basic code. Now there is an official counter which might be better than actually going in and creating another variable. It probably won't make a huge difference, but whateva you want. |
|
#12
|
||||
|
||||
|
Re: [FTC]: Toggle controls
still doesn't do anything
...thanks anaways guys if you could figure it out, thanks for putting up with me |
|
#13
|
||||
|
||||
|
Re: [FTC]: Toggle controls
found this online, but i tried converting it and with my small ammount of programming knowledge, i didn't get very far
Code:
#include <stdio.h>
int main() {
int x;
for (x = 0; x < 10; x++) {
if(x == 1 || x == 4 ) {
continue;
}
else if(x == 8) {
break;
}
else {
printf("x = %d", x);
}
}
return (1);
}
|
|
#14
|
|||
|
|||
|
Re: [FTC]: Toggle controls
The modulo ("%") function code will do what you want, but you really should look into state machines. The code should look more like:
int state=0; while (true) { ... (add your getjoystick function here) ... (and any other code you have) switch (state) { case 0: if(joy2Btn(1)) // if button one is pressed { // Move your server to the first position (aka state) servo[Servo1] = 100; state = 1; } break; case 1: if (joy2Btn(1) == 0) { // if the button was released then we can wait for another // button push state = 2; } break; case 2: if(joy2Btn(1)) // if button one is pressed { // now move your servo to the other position (aka state) servo[Servo1] = 0; state = 3; } break; case 3: if (joy2Btn(1) == 0) { // again, wait for the button to be released // before we look for another push state = 0; } break; default: state = 0; break; } } Hope this helps. Paul Tan. |
|
#15
|
||||
|
||||
|
Re: [FTC]: Toggle controls
Last edited by nate15810 : 12-02-2009 at 14:53. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [FTC]: FTC]: FTC Champ Tournament - Ontario (Scoring Breakdown) | Mr. Lim | FIRST Tech Challenge | 2 | 03-03-2008 11:54 |
| [FTC]: [FTC]: Ontario Provincial FTC Start/End Times | cbhl | FIRST Tech Challenge | 8 | 16-12-2007 13:37 |
| toggle switch | Windward | Programming | 31 | 27-01-2006 22:38 |
| Code: Toggle on Tap | Dave Scheck | Programming | 0 | 11-02-2005 18:07 |
| Toggle? | f22flyboy | Programming | 5 | 03-11-2002 08:03 |