Go to Post Sometimes the best feeling doesn't come from watching yourself excel but rather from watching others excel. - kristenliz_28 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-03-2008, 11:53
XXShadowXX's Avatar
XXShadowXX XXShadowXX is offline
They call me Cody.
no team (None currently :\)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Pontiac; MI
Posts: 408
XXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud of
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
__________________
Is now an engineer thanks to FIRST.
  #2   Spotlight this post!  
Unread 14-03-2008, 11:55
XXShadowXX's Avatar
XXShadowXX XXShadowXX is offline
They call me Cody.
no team (None currently :\)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Pontiac; MI
Posts: 408
XXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud of
Re: General question.

Also, for the gear tooth sensor, what should the input be; analog correct?
__________________
Is now an engineer thanks to FIRST.
  #3   Spotlight this post!  
Unread 14-03-2008, 12:08
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
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   Spotlight this post!  
Unread 14-03-2008, 12:11
XXShadowXX's Avatar
XXShadowXX XXShadowXX is offline
They call me Cody.
no team (None currently :\)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Pontiac; MI
Posts: 408
XXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud of
Re: General question.

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
__________________
Is now an engineer thanks to FIRST.

Last edited by XXShadowXX : 14-03-2008 at 12:17.
  #5   Spotlight this post!  
Unread 14-03-2008, 13:00
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
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   Spotlight this post!  
Unread 14-03-2008, 13:06
XXShadowXX's Avatar
XXShadowXX XXShadowXX is offline
They call me Cody.
no team (None currently :\)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Pontiac; MI
Posts: 408
XXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud of
Re: General question.

thank you very much
__________________
Is now an engineer thanks to FIRST.
  #7   Spotlight this post!  
Unread 14-03-2008, 13:10
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
Re: General question.

S'what we're here for. No Problem.
  #8   Spotlight this post!  
Unread 14-03-2008, 13:11
XXShadowXX's Avatar
XXShadowXX XXShadowXX is offline
They call me Cody.
no team (None currently :\)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Pontiac; MI
Posts: 408
XXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud of
Re: General question.

ok here is my question if pseudo-code

code:
Quote:
#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 = func4


switch (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
__________________
Is now an engineer thanks to FIRST.

Last edited by XXShadowXX : 14-03-2008 at 13:29.
  #9   Spotlight this post!  
Unread 14-03-2008, 13:33
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
Re: General question.

Quote:
Originally Posted by XXShadowXX
#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 = func4
#define analog_input_1 = Rgear
#define analog_input_2 = Lgear
this should look like

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:
Originally Posted by XXShadowXX
If (func1=1)
/*idk, how to program for raising and locking arm.*/
/*But, the arm has to be raised here. */
If (func4=1)
Rmotor1 = 127
Rmotor2 = 127
Lmotor3 = 127
Lmotor4 = 127
this part looks fine, just remember to curly brace your if blocks

Quote:
Originally Posted by XXShadowXX
switch (Set):
Case0:
If (Rgear = 0
Lgear = 0)
Rmotor1 = 254
Rmotor2 = 254
Lmotor3 = 254
Lmotor4 = 254
Case1:
If (Rgear =
Lgear = ) /* gear count unknown at this time */
Rmotor1 = 254
Rmotor2 = 254
Lmotor3 = 0
Lmotor4 = 0
Case2:
If (Rgear =
Lgear = )
Rmotor1 = 127
Rmotor2 = 127
Lmotor3 = 127
Lmotor4 = 127
Switch (Func2 = 0
Func3 = 0)
Case0:
If (Rgear =
Lgear = )
Rmotor1 = 254
Rmotor2 = 254
Lmotor3 = 254
Lmotor4 = 254
Case1:
If (Rgear =
Lgear = )
Rmotor1 = 254
Rmotor2 = 245
Lmotor3 = 0
Lmotor4 = 0
Case2:
If (Rgear =
Lgear = )
Rmotor1 = 254
Rmotor2 = 254
Lmotor3 = 254
Lmotor4 = 254
Case3:
If (Rgear =
Lgear = )
Rmotor1 = 127
Rmotor2 = 127
Lmotor3 = 127
Lmotor4 = 127
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:

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;
}
and so on.
  #10   Spotlight this post!  
Unread 14-03-2008, 13:38
XXShadowXX's Avatar
XXShadowXX XXShadowXX is offline
They call me Cody.
no team (None currently :\)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Pontiac; MI
Posts: 408
XXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud of
Re: General question.

yes thats basically it. But my orginial question still stands can i have several switchs

Code:
PHP Code:
Switch (func2=1)
 
Case0:
 
Case1:
Switch (
func1=1)
 
Case0:
 
Case1:
/*blah blah blah*/ 
__________________
Is now an engineer thanks to FIRST.
  #11   Spotlight this post!  
Unread 14-03-2008, 13:46
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
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   Spotlight this post!  
Unread 14-03-2008, 13:50
XXShadowXX's Avatar
XXShadowXX XXShadowXX is offline
They call me Cody.
no team (None currently :\)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Pontiac; MI
Posts: 408
XXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud ofXXShadowXX has much to be proud of
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:
#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
__________________
Is now an engineer thanks to FIRST.
  #13   Spotlight this post!  
Unread 14-03-2008, 14:02
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
Re: General question.

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

Code:
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;

}
  #14   Spotlight this post!  
Unread 21-03-2008, 23:45
RyanW RyanW is offline
Registered User
FRC #0449 (Blair Robot Project)
Team Role: Programmer
 
Join Date: Feb 2007
Rookie Year: 2007
Location: MD
Posts: 40
RyanW has a spectacular aura aboutRyanW has a spectacular aura about
Re: General question.

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:
Code:
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.
Code:
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.
Code:
if(!A_ISTRUE){
//Method 3
}//end if
will execute your method if your condition is false.
Code:
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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 02:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi