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
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
Also, for the gear tooth sensor, what should the input be; analog correct?
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
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.
}
sry about that
thats 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
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:
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;
}
thank you very much
S’what we’re here for. No Problem.
ok here is my question if pseudo-code
code:
#define pwm1 = Rmotor1
#define pwm2 = Rmotor2
#define pwm3 = Lmotor3
#define pwm4 = Lmotor4
#define digital_input_1 = func1
#define digital_input_2 = func2
#define digital_input_3 = func3
#define digital_input_4 = func4switch (timer <=1)
.Case0:
…If (Rgear = 0
…Lgear = 0)
.Case1:
…If (Rgear =
…Lgear = ) /* gear count unknown at this time */
.Case2:
…If (Rgear =
…Lgear = )
…Switch (Func2 = 0
…Func3 = 0)
…Case0:
…Case1:
…Case2:
.Case3:
…Switch (Func2 = 1
…Func3 = 0)
ok the periods r there to save indetions because idk how to anyother way, the periods have no point in code
this should look like
#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)
this part looks fine, just remember to curly brace your if blocks
I think what you’re trying to do here is a dead reckoning type autonomous mode.
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:
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;
}
and so on.
yes thats basically it. But my orginial question still stands can i have several switchs
Code:
Switch (func2=1)
Case0:
Case1:
Switch (func1=1)
Case0:
Case1:
/*blah blah blah*/
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
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
}
}
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:
#define func1=digital_input_1 /*or what ever*/
If (func1 = 1) /*singal 1 is being recieved by ir board*/
Be awesome!
If (func1 = 0) /*signal 1 not being recieved by ir board*/
Be lame!
Yes, you will receive that data in code as 1 or 0 in a variable, but remember, the IR Board only gives a momentary signal.
I suggest something like this to allow the RC to remember which was pushed
int IRSignal = 0;
if(func1 == 1){
IRSignal = 1;
}else if(func2 == 1){
IRSignal = 2;
}else if(func3 == 1){
IRSignal = 3;
}else if(func4 == 1){
IRSignal = 4;
}
switch(IRSignal){
case 0:
//no button pushed yet
break;
case 1:
//button 1 pushed
break;
case 2:
//button 2 pushed
break;
case 3:
//button 3 pushed
break;
case 4:
//button 4 pushed
break;
}
I don’t know how much programming experience you have, so I apologize if I’m just telling you stuff you already know…
“If (func1 = 1)”
This sets func1, it doesn’t check it. A conditional check is always a double equals sign - “==”.
A switch statement directly reads in a variable, then executes one of a number of commands (“cases”) depending on the value of that variable. If you have a number that will be 1, 2, 3, etc. depending on where you are in the code, this may be what you want to use. If you just want to check if you’ve gone above or below a certain critical value, as with your gear tooth sensor, you probably want to use if–>then–>else statements.
Personally, I find if–>then–>else statements easier, so here are a few examples:
If you want to check multiple conditions at once:
if(A_ISTRUE && B_ISTRUE){
//Method 1
}//end if
will execute your method if both of the conditions are true, but not if only one is true.
if(A_ISTRUE || B_ISTRUE){
//Method 2
}//end if
will execute your method if at least one of your conditions is true - that is, A, B, or both.
if(!A_ISTRUE){
//Method 3
}//end if
will execute your method if your condition is false.
if(A_ISTRUE){
//Do this if A is true
}//end if
else if(B_ISTRUE){
//Do this if A is false and B is true
}//end if
else{
//Do this if both A and B are false
}//end else
has three separate methods - one if A is true, one if A is false and B is true, one if both are false.