|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
General question.
Can you define the 'then' of an 'if then' statement as a set.
and if you have a set within a set is it proper to do if .set ..case ...if ....set ...if ....set ...case ...case i hope you get the point private message me your answer |
|
#2
|
||||
|
||||
|
Re: General question.
Also, for the gear tooth sensor, what should the input be; analog correct?
|
|
#3
|
|||
|
|||
|
Re: General question.
Gear tooth sensor is a phased interrupt as I recall, making it digital. It pulses once per tooth, and you count these in an ISR.
as for your original question... I'm not sure what language you're trying to use. In MPLAB/C18 C, syntax would be Code:
if(condition1){
//code to run if condition1 is true
}else if(condition2){
//code to run if condition2 is true and condition1 is false
}else{
//code to run if both condition1 and condition2 are false.
}
|
|
#4
|
||||
|
||||
|
Re: General question.
sry about thatthats wat im basically doing if (condition) then a list of more conditions that will be followed if the first " if " is true. I belive it is called a " switch (set): " Likewise, there can be more then one condition correct Such as If (Rgear=200 Lgear=210) likewise, if the gear reverse does the counter still count forward to subtract the negative? g2g 2 class Last edited by XXShadowXX : 14-03-2008 at 12:17. |
|
#5
|
|||
|
|||
|
Re: General question.
I believe the KoP GTSs use a phased output (Phase A/B) one rises before the other dependent on directionality of the passings... Kevin Watson has explained this much better than I can. So short answer, no it doesnt count back down, long answer yes, if you do it right.
The syntax for a switch statement is as follows: Code:
switch(condition){
case 1:
//if condition = 1
break;
case 2:
//if condition = 2
break;
case 3:
case 4:
//if condition = 3 or 4
break;
case 5:
//if condition = 5
case 6:
//if condition = 5 or 6
break;
case else:
//all other cases
break;
}
|
|
#6
|
||||
|
||||
|
Re: General question.
thank you very much
|
|
#7
|
|||
|
|||
|
Re: General question.
S'what we're here for. No Problem.
|
|
#8
|
||||
|
||||
|
Re: General question.
ok here is my question if pseudo-code
code: Quote:
Last edited by XXShadowXX : 14-03-2008 at 13:29. |
|
#9
|
|||
|
|||
|
Re: General question.
Quote:
Code:
#define Rmotor1 pwm01 #define Rmotor2 pwm02 #define Lmotor3 pwm03 #define Lmotor4 pwm04 #define func1 rc_dig_in01 #define func2 rc_dig_in02 #define func3 rc_dig_in03 #define func4 rc_dig_in04 #define Rgear Get_Analog_Value(rc_ana_in01) //if this is a GTS, it should be a digital input that's capable of interrupts (i recommend dig01/02) #define Lgear Get_Analog_Value(rc_ana_in02) Quote:
Quote:
It appears you're trying to build a state machine (variable set is your state counter) I think you want something along this line, although, personally, I would just use an if-elseif structure: Code:
switch(autostate){
case 0:
if(Lgear < 200 && Rgear < 200){ // && is the logical AND operator
//drive forward
}else{
autostate++;
}
break;
case 1:
if(Rgear < 500 && Lgear < 500){
//Turn Left
}else{
autostate++;
}
break;
}
|
|
#10
|
||||
|
||||
|
Re: General question.
yes thats basically it. But my orginial question still stands can i have several switchs
Code: PHP Code:
|
|
#11
|
|||
|
|||
|
Re: General question.
Well, a switch's condition can't be func2 = 1 (the switch is ON func2)
IMO switches are more trouble than they are worth I would just use something like this Code:
if(func1 == 1){ //remember, == is equality test, = is assignment
//do stuff if func1 is true
if(func2 == 1){
//do stuff if func1 and func2 are true
}else{
//do stuff if func1 is true and func2 is false
}
}else{
//do stuff if func1 is false
if(func2 == 1){
//do stuff if func1 is false and func2 is true
}else{
//do stuff if func1 and func2 are false
}
}
|
|
#12
|
||||
|
||||
|
Re: General question.
My assuption was that the ir board would connect to the controller by 4 pwm cables.
Each connection would eather get a 1 or 0 (1 signal recieved, 0 no signal) therefore i use that in code. See code: PHP Code:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| General Question About Pneumatics | itsme | Pneumatics | 21 | 23-01-2008 11:17 |
| General question about the robot controller | itsme | Technical Discussion | 6 | 14-01-2007 15:33 |
| General programming question | mikesown | Programming | 1 | 07-02-2005 16:09 |
| Awards at Nationals-- general question | archiver | 2001 | 1 | 24-06-2002 02:39 |
| Question about the animation in general... | Devil's Kid | 3D Animation and Competition | 5 | 22-01-2002 12:34 |